More Stepper programhelp needed.
NWUpgrades
Posts: 292
So I was able to get my code working with my controller, (As long as I ground the controller to my Homework board) However, I tried placing an IF THEN statement in it, but it did not work and continues as if there were no IF ThEN statement. I added IF (IN3 = 1) THEN just after Main: Any suggestions as to what I am doing wrong?
' {$STAMP BS2}
' {$PBASIC 2.5}
··· StepperDir····· PIN···· 0······················ ' direction control
··· StepperMove···· PIN···· 1······················ ' movement
··· CW············· CON···· 0
··· CCW············ CON···· 1
··· idx············ VAR···· Byte
··· Reset:
··· OUTPUT StepperDir
··· HIGH StepperMove····························· ' move on high-to-low transition
··· Main:
··· StepperDir = CW
··· FOR idx = 1 TO 100
··· PULSOUT StepperMove, 500
··· PAUSE 5
···· NEXT
··· StepperDir = CCW
··· FOR idx = 1 TO 100
··· PULSOUT StepperMove, 500
··· PAUSE 5
··· NEXT
··· GOTO Main
' {$STAMP BS2}
' {$PBASIC 2.5}
··· StepperDir····· PIN···· 0······················ ' direction control
··· StepperMove···· PIN···· 1······················ ' movement
··· CW············· CON···· 0
··· CCW············ CON···· 1
··· idx············ VAR···· Byte
··· Reset:
··· OUTPUT StepperDir
··· HIGH StepperMove····························· ' move on high-to-low transition
··· Main:
··· StepperDir = CW
··· FOR idx = 1 TO 100
··· PULSOUT StepperMove, 500
··· PAUSE 5
···· NEXT
··· StepperDir = CCW
··· FOR idx = 1 TO 100
··· PULSOUT StepperMove, 500
··· PAUSE 5
··· NEXT
··· GOTO Main
Comments
' {$STAMP BS2}
' {$PBASIC 2.5}
··· StepperDir····· PIN···· 0······················ ' direction control
··· StepperMove···· PIN···· 1······················ ' movement
··· CW············· CON···· 0
··· CCW············ CON···· 1
··· idx············ VAR···· Byte
··· Reset:
··· OUTPUT StepperDir
··· HIGH StepperMove
···························· ' move on high-to-low transition
··· Main:
··· IF (IN3 = 1) THEN
··· StepperDir = CW
··· FOR idx = 1 TO 100
··· PULSOUT StepperMove, 500
··· PAUSE 5
···· NEXT
···· ELSEIF (IN4 = 1) THEN
··· StepperDir = CCW
··· FOR idx = 1 TO 100
··· PULSOUT StepperMove, 500
··· PAUSE 5
··· NEXT
··· ENDIF
··· GOTO Main
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
When you design something and it works as you expect, you only need a detailed description if you're trying to make it possible for someone else to duplicate what you've done. When it doesn't work and you're asking for help, you need to always supply as much detail as possible. Usually you've made some kind of assumption and it's wrong and that's why the thing doesn't work.
In the program you showed, when you press the button attached to pin 3, StepperDir should be set to CW and you should get 100 high-low-high pulses, each 1ms with a 5ms pause between the pulses for a total of around 600ms of CW movement. If the button on pin 3 is not pressed, but the button on pin 4 is pressed, StepperDir should be set to CCW and you should get 100 high-low-high pulses, each 1ms with a 5ms pause between the pulses for a total of around 600ms of CCW movement. If you don't press either button, the program will continually test the button settings. If you hold one button down, the pulse trains will repeat.
StepperDir will not be changed when neither button is pressed and will retain its last setting.
If your program is not behaving as I described, one of several things must be true:
1) What you've compiled and downloaded to the Stamp is not what you've shown in your message.
2) What you've described for the wiring is not what you in fact have.
3) There's some kind of problem with your stepper motor driver.
4) You have a power supply problem.
You description of the behavior of your setup doesn't sound like #4 is happening