View Full Version : Stepper motor help

01-14-2008, 10:46 PM
Would some one be kind enough to explain briefly how I can use a stepper motor with my propeller. I am having a hard time understanding a way to code it. I am using an Allegero A2919SB IC. Here is my schematic.


01-15-2008, 12:06 AM
After a short view to the data sheet, here a short comment:

P1 is turning ON/OFF the current of PHASE2 (0=ON, 1=OFF)
P2 steers the direction of the current for PHASE2 (0=positive, 1=negative)

P3 same as P1 but for PHASE1
P4 same as P2 but for PHASE1

P5 lowers the output current.

You have to do the timing like the diagram in the attachment shows. It depends how you will drive the motor:

- Halfstep (save method with no risk of oscillations)
- Fullstep
- 1 phase mode
- 2 phase mode

I hope this helps a bit

Saluti Joerg

01-15-2008, 01:20 AM
Yes this helps a lot but i need some code to go off of as well.

01-15-2008, 01:59 AM
Check this out:
"Column #136: Stepping Out with Spin" is what you're looking for.

01-15-2008, 02:30 AM
YES, that is what i was looking for. Nice write up Thanks

01-15-2008, 02:32 AM
OK here some code!

connect P1 to P0, P2 to P1, P3 to P2 and P3 to P2 (first p is your controller, the second your Propeller chip!)

connect P5 to GND (VSS) or open (the propeller chip is a 3.3V chip!!)

Bit 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | State: 0 | 1
I I I I I I I I-------> Stop | Run
I I I I I I I-----------> Forward | Backward
I I I I I I---------------> Halfstep | Fullstep not implemented yet
I I I I I-------------------> SPhase | TPhase not implemented yet
I I I I-----------------------> Continous | Controled not implemented yet
I I I---------------------------> NU
I I-------------------------------> NU
I-----------------------------------> NU

Pin0 = P1
Pin0+1 = P2
Pin0+2 = P3
Pin0+3 = P4

P5 = VSS!!! (GND)


long Stack[14] 'Stack space for new cog
byte Cog 'Hold ID of cog in use, if any
byte StepNr 'the actual step number
long MCounter 'counter to hold the waitcycles

Run = 1
Backward = 2
FullStep = 4
TPhase = 8
Synch = 128

PUB Start(Pin0,AdrMotStat, AdrStepTime): Success

Success := (Cog := cognew(ManageMotor(Pin0,AdrMotStat, AdrStepTime), @Stack) + 1)

PUB Stop
{{Stop toggling process, if any.}}

if Cog
cogstop(Cog~ - 1)

PUB ManageMotor(Pin0, AdrMotStat, AdrStepTime)

StepNr~ 'clear the StepNr counter
dira[Pin0+7 .. Pin0]~~ 'sets the needed pins as output


repeat until byte[AdrMotStat] & Run 'wait until motor has to run!

if byte[AdrMotStat] & Backward

--StepNr 'backward
if StepNr == 255
StepNr := 7

++StepNr 'foreward
if StepNr > 7
StepNr := 0

outa[Pin0+3 .. Pin0] := STEPTBL[StepNr] 'set the outputs depending on the StepNr
waitcnt(clkfreq / 1_000_000 * long[AdrStepTime] + cnt) 'Wait for steptime cycles


STEPTBL byte 4, 0, 1, 2, 6, 10, 9, 8 'table for controling the motor (halfsteps)

and a little program for testing your hardware:


long StepTime
long ActPos
long RefPos
byte MotStat
byte SynchControl

byte Pin0

Motion : "Stepper_A2919"

PUB Main

StepTime := 100_000
MotStat := 0
Pin0 := 0
'' dira[16..19]~~


if ina[11..8] == 14
MotStat := 1
elseif ina[11..8] == 12
MotStat := 3
MotStat := 0

I hope it works

Saluti Joerg

01-15-2008, 06:28 AM
Thanks for the code example. I almost have it working now.