Here’s my stepper motor controller, based on an 18 pin PICAXE microcontroller. The idea is that this chip takes away the processing overhead associated controlling a stepper. A master CPU (of some kind, potentially a PC) can send a serial command to the PICAXE telling it how much to move and at what speed (and direction). A Darlington driver array controls the power and a 7-segment display shows the current coil powering. Here’s the schematic (PICAXE programming connector not shown):
The way I’ve programmed this is different to other approaches I’ve seen. These tend to complete a full rotation every time. I’m sure others have done controllers that manage sub-rotation control like this but maybe not the way I’ve done it. I basically have a single value which defines how far the motor has rotated. I then increase this number step wise and use modulo division (//) to find out what position the rotor should have.
Program and video of operation after the break…
The code is as follows. This version now includes the direction and speed (achieved with the same second serial byte).
'Serial driven stepper motor by DMT195 symbol posrotor=b0 symbol numturns=b2 symbol speeddir=b7 symbol direc=b8 symbol pulsegap=b3 symbol counter=b4 symbol modrotor=b1 symbol outbyte=b5 posrotor = 1 'set starting position start: 'main sequence - wait for command then move the motor numturns=0 'sets a default number of turns high 7 'reset ready flag serin 0,T2400,(138),numturns,speeddir 'get serial data gosub getspeed 'get the direction and speed gosub move 'perform number of steps goto start getspeed: if speeddir>128 then 'find direction and store in direc (1 is +ve, 0 is -ve) direc=1 else direc=0 endif speeddir=speeddir//128 'gets the speed 0-127 negative, 128-255 positive (higher =faster) pulsegap=264-2*speeddir return move: for counter=1 to numturns pause pulsegap 'wait before moving again (set by speed) if direc=1 then posrotor=posrotor+1 'increase/decrease the step by one else posrotor=posrotor-1 endif gosub moverotor 'set the rotor position for this step next counter return moverotor: modrotor=posrotor//8 'find out where the rotor arm should be (1 of 8 positions) lookup modrotor, (0x01,0x03,0x02,0x06,0x04,0x0C,0x08,0x09), outbuyte 'in binary this is (%00000001,%00000011,%00000010,%00000110,%00000100,%00001100,%00001000,%00001001) 'looks up the step from the sequence and applies it to the output pins pins=outbyte return
And here’s a video of the thing in action. A second PICAXE chip is producing the serial data based on an ADC reading from a potentiometer. The red LED is used to indicate the PICAXE is ready for the next serial command. This was taken with my phone so sorry for the poor quality.
YouTube – Stepper motor control circuit
Updated: for speed and direction.
Updated 2: I significantly reduced the code size by using a lookup table rather than a select/case type sequence. Some of the code is clipped on the right but I’m sure it can be copied and pasted elsewhere in its entirity if it’s important. I haven’t quite worked out how to display code nicely and still correct quite yet!


13 October, 2008 at 10:28 pm |
What specific Darlington driver array did you use with your stepper motor controller?
12 January, 2009 at 8:18 pm |
I used one of these: ULN2003A. (http://www.maplin.co.uk/Module.aspx?ModuleNo=5502)
Sorry for the delay in replying. :-(
20 January, 2009 at 10:48 pm |
[...] Overall plan – to do Stepper controllers -Unipolar: Video, Committing to PCB, hardware and software design -Bipolar – to do (but see Sparkfun board) Servo controllers – linked from actions for 2009 Position [...]
28 January, 2009 at 10:28 pm |
[...] got a schematic and program for running a bipolar stepper motor via a serial interface (just as for the unipolar case). This is important for the robot arm cause because two of the three steppers will be of the [...]