You are on page 1of 41

Stepper Motors

Widely use in Robotics ---why??

Because More precise than DC motor

Measured rotation and can be held at


a particular position- U can rotate the
stepper motor with an accuracy of 0.9
degree!!!!!!

Alignment is much better...

Stepper Motors contd..

Types of Stepper Motors


Mainly 2 types:
Unipolar- Current can flow only in one
direction in the coils
Bipolar- Current can flow in both the
directions

Comparison
Unipolar

Bipolar

Current flow in one


direction

Current flow in both


direction

Simple drive circuit

Complicated drive Circuit

Less torque

High Torque

Modes of Operation
Single Coil Excitation: Only one out of the
4 coils is excited at a given time
Double Coil: Two adjacent coils are
excited at a given time
Single and Double: Its a hybrid of
both..(refer diagram for details)

Stepper Motor basics


The stepper motor contains a permanent

magnet which is attached to the shaft at centre


and there are 4 coils on the 4 sides
Actually the stator contains 100 teeth to get a
step angle of 360/(2*100)=1.8degrees. But here
for the sake of simplicity, we are showing only
one tooth of stator. So dont get misled into
believing that its atep angle is 90 degrees

Single Coil Mode

Single coil Excitation

Note that until the next coil is switched on, the stator remains in its position only
And as we can control when to switch on a particular coil thru software, we can
rotate it by exactly the angle we wish.. Compare this with DC motor where the
shaft keeps on rotating as soon as the current is switched on

a. Single-Coil Excitation - Each


successive coil is energized in turn.

Double coil Excitation

b. Two-Coil Excitation - Each successive pair


of adjacent coils is energized in turn.

Single and Double coil Excitation

Interleaving the two sequences will


cause the motor to half-step

Comparison
Single coil

Double coil

Low torque

High torque

Consume less energy Consume double


Settling time is more

energy
Settling time is less

Note: The advantage of hybrid mode is that the step angle gets
halved.. So we can control the rotation with double precision

Circuit Diagram

Controlling motors thru Computer


Parallel Ports: Its the easiest way to

control the motors from computer. No


complicated intermediate circuits are
required
Serial/USB ports
Bluetooth
* The last 2 modes are beyond the scope of this workshop

25-way Female D-Type


Connector

The pin configuration of the other


end of parallel port connector

Pin details

Pin details contd.....

Pin Details
D0-D7 are the data pins(used for output)
C0-C3 are control pins. Note that C1 and
C3 are hardware inverted. They can be
used for both input and output
S3-S7 are status pins. They are used for
taking input from external ckt

PC parallel Port
The PC's Parallel Printer Port had a total of

12 digital outputs and 5 digital inputs accessed


via 3 consecutive 8-bit ports in the processor's
I/O space.
8 output pins accessed via the DATA Port
5 input pins (one inverted) accessed via the
STATUS Port
4 output pins (three inverted) accessed via the
CONTROL Port
The remaining 8 pins are grounded

Controlling pins thru program

Almost every programming language has


commands to control the ports. For
example in Turbo C, we can use the
outportb function defined in dos.h

outportb(0x378,5)
0x378 is the address of the data pins of the parallel port.
The binary form of 5 will appear as an output in the data
pins
i.e the binary of 5 is 00000101. Therefore D0 and D2 are on
and rest pins are off. The ouput can be upto 2^8-1=255

Control pins
The address for control pins can be

obtained by adding 2 to the address of


data pins. For eg, here the address of
control pins will be 0x378+0x2=0x37a
Therefore the command
outportb(0x37a,3) will make both the 1st 2
control pins(C0,C1) low! Because 3=0011
and C0 and C1 are hardware inverted

Controlling DC motors by H-Bridge

Implementation of H bridge

Driving the DC motor

Connections for a stepper motor

Data
Port1

Data
Port2

Note connect a 15v zener diode to pin 10 of IC as shown to prevent damage


to the IC due to "back emf" when loads such as motors switch on and off

