NU32: Driving a stepper motor
Driving a unipolar stepper motor using the TB6612 H-bridge and the NU32
Overview
The stepper motor included in the NU32 motor kit is a unipolar stepping motor with 95 ohms per half coil and a 7.5 degree per step size. It has a 3:25 gearhead, so the output shaft will make 1 revolution after 400 steps.
We will ignore the center taps of the unipolar motor and treat it as a bipolar motor, so that we can drive it with both bridges on the TB6612.
H-Bridge datasheet for driving the stepper motor
To make the motor step, we need to turn on the coils in a specific order. We need to have positive current or negative current going through the coils like this:
Coil 1 | Coil 2 |
+ | + |
+ | - |
- | - |
- | + |
The direction of the coil current is controlled by the TB6612. We always want the current on, so fix the PWM pin high. For positive current, we want OUT1 to be high, and OUT2 to be low. This corresponds to IN1 to be high, and IN2 to be low. To get negative current, we reverse the input pins.
In code, we will run through the table above at a fixed frequency to get a constant stepping speed. We will create a global variable, stepIndex, to know which coil state we are in, and use a switch() statement to know which state to go to next. By increasing stepIndex will will move in one direction, and decreasing stepIndex will rotate in the other direction. We must be careful to rollover stepIndex so that there are only 4 states.
Wiring
Code
The following code, NU32_stepper_example.c, uses timer 2 to step through the stepping sequence at 25Hz, resulting in 1 revolution of the output shaft ever 16s. Press and hold the USER button to reverse direction.
Try increasing the frequency of timer 2.
Details
Use the following table to determine the motor output:
More Information
NA