Speed regulator for sewing machine


Results 1 to 15 of 15

Threaded View

  1. #9
    Join Date
    Dec 2013
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Re: Speed regulator for sewing machine

    Thanks again for your ideas. I increased the encoder resolution to about 2500 pluses per inch of travel and counted the pulses. I seems to work quite well with good low speed movement. My sewing machine drive is a servo so I need to feed it with a frequency. I feed the PWM output to a filter and then to an ADC ( AD654) chip to give me 0 to 15kHz out.

    Code:
    '****************************************************************
    '*  Name    : Pulse Count.BAS                                      *
    '*  Author  : Jan                                      *
    '*  Notice  : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 27/12/2013                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : Count pulses in                                                  *
    '*          : 16F88                                                  *
    '****************************************************************
    
    Include "modedefs.bas"          ' Include serial modes
    define OSC 20
    
    #CONFIG __config _CONFIG1, _HS_OSC & _WDT_ON & _LVP_OFF & _CP_OFF & _CCPMX_RB3 & _CCP1_RB3 
    #ENDCONFIG    'Configure CCP1 (RB3) to PWM out
    
    
    SO      VAR PORTB.5     'Define serial out pin
    P1      var PORTA.0     'Define input pin  X
    P2      VAR PORTA.1     'Define input pin  Y
    W1      var WORD 
    W2      VAR WORD
    W3      VAR WORD
    led     var PORTB.0
    TRISA = %11111111
    ANSEL = %00000000
    output   led               
    low      led               'set led off
    
     displayloop:
    
            count  P1,10,W1
            COUNT  P2,10,W2 
            W3 = (W1 HYP W2)               'HYPOTENUSE CALCULATION 
            if W3 > 120 THEN               'Turn on lrd if Hypot is over 
            HIGH LED                       'Turn on led on RB0
            ENDIF
            'if W3 < 100 then
            'low led
            'endif  
            
            Serout SO,N2400,[#W3]
    
    disp:   Serout SO,N2400,[" Pulses",13,10]        ' Display trailer
            hpwm 1,W3,2000
    
                              
            Goto DISPLAYLOOP                 ' Forever
    Now I am trying to improve the design and I was told to try changing the PWM to a 50% duty cycle and very the frequency (hpwm 1,127,W5). This idea gives me my 15K but the lowest I can get is about 1.5KHz and I really need close to 0.
    I am trying to come up with a scheme that will use Timer 0 quickly sample the PWM output and replicate the output with a 1,500 hz offset. Any ideas would be appreciated.

    Code:
    '****************************************************************
    '*  Name    : Pulse Count.BAS                                      *
    '*  Author  : Jan                                      *
    '*  Notice  : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 27/12/2013                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : Count pulses in                                                  *
    '*          : 16F88                                                  *
    '****************************************************************
    
    Include "modedefs.bas"          ' Include serial modes
    define OSC 20
    
    #CONFIG __config _CONFIG1, _HS_OSC & _WDT_ON & _LVP_OFF & _CP_OFF & _CCPMX_RB3 & _CCP1_RB3 
    #ENDCONFIG    'Configure CCP1 (RB3) to PWM out
    
    
    SO      VAR PORTB.5     'Define serial out pin
    P1      var PORTA.0     'Define input pin  X
    P2      VAR PORTA.1     'Define input pin  Y
    
    W1      var WORD 
    W2      VAR WORD
    W3      VAR WORD
    W4      var word
    W5      var word
    
    led     var PORTB.0       
    
    TRISA = %11111111
    ANSEL = %00000000
    output   led               
    low      led               'set led off
    
     displayloop:
    
            count  P1,10,W1
            COUNT  P2,10,W2
          
            W3 = (W1 HYP W2)               'HYPOTENUSE CALCULATION 
            if W3 > 120 THEN               'Turn on lrd if Hypot is over 
            HIGH LED                       'Turn on led on RB0
            ENDIF
            W4 = (W3 + 20)                 'Add 20 to overcome min pwm frequence
            W5 = (W4 * 100)                'Times 100 to give min of 2 kHz
            Serout SO,N2400,[#W5]
    
    disp:   Serout SO,N2400,[" Pulses",13,10]        ' Display trailer
            hpwm 1,127,W5
          
                              
            Goto DISPLAYLOOP                 ' Forever
    Thanks Jan
    Last edited by Demon; - 21st January 2014 at 02:31. Reason: Helped format your code using [CODE]...[/CODE] feature

Similar Threads

  1. Replies: 0
    Last Post: - 7th August 2008, 09:02
  2. State machine programming
    By tjstevens in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th April 2007, 22:45
  3. Help - ID a 3.0V regulator (SOT23-5)
    By badcock in forum Off Topic
    Replies: 0
    Last Post: - 8th June 2006, 15:00
  4. voltage regulator help - ot
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 29
    Last Post: - 17th May 2006, 00:37
  5. Help with a Parallel I/O to Machine Interface?
    By john meiers in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 16th September 2005, 18:50

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts