Shop OBEX P1 Docs P2 Docs Learn Events
Stepper Motor on BS2: Help! — Parallax Forums

Stepper Motor on BS2: Help!

putrificationputrification Posts: 3
edited 2011-03-01 01:35 in BASIC Stamp
I have just gotten a stepper motor, and am using a BS2 BASIC Stamp, and was wondering, is there a way for me to, instead of moving the motor forwards and backwards by individual steps, can I point to specific steps and move to those ones directly?

Here's the Sample Code that came with the motor, if it helps:
' {$STAMP BS2}
' {$PBASIC 2.5}

Phase VAR OUTB ' phase control outputs

StpsPerRev CON 48 ' whole steps per rev

idx VAR Byte ' loop counter
stpIdx VAR Nib ' step pointer
stpDelay VAR Byte ' delay for speed control

Steps DATA %0011, %0110, %1100, %1001


Setup:
DIRB = %1111 ' make P4..P7 outputs
stpDelay = 15 ' set step delay


Main:
FOR idx = 1 TO StpsPerRev ' one revolution
  GOSUB Step_Fwd ' rotate clockwise
NEXT
PAUSE 500 ' wait 1/2 second
FOR idx = 1 TO StpsPerRev ' one revolution
  GOSUB Step_Rev ' rotate counter-clockwise
NEXT
PAUSE 500 ' wait 1/2 second
GOTO Main
END


Step_Fwd:
stpIdx = stpIdx + 1 // 4 ' point to next step
GOTO Do_Step


Step_Rev:
stpIdx = stpIdx + 3 // 4 ' point to previous step
GOTO Do_Step


Do_Step:
READ (Steps + stpIdx), Phase ' output new phase data
PAUSE stpDelay ' pause between steps
RETURN

Edit:
I have this motor: 12-Volt Unipolar Stepper Motor (#27964)

Comments

  • ercoerco Posts: 20,256
    edited 2010-11-20 21:35
    The short answer is no.

    Long answer: steppers are useful because they rotate a fixed amount per pulse, so in order to go to position B, your software must know current position A and send the proper sequence and number of pulses to drive the motor to position B. You can rotate a stepper any number of times to any position, but your code always has to keep track of where the motor is.

    An RC servo can be commanded to go to a certain position by sending a string of pulses to it. Servos generally rotate from 90-180 degrees. A servo requires just one IO pin, easier to use than a stepper motor. A Parallax ServoPal can be used to send a pulse train to the servo and free up your Stamp to other things.
  • putrificationputrification Posts: 3
    edited 2010-11-20 22:08
    So, there's no way I couldsay "Currently you're at position B, we want you at position A. Position A is (Position B - Position A) counter-clockwise steps away."? On a side note, I have already purchased the stepper mentioned above, and I have a deadline for my project coming up pretty soon, I'll keep that in mind for next time though, thanks.
  • LeonLeon Posts: 7,620
    edited 2010-11-20 22:31
    You could do that if you have a limit switch that is read by the controller - rotate the stepper until the switch closes, and you then have a known starting point. Or, put an absolute encoder on the stepper. They are expensive, though.
  • putrificationputrification Posts: 3
    edited 2010-11-21 00:44
    Hmm, that limit switch idea sounds easy enough. Definitely something to look into. Thanks for the input!
  • LittlebuckLittlebuck Posts: 7
    edited 2011-02-26 14:50
    Hi,
    It seems to me that if you use a few registers you can achieve what you want.
    Keep the pulse count of where you are at in a register.
    Put the pulse count for where you want to go in a register.
    Perform a math operation and put the result in a register.
    If the sum is negative, pulse the motor C.C.W. x sum in register
    If the sum is positive, pulse the motor C.W. x sum in register.
    Then, overwrite the new position (sum) in the original count register.
    I don't know code for it, but that's the principle.
    The only drawback is that you might accumulate error after extended use.
    Maybe you could add a switch for home position / error check. Then reset the register of where you are at.
    I have a project in mind for this as well.
    Hope this helps.
  • LittlebuckLittlebuck Posts: 7
    edited 2011-02-26 14:54
    Sorry,
    I didn't mean positive or negative,
    Should be Less than or greater than original vakue in register.
  • LittlebuckLittlebuck Posts: 7
    edited 2011-02-27 08:22
    Hey, I ran across an old post which should be helpful as well. Go to Forum search, Advanced search, User name = Newzed, Topic = Stepper Control, Date is Mar 8 or 9 2005, hit search.
  • StampmysterStampmyster Posts: 27
    edited 2011-03-01 01:35
    Have you taken a look at the Little Step-U controller? You can find it in the Parallax Store.

    They are easy to use and, I believe, will do all that you ask. No doubt.

    However, if writing raw-code for stepping motors is an assigned school project requirement, it would certainly be considered cheating!
Sign In or Register to comment.