StepperMotors

From ArduinoInfo
Jump to navigation Jump to search

STEPPER MOTORS

Example of Low-Cost small stepper motors and driver boards:

StepperMotor_Driver.jpg

You can see these in our shop:(HERE)

If you want just basic stepper motor knowledge, start with our detailed page about those motors and driver boards (HERE)

MORE DETAILED INFORMATION:


Details of our more powerful L298N boards is (HERE) But you should also use a separate 5 volt supply for any of these small motors. Maybe the 5V one (HERE) (Larger motors may require 12 volts or more).

The Arduino Library for Stepper motors is : (HERE) (This comes with the regular Arduino free software: Sketch > Import Library > Stepper. )

An advanced Library with more functions is (HERE). (This Supports acceleration and deceleration, and multiple simultaneous steppers, with independent concurrent stepping on each stepper)

And for more than you ever wanted to know :) : http://en.wikipedia.org/wiki/Stepper_motor

ABOUT STEPPER MOTORS:

An excellent page about stepper motors is on the RepRap 3D Printer WIKI here:

A stepper motor is a motor controlled by a series of electromagnetic coils. The center shaft has a series of magnets mounted on it, and the coils surrounding the shaft are alternately given current or not, creating magnetic fields which repulse or attract the magnets on the shaft, causing the motor to rotate.

This design allows for very precise control of the motor: by proper pulsing, it can be turned in very accurate steps of set degree increments (for example, two-degree increments, half-degree increments, etc.). They are used in printers, disk drives, and other devices where precise positioning of the motor is necessary.

There are two basic types of stepper motors, unipolar steppers and bipolar steppers:

Unipolar Stepper Motors

The unipolar stepper motor has five or six wires and four coils (actually two coils divided by center connections on each coil). The center connections of the coils are tied together and used as the power connection. They are called unipolar steppers because power always comes in on this one pole.

ONE of each pair of coils is activated at any one time. An example of this type of motor, with wiring diagram, is here:

Stepper-coils.jpg

Bipolar stepper motors

The bipolar stepper motor usually has four wires coming out of it. Unlike unipolar steppers, bipolar steppers have no common center connection. They have two independent sets of coils instead. You can distinguish them from unipolar steppers by measuring the resistance between the wires. You should find two pairs of wires with equal resistance. If you’ve got the leads of your meter connected to two wires that are not connected (i.e. not attached to the same coil), you should see infinite resistance (or no continuity).

Like other motors, stepper motors require more power than a microcontroller can give them, so you’ll need a separate power supply for it. Ideally you’ll know the voltage from the manufacturer, but if not, get a variable DC power supply, apply the minimum voltage (hopefully 3V or so), apply voltage across two wires of a coil (e.g. 1 to 2 or 3 to 4) and slowly raise the voltage until the motor is difficult to turn. It is possible to damage a motor this way, so don’t go too far. Typical voltages for a stepper might be 5V, 9V, 12V, 24V. Higher than 24V is less common for small steppers, and frankly, above that level it’s best not to guess.

To control the stepper, apply voltage to each of the coils in a specific sequence. The sequence would go like this:

Step wire 1 wire 2 wire 3 wire 4
1 High low high low
2 low high high low
3 low high low high
4 high low low high

To control a unipolar stepper, you might use a Darlington Transistor Array. The stepping sequence is as shown above. Wires 5 and 6 are wired to the supply voltage.

Stepper-wiring.jpg

To control a bipolar stepper motor, you give the coils current using to the same steps as for a unipolar stepper motor. However, instead of using four coils, you use the both poles of the two coils, and reverse the polarity of the current.The easiest way to reverse the polarity in the coils is to use a pair of H-bridges. The L293D dual H-bridge has two H-bridges in the chip, so it will work nicely for this purpose.

Stepper-bipolar-hbridge.jpg

Once you have the motor stepping in one direction, stepping in the other direction is simply a matter of doing the steps in reverse order.Knowing the position is a matter of knowing how many degrees per step, and counting the steps and multiplying by that many degrees. So for examples, if you have a 1.8-degree stepper, and it’s turned 200 steps, then it’s turned 1.8 x 200 degrees, or 360 degrees, or one full revolution.Two-Wire ControlThanks to Sebastian Gassner for ideas on how to do this.In every step of the sequence, two wires are always set to opposite polarities. Because of this, it’s possible to control steppers with only two wires instead of four, with a slightly more complex circuit.

The stepping sequence is the same as it is for the two middle wires of the sequence above:

Step wire 1 wire 2
1 low high
2 high high
3 high low
4 low low

