Sie sind auf Seite 1von 15

Stepper Motor Tutorial

Home (/) / Rikipedia (/wiki/) / Stepper Motor Tutorial

From Rikipedia Embedded Wiki

Page (/wiki/Stepper_Motor_Tutorial)
Discussion (/mediawiki/index.php?title=Talk:Stepper_Motor_Tutorial&action=edit&redlink=1)

Edit
Nav

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 pricipal, di erent 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.

Table of Content

Types of Stepper Motors


Unipolar stepper motor
Bipolar stepper motor
Working of Stepper Motor
Step Sequence
Full Step Sequence
Half Step Sequence
Step Angle
Step Sequence for 2-wire control of
Unipolar stepper motor
Step Sequence for Bipolar stepper motor
Stepper Motor Connections
Connecting Unipolar Stepper Motor
2-wire connection for Unipolar Stepper
Motor
Connecting Bipolar Stepper Motor
Stepper Motor Programming
Programming Full step Sequence
Programming Half step Sequence
Programming for 2-wire connection of
Unipolar Stepper Motor
Programming for Bipolar Stepper Motor

Types of Stepper Motors

Types of Stepper Motors


There are basic two types of stepper motors available in market.

Unipolar stepper motor


The unipolar stepper motor has ve 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.

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 nd
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 in nite 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.

Stepper Motor Coils

Working of Stepper Motor


Now lets discuss the operation pricipal 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.

Stepper Motor Coils


You can see in the example, when coil "A" is energized, A north-south polarity is generated at "A+A\" as
shown in the gure 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 principal.

Stepper Motor Coils When energized


We have seen that to make the stepper motor work, we need to energize coil in a sequence.

Step Sequence
Stepper motors can be driven in two di erent patterns or sequences. namely, Full Step Sequence
Bulleted list item
Half Step Sequence

Half Step Sequence


we will go through these sequences one by one.

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.
Full Mode Sequence
Step

A\

B\

The working of the full mode sequence is given in the animated gure below.

Full mode Sequence Animation

Half Step Sequence


In Half mode step sequence, motor step angle reduces to half the angle in full mode. So the angualar
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 pre ered over full
mode. Table below shows the pattern of energizing the coils.
Half Mode Sequence
Step

A\

B\

The working of the half mode sequence is given in the animated gure below.

Half mode Sequence Animation

Step Angle
Step angle of the stepper motor is de ned 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

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:
2-wire Mode Sequence
Step

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 stepepr motors. Being simpler in contruction, 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.
Polarity Sequence
Step

A\

B\

+ve

-ve

-ve

-ve

-ve

-ve

+ve

-ve

-ve

+ve

-ve

-ve

-ve

-ve

-ve

+ve

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.
Step Sequence
Step

A\

B\

Stepper Motor Connections

Stepper Motor Connections


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:
1. Interface using L293D - H-Bridge Motor Driver
2. Interface using ULN2003/2004 - Darlington Arrays
We will discuss both connection techniques one by one. The above mentioned methods need 4 controller
pins for interface.

Connecting Unipolar stepper using L293D

Unipolar Stepper with 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 sequence programmed in the controller.

Connecting Unipolar stepper using ULN2003/2004

Unipolar Stepper with ULN2003/ULN2004


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.

Unipolar Stepper Motor connection

Connecting Bipolar Stepper Motor


As we have studied that, Bi-polar stepper motors has 2 di erent 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 gure below:

Bipolar Stepper Motor connection


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.

Stepper Motor Programming


Programming Full step Sequence
C Programming
I am assuming that stepper motor is connected at Port 1.0 to Port 1.3. Adjusting the delay will increase or
decrease the speed of the motor. Here just for demonstration i have taken some delay, you can change it
as you want.
[Tip: Do testing... ]

1. #include<REG2051.H>
2. #definestepperP1
3.
4. voiddelay()
5. {
6.

unsignedchari,j,k;

7.

for(i=0;i<6;i++){

8.

for(j=0;j<255;j++)

8.

for(j=0;j<255;j++)

9.

10.

for(k=0;k<255;k++);

11. }
12.
13. voidmain()
14. {
15.

while(1){

16.

stepper=0x0C;

17.

delay();

18.

stepper=0x06;

19.

delay();

20.

stepper=0x03;

21.

delay();

22.

stepper=0x09;

23.

delay();

24.

25. }

Assembly Programming

1.

org0H

2.
3.

stepperequP1

4.
5. main:
6.

movstepper,#0CH

7.

acalldelay

8.

movstepper,#06H

9.

acalldelay

9.

acalldelay

10.

movstepper,#03H

11.

acalldelay

12.

movstepper,#09H

13.

acalldelay

14.

sjmpmain

15.
16. delay:
17.

movr7,#4

18. wait2:
19.

movr6,#0FFH

20. wait1:
21.

movr5,#0FFH

22. wait:
23.

djnzr5,wait

24.

djnzr6,wait1

25.

djnzr7,wait2

26.

ret

27.

end

The working of the above code can be seen in the demo animation below.

Full Step Sequence Simulation

Programming Half step Sequence


C Programming
Just the main routine changes rest everything remains same, i mean same delay routine.
1. voidmain()
2. {
3.

while(1){

4.

stepper=0x08;

5.

delay();

5.

delay();

6.

stepper=0x0C;

7.

delay();

8.

stepper=0x04;

9.

delay();

10.

stepper=0x06;

11.

delay();

12.

stepper=0x02;

13.

delay();

14.

stepper=0x03;

15.

delay();

16.

stepper=0x01;

17.

delay();

18.

stepper=0x09;

19.

delay();

20.

21. }

Assembly Programming
Here also the main routine changes rest everything remains same.

1. main:
2.

movstepper,#08H

3.

acalldelay

4.

movstepper,#0CH

5.

acalldelay

6.

movstepper,#04H

7.

acalldelay

8.

movstepper,#06H

9.

acalldelay

10.

movstepper,#02H

11.

acalldelay

11.

acalldelay

12.

movstepper,#03H

13.

acalldelay

14.

movstepper,#01H

15.

acalldelay

16.

movstepper,#09H

17.

acalldelay

18.

sjmpmain

The working of the above code can be seen in the demo animation below.

Half Step Sequence Simulation

Programming for 2-wire connection of Unipolar Stepper Motor


C Programming

1. voidmain()
2. {
3.

while(1){

4.

stepper=0x03;

5.

delay();

6.

stepper=0x01;

7.

delay();

8.

stepper=0x00;

9.

delay();

10.

stepper=0x02;

11.

delay();

12.

12.

13. }

Assembly Programming
1. main:
2.

movstepper,#03H

3.

acalldelay

4.

movstepper,#01H

5.

acalldelay

6.

movstepper,#00H

7.

acalldelay

8.

movstepper,#02H

9.

acalldelay

10.

sjmpmain

The working of the above code can be seen in the demo animation below.

2-wire connection of Unipolar Stepper Motor simulation

Programming for Bipolar Stepper Motor


C Programming
1. voidmain()
2. {
3.

while(1){

4.

stepper=0x08;

5.

delay();

6.

stepper=0x02;

7.

delay();

8.

stepper=0x04;

9.

delay();

10.

stepper=0x01;

11.

delay();

12.

13. }

Assembly Programming
1. main:
2.

movstepper,#08H

3.

acalldelay

4.

movstepper,#02H

5.

acalldelay

6.

movstepper,#04H

7.

acalldelay

8.

movstepper,#01H

9.

acalldelay

10.

sjmpmain

Das könnte Ihnen auch gefallen