Shop OBEX P1 Docs P2 Docs Learn Events
stepper motor in a loop — Parallax Forums

stepper motor in a loop

eman53132eman53132 Posts: 6
edited 2006-12-13 23:58 in BASIC Stamp
i am trying to have a stepper motor do 40 steps clockwise when the input goes high, then do nothing until the input goes low. the low would then turn the motor 40 steps counterclockwise.

i have the stepper motor turning in both directions. i am stuck on on what to do next. i need the program to keep checking if the input has changed.


thanks,
e

Comments

  • PARPAR Posts: 285
    edited 2006-12-13 19:22
    eman53132 said...
    i am trying to have a stepper motor do 40 steps clockwise when the input goes high, then do nothing until the input goes low. the low would then turn the motor 40 steps counterclockwise.

    i have the stepper motor turning in both directions. i am stuck on on what to do next. i need the program to keep checking if the input has changed.
    Please post your program so we can see what your "next" thing to do is, as well as what your previous thing done was.

    PAR
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-12-13 20:55
    E,
    ·
    ·· All you need to do is have a conditional in your loop checking the status of the input.· When it is HIGH you GOSUB to a subroutine to step the Stepper Motor one way then return.· The ELSEIF section of the conditional will call the reverse subroutine which moves 40 steps.· This assumes you don’t need to stop once you start the 40 steps.· But the loop would do nothing until the input changed.
    ·
    ·· The other part of this equation is a flag variable.· This flag will be set when one routine runs and cleared when the other runs.· Your IF…THEN routine will check the state of the input AND the flag.· I will see if I can explain with some sample code…

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    Sensor  PIN   0
    flag    VAR   bit
    index   VAR   byte
    do
      IF Sensor = 1 AND flag = 0 THEN
        GOSUB Step_Forward
        flag = 1
      ELSEIF Sensor = 0 AND flag = 1 THEN
        GOSUB Step_Reverse
        flag = 0
      endif
    loop
    
    Step_Forward:
      FOR index = 0 TO 39
        ' Code to handle Stepper Motor
      NEXT
      return
    Step_Reverse:
      FOR index = 0 TO 39
        ' Code to handle Stepper Motor
      next
      return
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • eman53132eman53132 Posts: 6
    edited 2006-12-13 23:40
    thanks for the help.



    one more question.....how do i compare variables (ex. dsdata and s1)

    what i want them to do is if they are the same out10 goes low.· if they are different out10 goes high.·



    thanks

    e
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-12-13 23:44
    E,
    ·
    ·· This should work fine…Take care.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    dsData    VAR   byte
    s1        VAR   byte
    
    do
      IF dsData = s1 then
        LOW 10
      ELSE
        HIGH 10
      endif
    loop
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • eman53132eman53132 Posts: 6
    edited 2006-12-13 23:58
    thank thank thankhop.gifhop.gif
Sign In or Register to comment.