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:
Choose the desired rotational speed of the stepper motor and consult your motor's data sheet to convert this to "steps per second."
Determine the step sequence for your motor. This information is also available in the data sheet.
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.
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.
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.
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.
Update each control pin according to the step sequence of the motor every time the program vectors to the interrupt service routine.
Increment a counter in your interrupt service routine so the program will know when to stop driving the motor.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for