Shop OBEX P1 Docs P2 Docs Learn Events
More Stepper programhelp needed. — Parallax Forums

More Stepper programhelp needed.

NWUpgradesNWUpgrades Posts: 292
edited 2009-06-18 01:48 in BASIC Stamp
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

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-06-15 18:54
    Can't tell what's wrong without more information. Just describing roughly what you tried doesn't help. The details matter.
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-06-15 19:08
    OK, Below is the code I typed. What happens is the motor is going CW and CCW without pressing· IN 3 or IN 4. I tested the input·on an LED to make sure the pulsout is working.

    ' {$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
  • FranklinFranklin Posts: 4,747
    edited 2009-06-15 20:38
    What are the values of IN3 and IN4 if the buttons are not pressed? Just what does your code do?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Mike GreenMike Green Posts: 23,101
    edited 2009-06-15 20:44
    How do you have the buttons connected to pins 3 and 4?
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-06-15 20:47
    Via a wired switch I made. It is basically a replica of the 2 switch project from the What's A Microcotroller manul. I basically just created this on my own PCB and have tested it with LED,s and also the Servo motors that come with the Boe Bot and it functions just fine with those.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-06-15 21:08
    Details matter. How about a description of how one of the switches is wired? What page of the manual? Did you wire it exactly the same? The fact that you tested it somehow with LEDs means little.

    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.
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-06-15 21:22
    Sorry. I used the diagram from page 65 of the What's A Microcontroller. I am using Pin 0 for Direction and Pin 1 for Step. Pin 3 is for CW and Pin 4 is for CCW. From the Switch I am using. Following the Schematic on page 64, the switch is identical with the exception that Pins 3 and for are Pins 0 and 1, and Pins 14 and 15 are Pins 3 and 4.
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-06-16 04:38
    My bad. It's page 84 and 85 of What's A Microcontroller
  • Mike GreenMike Green Posts: 23,101
    edited 2009-06-16 19:33
    Your description is confusing. In the What's a Microcontroller tutorial, pins 3 and 4 go high (1) when the corresponding button is pushed and low (0) when the button is released. There's usually some bounce involved, but may not be of any consequence in your program.

    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
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-06-17 19:46
    I got it figured out. Turns out that the power was draining to the LED's on my switch and sending incorrect voltage to the motor driver. Thanks for the help.
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-06-18 01:48
    Mike, How would I keep a pulse to the motor so as to keep it from moving, such as for a clamp that needs the torque when the motor is not actually moving?
Sign In or Register to comment.