Motor 1

Motor 2

Driving the Stepper Motor


In the following slides, we discuss the
code for driving the stepper motor in
various modes
Single coil mode
Double coil mode
Hybrid mode

Single Coil Mode


The order of the values to be written to
parallel port(data pins)
00000001 (1st coil is on) = 1
00000010 (2nd coil is on) = 2
00000100 (3rd coil is on) = 4
00001000 (4th coil is on) = 8
For 2nd motor
00010000 (1st coil is on) = 16
0010000 (2nd coil is on) = 32
0100000 (3rd coil is on) = 64
1000000 (4th coil is on) = 128

Double Coil Mode


The order of the values to be written to
parallel port(data pins)
00000011 (1st & 2nd coils are on) = 3
00000110 (2nd & 3rd coils are on) = 6
00001100 (3rd & 4th coils are on) = 12
00001001 (4th & 1st coils are on) = 9
For 2nd motor
00110000 (1st & 2nd coils are on) = 48
01100000 (2nd & 3rd coils are on) = 96
11000000 (3rd & 4th coils are on) = 192
10010000 (4th & 1st coils are on) = 144

Hybrid mode
The order of the values to be written to parallel
port(data pins)
00000001
00000011
00000010
00000110
00000100
00001100
00001000
00001001

(1st coil is on) = 1


(1st & 2nd coil is on) = 3
(2rd coil is on) = 2
(2nd & 3rd coil is on) = 6
(3st coil is on) = 4
(4th & 3nd coil is on) = 12
(4rd coil is on) = 8
(1st & 4th coil is on) = 9

The values for the other coil can be determined by shifting the binary representation by 4
places left or multiply the decimal values by 2^4=16

Sample codes to rotate in ccw drn


//single coil mode
#include <stdio.h>
#include <dos.h>

//double coil
#include <stdio.h>
#include <dos.h>

