Shop OBEX P1 Docs P2 Docs Learn Events
Stepper motor code help needed. — Parallax Forums

Stepper motor code help needed.

NWCCTVNWCCTV Posts: 3,629
edited 2013-07-02 22:56 in Propeller 1
I modified the Unipolar Stepper program from the OBEX so that the stepper motor turns clockwise when a button is pressed. I am using the motor and driver from this thread: http://forums.parallax.com/showthread.php/141149-3-Stepper-Motor-amp-Board?highlight=dollar+stepper Everything works as expected but I need to know how to end the program. The motor stops upon releasing the button on P4 but 2 of the lights on the ULN2003 driver board stay on. I tried QUIT but that kills the whole program. Just a little help at the end is all I need.
Here's the code. Thanks in advance for the help.

PUB main
   
  
    dira[3..0]~~                           'make pins outputs
    FullStep                               'High torque
  
PUB FullStep                               'High torque
  repeat                                   ' Main loop
    if ina[4] == 1                         ' If P3 pushbutton pressed
      stpDelay := 250                      'initial speed
      repeat 1                             'Distance
       stpDelay := 250                           
       stepFwd      
       waitcnt(clkfreq/stpDelay + cnt)    'speed   250 steps per second
      
 
PRI stepFwd
  stpIdx := ++stpIdx // 4                    ' point to next step
  outa[3..0] := Steps[stpIdx]                ' update outputs

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2013-07-02 22:41
    You could do something like this in your code...
    PUB FullStep                               'High torque
              repeat                                   ' Main loop
                if ina[4] == 1                         ' If P3 pushbutton pressed
                  stpDelay := 250                      'initial speed
                  repeat 1                             'Distance
                    stpDelay := 250                           
                    stepFwd      
                    waitcnt(clkfreq/stpDelay + cnt)    'speed   250 steps per second
    [B][COLOR="#FF0000"]              else    
                    outa[3..0]~[/COLOR][/B]
    
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-07-02 22:56
    That did it!!!! I thank you sir.
Sign In or Register to comment.