The circuits for two-wire stepping are as follows:

Unipolar stepper two-wire circuit:

Unipolar stepper.png

Bipolar stepper two-wire circuit:

Bipolar stepper.jpg

Programming the Microcontroller to Control a Stepper:

Because both unipolar and bipolar stepper motors are controlled by the same stepping sequence, we can use the same microcontroller code to control either one. In the code examples below, connect either the Darlington transistor array (for unipolar steppers) or the dual H-bridge (for bipolar steppers) to the pins of your microcontroller as described in each example.

There is a switch attached to the microcontroller as well. When the switch is high, the motor turns one direction. When it’s low, it turns the other direction.

Stepper Motor Controller language: Wiring/Arduino This example uses the Stepper library for Wiring/Arduino. It was tested using the 2-wire circuit. To change to the 4-wire circuit, just add two more motor pins, and change the line that initalizes the Stepper library like so: Stepper myStepper(motorSteps, motorPin1,motorPin2,motorPin3,motorPin4);

This program drives a unipolar or bipolar stepper motor. The motor is attached to digital pins 8 and 9 of the Arduino. The motor moves 100 steps in one direction, then 100 in the other.

Created 11 Mar. 2007
Modified 7 Apr. 2007
by Tom Igoe

*/

define the pins that the motor is attached to. You can use
any digital I/O pins.

#include <Stepper.h>

#define motorSteps 200 change this depending on the number of steps
per revolution of your motor
#define motorPin1 8
#define motorPin2 9
#define ledPin 13

initialize of the Stepper library:
Stepper myStepper(motorSteps, motorPin1,motorPin2);

void setup() {
set the motor speed at 60 RPMS:
myStepper.setSpeed(60);

Initialize the Serial port:
Serial.begin(9600);

set up the LED pin:
pinMode(ledPin, OUTPUT);
blink the LED:
blink(3);
}

void loop() {
Step forward 100 steps:
Serial.println("Forward");
myStepper.step(100);
delay(500);

Step backward 100 steps:
Serial.println("Backward");
myStepper.step(-100);
delay(500);

}

Blink the reset LED:
void blink(int howManyTimes) {
int i;
for (i=0; i< howManyTimes; i++) {
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
delay(200);
}
}


Stepper motor drive circuits

(From http://en.wikipedia.org/wiki/Stepper_motor )

Stepper motor performance is strongly dependent on the drive circuit. Torque curves may be extended to greater speeds if the stator poles can be reversed more quickly, the limiting factor being the winding inductance. To overcome the inductance and switch the windings quickly, one must increase the drive voltage. This leads further to the necessity of limiting the current that these high voltages may otherwise induce.

L/R drive circuits

L/R drive circuits are also referred to as constant voltage drives because a constant positive or negative voltage is applied to each winding to set the step positions. However, it is winding current, not voltage that applies torque to the stepper motor shaft. The current I in each winding is related to the applied voltage V by the winding inductance L and the winding resistance R.

The resistance R determines the maximum current according to Ohm's lawI=V/R.

The inductance L determines the maximum rate of change of the current in the winding according to the formula for an InductordI/dt = V/L.

Thus when controlled by an L/R drive, the maximum speed of a stepper motor is limited by its inductance since at some speed, the voltage U will be changing faster than the current I can keep up. In simple terms the rate of change of current is L / R (e.g. a 10mH inductance with 2 ohms resistance will take 5 ms to reach approx 2/3 of maximum torque or around 24 msec to reach 99% of max torque).

To obtain high torque at high speeds requires a large drive voltage with a low resistance and low inductance. With an L/R drive it is possible to control a low voltage resistive motor with a higher voltage drive simply by adding an external resistor in series with each winding. This will waste power in the resistors, and generate heat. It is therefore considered a low performing option, albeit simple and cheap.

Chopper drive circuits

Chopper drive circuits are also referred to as constant current drives because they generate a somewhat constant current in each winding rather than applying a constant voltage. On each new step, a very high voltage is applied to the winding initially. This causes the current in the winding to rise quickly since dI/dt = V/L where V is very large. 

The current in each winding is monitored by the controller, usually by measuring the voltage across a small sense resistor in series with each winding.

When the current exceeds a specified current limit, the voltage is turned off or "chopped", typically using power transistors. When the winding current drops below the specified limit, the voltage is turned on again.

In this way, the current is held relatively constant for a particular step position. This requires additional electronics to sense winding currents, and control the switching, but it allows stepper motors to be driven with higher torque at higher speeds than L/R drives. Integrated electronics for this purpose are widely available.