This section of tutorial will explain you everything that you need to know about stepper motors. Stepper motors can be used in various areas of your microcontroller projects such as making robots, robotic arm, automatic door lock system etc. This tutorial will explain you construction of stepper motors (unipolar and bipolar stepper motors ), basic principle, different controlling types (Half step and Full step), Interfacing Techniques (using L293D or ULN2003) and programming your microcontroller in C and assembly to control stepper motor.
1. Unipolar stepper motor
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.
2. Bipolar stepper motor
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).
As already said, we will talk mostly on "Unipolar stepper motors" which is most common type of stepper motor available in the market. A simple example of 6 lead step motor is given below and in 5 lead step motor wire 5 and 6 are joined together to make 1 wire as common.
Working of Stepper Motor
Now lets discuss the operation principle of a stepper motor. When we energize a coil of stepper motor, The shaft of stepper motor (which is actually a permanent magnet) align itself according to poles of energized coil. So when motor coils are energized in a particular sequence, motor shaft tend to align itself according to pole of coils and hence rotates. A small example of energizing operation is given below.
You can see in the example, when coil "A" is energized, A north-south polarity is generated at "A+A\" as shown in the figure above and magnetic shaft automatically align itself according to the poles generated. When the next coil is energized the shaft again align itself and take a step. Hence the working principle.
We have seen that to make the stepper motor work, we need to energize coil in a sequence. The explanation and generation of the sequence is explained in the next section of the tutorial.
Stepper motors can be driven in two different patterns or sequences. namely,
- Full Step Sequence
- Half Step Sequence
Full Step Sequence
In the full step sequence, two coils are energized at the same time and motor shaft rotates. The order in which coils has to be energized is given in the table below.
The working of the full mode sequence is given in the animated figure below.
Half Step Sequence
In Half mode step sequence, motor step angle reduces to half the angle in full mode. So the angular resolution is also increased i.e. it becomes double the angular resolution in full mode. Also in half mode sequence the number of steps gets doubled as that of full mode. Half mode is usually prefer over full mode. Table below shows the pattern of energizing the coils.
The working of the half mode sequence is given in the animated figure below.
Step Angle
Step angle of the stepper motor is defined as the angle traversed by the motor in one step. To calculate step angle,simply divide 360 by number of steps a motor takes to complete one revolution. As we have seen that in half mode, the number of steps taken by the motor to complete one revolution gets doubled, so step angle reduces to half.
As in above examples, Stepper Motor rotating in full mode takes 4 steps to complete a revolution, So step angle can be calculated as...
Step Angle ø = 360° / 4 = 90°
and in case of half mode step angle gets half so 45°.
So this way we can calculate step angle for any stepper motor. Usually step angle is given in the spec sheet of the stepper motor you are using. Knowing stepper motor's step angle helps you calibrate the rotation of motor also to helps you move the motor to correct angular position.
Step Sequence for 2-wire control of Unipolar stepper motor
As seen in above explanation, 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 coils A and B, and the opposite polarity value is given to A\ and B\. The sequence is given in the table below:
Step Sequence for Bipolar stepper motor
Bipolar motor has simpler construction. It has two windings with no center taps and a permanent magnet at the center just like unipolar stepper motors. Being simpler in construction, the stepping sequence is a little complex, as the power for both the coils has to be controlled in such a way that the polarity of the poles get reversed. This polarity sequence is shown in the table below.
The above polarity sequence can be interpreted in terms of logic levels for microcontroller by activating one coil at a time as shown in the table below.
We have now learn most of the necessary things regarding a stepper motor. In the next section we will discuss about the various techniques to interface a stepper motor.
Connecting Unipolar Stepper Motor
There are actually many ways you can interface a stepper motor to your controller, out of them the most used interfaces are:
- Interface using L293D - H-Bridge Motor Driver
- Interface using ULN2003/2004 - Darlington Arrays
Connecting Unipolar stepper using L293D
As you see in the circuit above the four pins "Controller pin 1",2,3 and 4 will control the motion and direction of the stepper motor according to the step sequece programmed in the controller.
Connecting Unipolar stepper using ULN2003/2004
As already discussed in case of L293D, Here in this circuit too the four pins "Controller pin 1",2,3 and 4 will control the motion and direction of the stepper motor according to the step sequence sent by the controller.
2-wire connection for Unipolar Stepper Motor
We have seen the generally used 4-wire connection method for interfacing unipolar stepper motor, but we can simplify the design to make controller use less pins with the help of 2-wire connection method. The circuit for 2-wire connection is shown below.
Connecting Bipolar Stepper Motor
As we have studied that, Bi-polar stepper motors has 2 different coils. The step sequence for Bipolar stepper motor is same as that of unipolar stepper motors. The driving circuit for this require an H-Bridge as it allows the polarity of the power applied to be controlled independently. This can be done as shown in the figure below:
Now we have seen the methods for connecting stepper motors with your microcontroller. So keeping these circuits in mind,we will now look at the programming of microcontroller to control stepper motors. This is discussed in the next section of the tutorial.
Full step Sequence
Connect the motor from Port 1.0 to Port 1.3. Adjusting the delay will increase/decrease the speed.
Code: Select all
#include <REG2051.H>
#define stepper P1
void delay();
void main(){
while(1){
stepper = 0x0C;
delay();
stepper = 0x06;
delay();
stepper = 0x03;
delay();
stepper = 0x09;
delay();
}
}
void delay(){
unsigned char i,j,k;
for(i=0;i<6;i++)
for(j=0;j<255;j++)
for(k=0;k<255;k++);
}
Code: Select all
org 0H
stepper equ P1
main:
mov stepper, #0CH
acall delay
mov stepper, #06H
acall delay
mov stepper, #03H
acall delay
mov stepper, #09H
acall delay
sjmp main
delay:
mov r7,#4
wait2:
mov r6,#0FFH
wait1:
mov r5,#0FFH
wait:
djnz r5,wait
djnz r6,wait1
djnz r7,wait2
ret
end
Code: Select all
void main(){
while(1){
stepper = 0x08;
delay();
stepper = 0x0C;
delay();
stepper = 0x04;
delay();
stepper = 0x06;
delay();
stepper = 0x02;
delay();
stepper = 0x03;
delay();
stepper = 0x01;
delay();
stepper = 0x09;
delay();
}
}
Code: Select all
main:
mov stepper, #08H
acall delay
mov stepper, #0CH
acall delay
mov stepper, #04H
acall delay
mov stepper, #06H
acall delay
mov stepper, #02H
acall delay
mov stepper, #03H
acall delay
mov stepper, #01H
acall delay
mov stepper, #09H
acall delay
sjmp main
Code: Select all
void main(){
while(1){
stepper = 0x03;
delay();
stepper = 0x01;
delay();
stepper = 0x00;
delay();
stepper = 0x02;
delay();
}
}
Code: Select all
main:
mov stepper, #03H
acall delay
mov stepper, #01H
acall delay
mov stepper, #00H
acall delay
mov stepper, #02H
acall delay
sjmp main
Code: Select all
void main(){
while(1){
stepper = 0x08;
delay();
stepper = 0x02;
delay();
stepper = 0x04;
delay();
stepper = 0x01;
delay();
}
}
Code: Select all
main:
mov stepper, #08H
acall delay
mov stepper, #02H
acall delay
mov stepper, #04H
acall delay
mov stepper, #01H
acall delay
sjmp main