PICAXE unipolar stepper motor controller

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

 if speeddir>128 then  'find direction and store in direc (1 is +ve, 0 is -ve)
 'gets the speed 0-127 negative, 128-255 positive (higher =faster)

 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
   gosub moverotor  'set the rotor position for this step
 next counter

 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

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 Responses to PICAXE unipolar stepper motor controller

  1. Jim Rybak says:

    What specific Darlington driver array did you use with your stepper motor controller?

  2. […] 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 […]

  3. […] 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 […]

  4. DIY Audio says:

    DIY Audio…

    […]PICAXE unipolar stepper motor controller « dmt195 today[…]…

  5. Free Gaming Supplies…

    […]PICAXE unipolar stepper motor controller « dmt195 today[…]…

  6. Ayman says:

    Can we use the same PICAXE programming cable to communicate with the PICAXE instead of using another serial cable?

    Can we use hyperterminal for this communication?

    Sorry for being novice

  7. Ayman says:

    Sorry, I found that this can be done, but I could send from PICAXE to the PC “hyperterminal” but could not send, I think there is some mistake, I’m just tryng to send data from PC to the controller and putting the byte I get to the port B, but it seems its not working


    let b2 = 0

    for b3 =0 to 10

    serout C.0,N2400,(“Enter your input”)

    pause 1000

    serin C.1,N2400,(b2)

    pause 1000

    serout C.0,N2400,(b2)

    outpinsB = b2

    next b3

    pause 1000
    goto main


  8. Ayman says:

    I found that

    serin C.1,N2400,(b2) is the issue, it should be serin C.1,N2400,b2

    b2 is the first byte to receive , we can receive multiple bytes

    serin C.1,N2400,b2,b3,b4
    But the most important question , is there a specific requirements for the control circuit in order to work with some CNC software like MACH 3, where can we find such information ?

  9. noxxie is a lesson in self promotion…

    […]PICAXE unipolar stepper motor controller « dmt195 today[…]…

  10. Ahmad Hussain says:

    If i want to control the the speed of the stepper motor than what should i do.?
    can i use a digital potentiometer. which dp i can use?
    Please reply me at ahmadhussain101@gmail.com

    • dmt195 says:

      Stepper motors are very different to dc motors. Applying current to a loop will hold the rotor in a certain position. A potentiometer in that loop would only control how well that position is held.
      To turn the motor you need to cycle which circuits are powered (read this and other posts carefully for more info). Think of a monkey swinging between branches.
      You generally need some logic to arrange that for you. That logic could also read the voltage across a potentiometer and use that as a metric in how quickly to rotate the motor.
      I hope that helps and that I’ve understood your question correctly.

  11. Very nice post. I just stumbled upon your weblog and wished to
    say that I’ve really enjoyed surfing around your blog posts. In any case I will be subscribing to your feed and I hope you write again soon!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: