Stepper Motor on BS2: Help!
putrification
Posts: 3
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:
Edit:
I have this motor: 12-Volt Unipolar Stepper Motor (#27964)
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
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.
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.
I didn't mean positive or negative,
Should be Less than or greater than original vakue in register.
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!