Specifications
CIRCUIT IDEAS
The functions of the various pins are
given in Table I. Pins 2 through 9 are
data pins. Here, we will use data pins 2
to 5, corresponding to data bits D0
through D3 of port 378(hex) for LPT1
or 278(hex) for LPT2. Also, pin 25 is
used as the ground pin.
The PC’s parallel port cannot sink
much current. At the most, it can
handle a few milliamperes. So, if the
parallel port is connected directly to an
electrical device, it will damage the par-
allel port. Thus, we need a current am-
plifier in between the parallel port and
the electrical device. The ULN2003,
used precisely for this purpose, has an
array of Darlington transistor pairs. A
Darlington configuration is a way of
connecting two transistors in order to
amplify current to many times the in-
put current value.
The stepper motor has various ad-
vantages over other motors, as far as
controlling by a computer is concerned.
It includes high precision of angular
movement, speed of rotation, and high
moving and holding torque. It comes in
various flavours. We are dealing with
unipolar permanent magnet stepper
motor that has four coils arranged as
follows:
Terminals 1 and 2 are common ter-
minals (connected to ground or the posi-
tive supply) and the other four termi-
nals are fed to the appropriate signals.
When a proper signal is applied, the
shaft turns by a specific angle, called
the step resolution of the
motor. On continuous appli-
cation of the same signal,
the shaft stays in the same
position. Rotation occurs
only when the signal is
changed in a proper se-
quence. There are three
modes of operation of a step-
per motor, namely, single-
coil excitation mode, dual-
coil excitation mode, and
half-step modes.
•
Single-coil excita-
tion. Each coil is energised
successively in a rotary
fashion. If the four coils are
assumed to be in a horizon-
tal plane, the bit pattern will be 0001,
0010, 0100, 1000, and 0001.
•
Dual-coil excitation. Here, two
adjacent coils are energised successively
in a rotary fashion. The bit pattern will
be 0011, 0110, 1100, 1001, and 0011.
•
Half-step mode. Here, the step-
per motor operates at half the given
step resolution. The bit pattern is 0001,
0011, 0010, 0110, 0100, 1100, 1000, 1001,
and 0001.
Two software control programs, one
for DOS and another for Linux, are in-
cluded here. The program for DOS can
be used to run the motor in full- or
half-step mode, or in single-coil or
double-coil excitation mode.
(EFY Lab note. The method used
at EFY for correct identification of the
stepper motor coils involved measuring
the windings’ resistance as well as their
continuity in ohmsx1 scale, using any
good multimeter. The resistance of in-
dividual coils with respect to the middle
points will roughly be half the resistance
of the combined coil pairs (L1 and L2
or L3 and L4 in the figure). After hav-
ing identified the coils in this fashion,
connect them to the circuit as shown in
the figure. Now, if the sequence of input
to the coils happens to be wrong, the
shaft, instead of moving (clockwise or
anti-clockwise), will only vibrate. This
can be corrected by trial and error, by
interchanging connection to the coils.
The output waveforms for full-step
single-coil mode, as seen on the oscillo-
scope, are shown in the figure.)
TABLE I
Pin No Signal Direction Register Hardware
(D-type 25) In/Out Inverted
1 Strobe In/Out Control Yes
2D0
thru thru Out Data —
9D7
10 Ack In Status
11 Busy In Status Yes
12 PE In Status —
13 Select In Status —
14 AFeed Out Control Yes
15 Error In Status —
16 Initialise Out Control —
17 SLCT Out Control Yes
(Printer)
18 thru 25 Ground —— —
#include <conio.h>
#include <dos.h>
#define FULLSTEP_SINGLECOIL
//#define FULLSTEP_DOUBLECOIL
//#define HALFSTEP
unsigned char fullstep_singlecoil_val[]={1,2,4,8};
unsigned char fullstep_doublecoil_val[]={3,6,12,
9};
unsigned char halfstep_val[]={8,12,4,6,2,3,9};
void main()
{
unsigned int i=0;
while(!kbhit())
{
#ifdef FULLSTEP_SINGLECOIL
outportb(0x378,fullstep_singlecoil_val[i%sizeof
(fullstep_singlecoil_val)]);
#elif defined(FULLSTEP_DOUBLECOIL)
outportb(0x378,fullstep_doublecoil_val[i%sizeof
(fullstep_doublecoil_val)]);
#elif defined(HALFSTEP)
DOS PROGRAM
outportb(0x378,halfstep_val[i%sizeof(halfstep_val)]);
#endif
delay(10);
i++;
if(i==65535u) i=0;
}
outportb(0x378,0);
}
Compile and run the program under any com-
piler like turboc for dos or Borland C++.
LINUX PROGRAM
#endif
usleep(5000);
i++;
if(i==65535u) i=0;
}
outb(0,0x378);
}
Compile and run the program as follows:
#gcc – O6 – o motor motor.c
#./motor
The – O6 flag is necessary for using the ‘outb’
function.
#include <sys/io.h>
#include <unistd.h>
#include <stdlib.h>
//#define FULLSTEP_SINGLECOIL
//#define FULLSTEP_DOUBLECOIL
#define HALFSTEP
unsigned char fullstep_singlecoil_val[]={1,2,4,8};
unsigned char fullstep_doublecoil_val[]={3,6,12,
9};
unsigned char halfstep_val[]={8,12,4,6,2,3,9};
void main()
{
unsigned int i=0;
if(ioperm(0x378,1,1)==-1) exit(1);
while(1)
{
#ifdef FULLSTEP_SINGLECOIL
outb(fullstep_singlecoil_val[i%sizeof(fullstep_
singlecoil_val)],0x378);
#elif defined(FULLSTEP_DOUBLECOIL)
outb(fullstep_doublecoil_val[i%sizeof(fullstep_
doublecoil_val)],0x378);
#elif defined(HALFSTEP)
outb(halfstep_val[i%sizeof(halfstep_val)],0x378);
204