Stepper Motor Code
Archiver
Posts: 46,084
Hi,
I am new to Basic Stamps, I just got a BS2p 40 and want to use it to control
a robotic arm with six stepper motors.
I plan to use serial coms from a PC or Pocket PC to issues the movement
commands, and just use the Stamp to drive the stepper motor sequences.
I have written some PBASIC code, to generate the appropriate sequences, but
it is quite clumsy. Before I sit down a do a complete re-write, I was
wondering if there is some code already written that I can reuse, or if
anyone can point me to some functions that will help? I have included my
code below.
Many Thanks - Luke
'{$STAMP BS2p}
'{$PBASIC 2.5}
Direction VAR Bit '0 for CW 1 for CCW
StepType VAR Bit '0 for half step 1 for full step
Revs VAR Word
StepDelay VAR Word
L VAR Word
Direction = 1
StepType = 1
Revs = 10
StepDelay = 250 '20
DIRA =%1111
IF StepType = 0 THEN
IF Direction = 0 THEN
GOTO HalfStepCW
ELSE
GOTO HalfStepCCW
ENDIF
ELSE
IF Direction = 0 THEN
GOTO FullStepCW
ELSE
GOTO FullStepCCW
ENDIF
ENDIF
HalfStepCW:
L=1
FOR L =1 TO Revs
OUTA =%1000
PAUSE StepDelay
OUTA =%1100
PAUSE StepDelay
OUTA =%0100
PAUSE StepDelay
OUTA =%0110
PAUSE StepDelay
OUTA =%0010
PAUSE StepDelay
OUTA =%0011
PAUSE StepDelay
OUTA =%0001
PAUSE StepDelay
OUTA =%1001
PAUSE StepDelay
NEXT
GOTO ll
HalfStepCCW:
L=1
FOR L =1 TO Revs
OUTA =%0001
PAUSE StepDelay
OUTA =%0011
PAUSE StepDelay
OUTA =%0010
PAUSE StepDelay
OUTA =%0110
PAUSE StepDelay
OUTA =%0100
PAUSE StepDelay
OUTA =%1100
PAUSE StepDelay
OUTA =%1000
PAUSE StepDelay
OUTA =%1001
PAUSE StepDelay
NEXT
GOTO ll
FullStepCW:
L=1
FOR L =1 TO Revs
OUTA =%1000
PAUSE StepDelay
OUTA =%0100
PAUSE StepDelay
OUTA =%0010
PAUSE StepDelay
OUTA =%0001
PAUSE StepDelay
NEXT
GOTO ll
FullStepCCW:
L=1
FOR L =1 TO Revs
OUTA =%0001
PAUSE StepDelay
OUTA =%0010
PAUSE StepDelay
OUTA =%0100
PAUSE StepDelay
OUTA =%1000
PAUSE StepDelay
NEXT
GOTO ll
ll:
[noparse][[/noparse]Non-text portions of this message have been removed]
I am new to Basic Stamps, I just got a BS2p 40 and want to use it to control
a robotic arm with six stepper motors.
I plan to use serial coms from a PC or Pocket PC to issues the movement
commands, and just use the Stamp to drive the stepper motor sequences.
I have written some PBASIC code, to generate the appropriate sequences, but
it is quite clumsy. Before I sit down a do a complete re-write, I was
wondering if there is some code already written that I can reuse, or if
anyone can point me to some functions that will help? I have included my
code below.
Many Thanks - Luke
'{$STAMP BS2p}
'{$PBASIC 2.5}
Direction VAR Bit '0 for CW 1 for CCW
StepType VAR Bit '0 for half step 1 for full step
Revs VAR Word
StepDelay VAR Word
L VAR Word
Direction = 1
StepType = 1
Revs = 10
StepDelay = 250 '20
DIRA =%1111
IF StepType = 0 THEN
IF Direction = 0 THEN
GOTO HalfStepCW
ELSE
GOTO HalfStepCCW
ENDIF
ELSE
IF Direction = 0 THEN
GOTO FullStepCW
ELSE
GOTO FullStepCCW
ENDIF
ENDIF
HalfStepCW:
L=1
FOR L =1 TO Revs
OUTA =%1000
PAUSE StepDelay
OUTA =%1100
PAUSE StepDelay
OUTA =%0100
PAUSE StepDelay
OUTA =%0110
PAUSE StepDelay
OUTA =%0010
PAUSE StepDelay
OUTA =%0011
PAUSE StepDelay
OUTA =%0001
PAUSE StepDelay
OUTA =%1001
PAUSE StepDelay
NEXT
GOTO ll
HalfStepCCW:
L=1
FOR L =1 TO Revs
OUTA =%0001
PAUSE StepDelay
OUTA =%0011
PAUSE StepDelay
OUTA =%0010
PAUSE StepDelay
OUTA =%0110
PAUSE StepDelay
OUTA =%0100
PAUSE StepDelay
OUTA =%1100
PAUSE StepDelay
OUTA =%1000
PAUSE StepDelay
OUTA =%1001
PAUSE StepDelay
NEXT
GOTO ll
FullStepCW:
L=1
FOR L =1 TO Revs
OUTA =%1000
PAUSE StepDelay
OUTA =%0100
PAUSE StepDelay
OUTA =%0010
PAUSE StepDelay
OUTA =%0001
PAUSE StepDelay
NEXT
GOTO ll
FullStepCCW:
L=1
FOR L =1 TO Revs
OUTA =%0001
PAUSE StepDelay
OUTA =%0010
PAUSE StepDelay
OUTA =%0100
PAUSE StepDelay
OUTA =%1000
PAUSE StepDelay
NEXT
GOTO ll
ll:
[noparse][[/noparse]Non-text portions of this message have been removed]
Comments
I don't think that I would do it this way. For one, stepper motors require
move current than a stamp can provide. This requires support chips. There
are stepper motor driver chips available that take care of all of the
pulsing of the coils for you. These chips are much cheeper than a
stamp. You could get serial data from the pc via the stamp then write to
the individual chips that will control the stepper motors.
Brian G.
wrote:
> Hello,
>
> I don't think that I would do it this way. For one, stepper motors
require
> move current than a stamp can provide. This requires support
chips. There
> are stepper motor driver chips available that take care of all of
the
> pulsing of the coils for you. These chips are much cheeper than a
> stamp. You could get serial data from the pc via the stamp then
write to
> the individual chips that will control the stepper motors.
>
> Brian G.
A agree.
Steppers require power.
also to get more than jerky movement, you need to get away from the
serial control.
If you wanna see the differences, hook up a Stamp to an H-bridge for
motor control, actually 2 or 3 if you can for the test.
Then have the Stamp run some sensors and movement.
Then connect a second stamp to the sensors, and the second would just
pulse out to the first for steps. The first would handle the control
on a digial input basis from the second chip.
Then connect the 2 Stamps with a serial comm and repeat.
Dave
thanks for your reply. i was aware that the Stamp was not suitable
for the amount of power required, i just want to use it to generate
the signals, they will be put through Quad V-MOS Power FET VQ1000Js.
i have no experience of stepper motor comtrol chips. how do they
work? can you point me to one suitable for small 12v - 15v motors?
(5 wire 7.5 degree step).
many thanks.
--- In basicstamps@yahoogroups.com, Brian Gracia <bgracia1@b...>
wrote:
> Hello,
>
> I don't think that I would do it this way. For one, stepper
motors require
> move current than a stamp can provide. This requires support
chips. There
> are stepper motor driver chips available that take care of all of
the
> pulsing of the coils for you. These chips are much cheeper than a
> stamp. You could get serial data from the pc via the stamp then
write to
> the individual chips that will control the stepper motors.
>
> Brian G.
> hi,
>
> thanks for your reply. i was aware that the Stamp was not suitable
> for the amount of power required, i just want to use it to generate
> the signals, they will be put through Quad V-MOS Power FET VQ1000Js.
>
> i have no experience of stepper motor comtrol chips. how do they
> work? can you point me to one suitable for small 12v - 15v motors?
> (5 wire 7.5 degree step).
>
> many thanks.
The Allegro 5803 was the preferred chip until it became phased out.
The difference as far as you are concerned is that a driver chip
would offer the operation by 2 of the Stamp pins, one for STEP
signals and the other for DIRECTION.
If you are just running the stepper motor at the nameplate voltage,
then you can simply use rated transistors.
Assuming you are using small, pressed steel can motors, they are most
likely less than 5 watts. with 12 volts that means the coils will be
around 400 mA. Check the coil resistance to make sure.
I didn't check the Parallax site for stepper projects....
But, the logic is simple. Power is sent to the common wire with a
properly sized (for current) resistor.
Then each transistor is an NPN. With 5 wire, (unipolar) you need 4
Stamp pins.
When you pulse them, send an on to a transistor, then off, then
repeat with the next one.
To figure out which wires are which, if you don't know, connect any
two. and alternate pulses on those two. If the motor dithers (moves
back and forth) those are on different phases.
If the motor doesn't move, then they would be on the same phase.
To run, you would need to pulse
coil phase A1
coil phase B1
coil phase A2
Coil phase B2
This will make it run in one direction. Then reverse the pulse order
to get it spin the opposite way.
Good luck !
Dave
>
>
> --- In basicstamps@yahoogroups.com, Brian Gracia <bgracia1@b...>
> wrote:
> > Hello,
> >
> > I don't think that I would do it this way. For one, stepper
> motors require
> > move current than a stamp can provide. This requires support
> chips. There
> > are stepper motor driver chips available that take care of all of
> the
> > pulsing of the coils for you. These chips are much cheeper than
a
> > stamp. You could get serial data from the pc via the stamp then
> write to
> > the individual chips that will control the stepper motors.
> >
> > Brian G.