PWM Motor Control with Soft Start, Soft Stop Example Please
+ Reply to Thread
Results 1 to 15 of 15
  1. #1
    Join Date
    Oct 2004
    Location
    New Hampshire
    Posts
    116

    Default PWM Motor Control with Soft Start, Soft Stop Example Please

    Hi All,

    It has been a while!

    I need to drive a small 12v motor with PWM speed control to include soft start and stop. I would like to keep the circuit board small and I have a bunch of 675's at my disposal. Ultimately I would like to use a single pot to determine both speed and direction with half-way being the motor stop position. Can you point me to some fairly simple code examples (it has really been a while :-) to get me going?

    Thank you!!!

    Ross
    Never enough knowledge to be called intelligent but just enough knowledge to be considered dangerous!

    I like that! :-)

  2. #2
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    220

    Default Re: PWM Motor Control with Soft Start, Soft Stop Example Please

    Ross

    Here's a snippet of some old code that might get you started with the pot control:

    Code:
    DEFINE ADC_BITS     8   ' Set number of bits in result
    DEFINE ADC_CLOCK    3   ' Set clock source (3=rc)
    DEFINE ADC_SAMPLEUS 50  ' Set sampling time in uS
    
    Speed   VAR WORD
    Wait_1  VAR WORD
    
    ' Turn ON every other output varying speed with pot from center
    Pots:
        ADCIN 1, Speed
        
        IF Speed < 128 THEN       'Checks if pot in CCW position range
        wait_1 = ABS(Speed-128)   'Sets pot value to increase in CCW direction
        PORTC = $50               'Turn outputs 4 and 6 ON
        ENDIF
        PAUSE wait_1              'Pause with new pot value
        PORTC = $0                'Turn OFF all outputs
        
        IF Speed >= 128 THEN      'Checks if pot in CW position range
        wait_1 = (Speed-128)+1    'Sets pot value to increase in CW direction
        PORTC = $A0               'Turns outputs 5 and 7 ON
        ENDIF
        PAUSE wait_1              'Pause with new pot value
        PORTC = $0                'Turn OFF all outputs
    
    GOTO Pots
    This routine sets the pot to a plus/minus from center position for direction and speed value. Change the A/D to 10 bit for better resolution.
    It doesn't have dead band gap in center for the OFF position but you can change that.
    Then instead of using the A/D value for the "PAUSE wait_1" control, use it to adjust your PWM signal.
    Louie

  3. #3
    Join Date
    Oct 2004
    Location
    New Hampshire
    Posts
    116

    Default Re: PWM Motor Control with Soft Start, Soft Stop Example Please

    Thank you for replying Louie!

    Soooo... I'm leaning towards ditching the dead-band and throwing in a DPDT slide switch on the board edge. The switch determines motor direction and that leaves me with PWM motor speed and Soft Start/Stop. To get up and going, I'm going to put a resistor/capacitor timer between the pot and the A/D pin. Power to the pot will be through a foot switch. When power is supplied, the capacitor charges through the pot position and resistor. When power is removed, the capacitive charge drains back through the resistor and pot. That gives me soft start/stop. I'll get that going first then move to writing code to eliminate the RC circuit.

    Any thoughts, suggestions, wise-cracks?

    Ross
    Never enough knowledge to be called intelligent but just enough knowledge to be considered dangerous!

    I like that! :-)

  4. #4
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    220

    Default Re: PWM Motor Control with Soft Start, Soft Stop Example Please

    Your method simplifies it enough to get it started, especially after a long break.
    I'm guilty of diving fingers first with "intentional coding" then get stuck with paralysis of analysis.
    Louie

  5. #5
    Join Date
    Oct 2004
    Location
    New Hampshire
    Posts
    116

    Wink Re: PWM Motor Control with Soft Start, Soft Stop Example Please

    Amen to that brother!
    Never enough knowledge to be called intelligent but just enough knowledge to be considered dangerous!

    I like that! :-)

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,820

    Default Re: PWM Motor Control with Soft Start, Soft Stop Example Please

    Since you have the software, why would you put extra hardware for the soft start part?

    Consider a loop with maybe a for-next to increase the PWM to the set point gradually.

    Ioannis

  7. #7
    Join Date
    Oct 2004
    Location
    New Hampshire
    Posts
    116

    Default Re: PWM Motor Control with Soft Start, Soft Stop Example Please

    Loannis,

    Thank you for your confidence! I definitely want to do just that! But alas, I am a lowly mechanical engineer that dabbles in this stuff once a century and must admit my limitations. I'll be lucky to write code that uses PWM... and works! Every time I get back to this stuff I feel like I'm starting completely over. (...what the hell is a TRIS???) I have to dust off my PicStart Plus programmer, remember how to make a board with a laser printer and find that dang green programming book. So I bow to the genius' of this forum for grace and understanding.

    I will be starting with the BLINK program!

    If I am successful, you shall be the first to know!

    Thank you!

    Ross
    Never enough knowledge to be called intelligent but just enough knowledge to be considered dangerous!

    I like that! :-)

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,820

    Default Re: PWM Motor Control with Soft Start, Soft Stop Example Please

    Well, OK.

    This is just a as simple example as can it get, to help you start to experiment.

    Say your PWM variable to output is my_pwm and the range of values is 0-255:

    Code:
    my_pwm=0
    
    for i =0 to 255
        my_pwm=my_pwm+1
        hpwm channel, my_pwm, frequency
        pause 1
    next i
    Now you have a pwm signal ramping up to 100% in 2,55 seconds.

    Ioannis

  9. #9
    Join Date
    Oct 2004
    Location
    New Hampshire
    Posts
    116

    Default Re: PWM Motor Control with Soft Start, Soft Stop Example Please

    Thank you Ioannis!

    I've ordered parts for the circuit board. Should be complete and ready to program mid week. I'll be back when I start writing code.

    Thanks all!

    Ross
    Never enough knowledge to be called intelligent but just enough knowledge to be considered dangerous!

    I like that! :-)

  10. #10
    Join Date
    Oct 2004
    Location
    New Hampshire
    Posts
    116

    Default Re: PWM Motor Control with Soft Start, Soft Stop Example Please

    Can I get some help please looking this over.

    12f675 pwm motor speed control

    pot connected at GPIO.4 (AN.3)

    Output to the motor works. PWM works. Now trying to read pot. Not working.

    I checked between wiper and leg of pot and I'm getting wierd voltage. I don't think I have the presets right. It is acting like my port is conducting 5volts when it should be reading an analog voltage in.

    Any help would be appreciated. Thank you!

    Ross
    Code:
     Define OSCCAL_1K 1  ' Calibrate internal oscillator
    
       MOTOR VAR GPIO.2  ' Alias GPIO.2 to MOTOR
       ADVAL VAR WORD
       DUTY VAR Byte
       
        DEFINE  ADC_BITS        10       ' Set number of bits in result
        DEFINE  ADC_CLOCK       3       ' Set clock source (3=rc)
        DEFINE  ADC_SAMPLEUS    50      ' Set sampling time in uS
       
       TRISIO = %000100     ' GPIO 0,1,3,4,5 ARE INPUTS, 2 IS OUTPUT (MOTOR)
       ANSEL = %00001000   ' Set AN3 analog, rest digital
       ADCON0 = %10001100  ' Select AN3, Right justify result
       CMCON = 7           ' Analog comparators off
       
       
       pAUSE 500
       
    main:
        ADCIN 3, ADVAL     'READ ANALOG CHANNEL 3 AND PLACE IN ADVAL
        duty = adval / 4
        PWM MOTOR,duty,20
        GOTO MAIN
        END
    Never enough knowledge to be called intelligent but just enough knowledge to be considered dangerous!

    I like that! :-)

  11. #11
    Join Date
    May 2013
    Location
    australia
    Posts
    1,604

    Default Re: PWM Motor Control with Soft Start, Soft Stop Example Please

    TRISIO = %000100 ' GPIO 0,1,3,4,5 ARE INPUTS, 2 IS OUTPUT (MOTOR)// not really , quite the opposite

    you need to make gpio.4 an input before you can use it as analog
    have another read of the data sheet
    This is more entertaining than Free to Air TV

  12. #12
    Join Date
    Oct 2004
    Location
    New Hampshire
    Posts
    116

    Default Re: PWM Motor Control with Soft Start, Soft Stop Example Please

    Yep... my bad. I was confused because the motor on GPIO.2 was working. The PWM statement was toggling the port to output. I will change the TRIS statement to correct it.

    Can I get clarification on two other lines of code? I have trouble reading the data sheets. I am using AN3 on the chip. Is the following line correct?

    ADCON0 = %10001100 ' Select AN3, Right justify result
    Also... AN3 is on port GPIO.4. The Picbasic Pro manual's example uses the term "channel" instead of "port". I don't know if these terms are interchangeable as I have seen both used. When I read "channel" I think channel "AN3" which is on port "GPI0.4". Which of the following statements are correct please? I could use some clarification on the terminology.

    ADCIN 3, ADVAL 'READ ANALOG CHANNEL 3 AND PLACE IN ADVAL
    ADCIN AN3, ADVAL 'READ ANALOG CHANNEL 3 AND PLACE IN ADVAL
    ADCIN GPIO.4, ADVAL 'READ ANALOG CHANNEL 3 AND PLACE IN ADVAL
    I appreciate this community so very much! The support I have gotten here has really meant a lot to me!

    Thank you!

    Ross
    Never enough knowledge to be called intelligent but just enough knowledge to be considered dangerous!

    I like that! :-)

  13. #13
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    271

    Default Re: PWM Motor Control with Soft Start, Soft Stop Example Please

    You have to assign the result to a variable:

    Pot VAR BYTE
    ADCIN 3, Pot

  14. #14
    Join Date
    Oct 2004
    Location
    New Hampshire
    Posts
    116

    Default Re: PWM Motor Control with Soft Start, Soft Stop Example Please

    MPGMIKE,

    ADVAL VAR WORD

    ACDIN GPIO.4, ADVAL

    I used ADVAL instead of POT and it is already a word variable.

    Thank you,

    Ross
    Never enough knowledge to be called intelligent but just enough knowledge to be considered dangerous!

    I like that! :-)

  15. #15
    Join Date
    Oct 2004
    Location
    New Hampshire
    Posts
    116

    Default Re: PWM Motor Control with Soft Start, Soft Stop Example Please

    Update:

    I got the pwm motor control working:

    Code:
       Define OSCCAL_1K 1  ' Calibrate internal oscillator
    
       MOTOR VAR GPIO.2  ' Alias GPIO.2 to MOTOR
       LOW MOTOR         ' Make sure motor is off when powered up
       ADVAL VAR WORD
       DUTY VAR Byte
       AD VAR GPIO.4
       
        DEFINE ADC_BITS 10          ' Set number of bits in result
        DEFINE ADC_CLOCK 3          ' Set clock source (3=rc)
        DEFINE ADC_SAMPLEUS 50      ' Set sampling time in uS
       
       TRISIO = %111011     ' GPIO 0,1,3,4,5 ARE INPUTS, 2 IS OUTPUT (MOTOR)
       ANSEL = %00111000   ' Set AN3 analog, rest digital
       ADCON0 = %10000001  ' Right justify result and enable A/D
       CMCON = 7           ' Analog comparators off
       
       
       pAUSE 500
       
    main:
        ADCIN 3, ADVAL     'READ ANALOG CHANNEL 3 AND PLACE IN ADVAL
        duty = adval / 4
        PWM MOTOR,duty,20
        GOTO MAIN
        END
    Thank you for everyone's help!

    Ross
    Never enough knowledge to be called intelligent but just enough knowledge to be considered dangerous!

    I like that! :-)

Similar Threads

  1. Soft-start for mains LEDs?
    By ardhuru in forum Off Topic
    Replies: 10
    Last Post: - 29th September 2015, 14:54
  2. Soft On/Off switch
    By Audette in forum General
    Replies: 6
    Last Post: - 18th August 2012, 19:54
  3. 'Soft' On/Off Power Switch
    By Art in forum General
    Replies: 19
    Last Post: - 14th November 2008, 02:54
  4. Cad Soft Eagle?
    By fowardbias in forum Off Topic
    Replies: 1
    Last Post: - 4th September 2008, 08:28
  5. HT-Soft C compiler issues
    By ken_mazur in forum General
    Replies: 1
    Last Post: - 19th October 2006, 14:10

Members who have read this thread : 28

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