main()
main()
{ char a[]={3,6,12,9};
{ char a[]={1,2,4,8};
for (int
for (int i=0;i<=100;i++)
i=0;i<=100;i++)

{ outportb(888,a[i%4]);
delay(10);
}
outportb(888,0);

{outportb(888,a[i%
4]);
delay(10);
}
outportb(888,0);

//hybrid mode
#include <stdio.h>
#include <dos.h>
main()
{ char
a[]={1,3,2,6,4,12,8,9
};
for (int
i=0;i<=100;i++)
{
outportb(888,a[i%8]);
delay(10);
}
outportb(888,0);
}

Sample codes to rotate in cw drn


//single coil mode
#include <stdio.h>
#include <dos.h>
main()
{ char a[]={1,2,4,8};
for (int i=100;i<=0;i--)
{ outportb(888,a[i%4]);
delay(10);
}
outportb(888,0);
}

//double coil
#include <stdio.h>
#include <dos.h>

//hybrid mode
#include <stdio.h>
#include <dos.h>

main()
{ char a[]={3,6,12,9};
for (int i=100;i<=0;i-)

main()
{ char
a[]={1,3,2,6,4,12,8,9
};
for (int i=100;i<=0;i--)
{
outportb(888,a[i%8]);
delay(10);
}
outportb(888,0);
}

{outportb(888,a[i%
4]);
delay(10);
}
outportb(888,0);

Sample codes to move the robot


backward
//single coil mode
#include <stdio.h>
#include <dos.h>
main()
{ char a[]={1,2,4,8};
char
b[]={16,32,64,128};
for (int i=100;i<=0;i--)
{
outportb(888,a[i%4]|b
[i%4]);
delay(10);
}
outportb(888,0);
}

//double coil
#include <stdio.h>
#include <dos.h>
main()
{ char a[]={3,6,12,9};

//hybrid mode
#include <stdio.h>
#include <dos.h>
main()
{ char
a[]={1,3,2,6,4,12,8,9
char
};
b[]={48,96,192,144};
for (int i=100;i<=0;i- char
b[]={16,48,32,96,64,19
-)

2,128,144};

{outportb(888,a[i%
4]|b[i%4]);
delay(10);
}
outportb(888,0);
}

for (int i=100;i<=0;i--)


{
outportb(888,a[i%8]|
b[i%8]);
delay(10);
}
outportb(888,0);

Sample codes to move the robot


forward
//single coil mode
#include <stdio.h>
#include <dos.h>
main()
{ char a[]={1,2,4,8};
char
b[]={16,32,64,128};
for (int i=0;i<=100;i++)
{
outportb(888,a[i%4]|b
[i%4]);
delay(10);
}
outportb(888,0);
}

//double coil
#include <stdio.h>
#include <dos.h>
main()
{ char a[]={3,6,12,9};
char
b[]={48,96,192,144};

for (int
i=0;i<=100;i++)

//hybrid mode
#include <stdio.h>
#include <dos.h>
main()
{ char
a[]={1,3,2,6,4,12,8,
9};
char
b[]={16,48,32,96,64,1
92,128,144};

{outportb(888,a[i%
4]|b[i%4]);
delay(10);
}
outportb(888,0);
}

for (int
i=0;i<=100;i++)
{
outportb(888,a[i%8]
|b[i%8]);
delay(10);
}
outportb(888,0);

Sample codes to turn the bot left


//double coil
#include <stdio.h>
#include <dos.h>
main()
{ char a[]={3,6,12,9};

//hybrid mode
#include <stdio.h>
#include <stdio.h>
#include <dos.h>
#include <dos.h>
main()
main()
{ char
{ char a[]={1,2,4,8};
a[]={1,3,2,6,4,12,8,
char
char
9};
b[]={48,96,192,144};
b[]={16,32,64,128};
char
for (int
for (int i=0;i<=100;i++)
b[]={16,48,32,96,64,1
i=0;i<=100;i++)
{ outportb(888,a[(100//single coil mode

i)%4]|b[i%4]);
delay(10);

}
outportb(888,0);

{outportb(888,a[(10
0-i)%4]|b[i%4]);
delay(10);
}
outportb(888,0);

92,128,144};

for (int
i=0;i<=100;i++)
{
outportb(888,a[(100
-i)%8]|b[i%8]);
delay(10);
}
outportb(888,0);

Sample codes to turn the bot right


//double coil
#include <stdio.h>
#include <dos.h>
main()
{ char a[]={3,6,12,9};

//hybrid mode
#include <stdio.h>
#include <stdio.h>
#include <dos.h>
#include <dos.h>
main()
main()
{ char
{ char a[]={1,2,4,8};
a[]={1,3,2,6,4,12,8,
char
char
9};
b[]={48,96,192,144};
b[]={16,32,64,128};
char
for (int
for (int i=0;i<=100;i++)
b[]={16,48,32,96,64,1
i=0;i<=100;i++)
{
92,128,144};
outportb(888,a[i%4]|b {outportb(888,a[i%4]|
[(100-i)%4]);
b[(100-i)%4]);
for (int
delay(10);
i=0;i<=100;i++)
delay(10);
}
{
}
outportb(888,0);
outportb(888,a[i%8]
outportb(888,0);
|b[(100-i)%8]);
}
}
delay(10);
}
outportb(888,0);
//single coil mode

Cracking Techno Tennis....


Here we present some vague ideas for
developing your robot. Two important
considerations are:
Basic movable base which can be
accurately positioned and moved in any
direction
Hitting mechanism

If u use stepper motors


The data pins D0-D3 will be connected to the

left motor and D4-D7 to the right one (or vice


versa)
To control the hitting mechanism u can use the
4 control pins. For example u can switch on a
control pin to trigger a flap mechanism. A power
amplifier must be used in between port pins and
devices involved in hitting mechanism

MATLAB CODE
dio=digitalio('parallel','LPT1');
addline(dio,0:3,'out');

putvalue(dio,[0 1 1 0]);

You might also like