How to program a microprocessor to control a stepper motor

Written by joseph west
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to program a microprocessor to control a stepper motor
Stepper motors enable robotic machinery to achieve precise movements. (robot soudeur image by photlook from

A stepper motor is different from most motors in that it is designed to move in individual (or "discrete") steps. Specialised controller chips or microprocessors generate carefully designed sequences of voltage pulses that determine the speed and rotational direction of the stepper motor. Stepper motors are not typically intended for high-speed operation, so the pulse frequency is low. Consequently, almost any microprocessor can drive a stepper motor without significant processor loading.

Skill level:


  1. 1

    Choose the desired rotational speed of the stepper motor and consult your motor's data sheet to convert this to "steps per second."

  2. 2

    Determine the step sequence for your motor. This information is also available in the data sheet.

  3. 3

    Allocate port pins to drive the stepper control lines. Most steppers have four control lines, so you will probably need four pins. Remember to configure these pins as outputs.

  4. 4

    Divide one by the desired speed of the motor in steps per second. This gives you the step period, in other words, the amount of time between steps.

  5. 5

    Configure a timer to fire an interrupt when it overflows. Call this the step timer. Every time the step timer overflows, the processor will vector to an interrupt service routine. This is where you will update the stepper control pins and load a new timeout value into the timer.

  6. 6

    Configure the timer to have an overflow period much longer than the step period and start the timer. You will need to accelerate (and, if possible, decelerate) the motor, so you must gradually decrease the overflow period until you reach the desired step period. For optimal operation, implement a linear-velocity acceleration profile as described in the application note from Silicon Laboratories.

  7. 7

    Update each control pin according to the step sequence of the motor every time the program vectors to the interrupt service routine.

  8. 8

    Increment a counter in your interrupt service routine so the program will know when to stop driving the motor.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.