You are on page 1of 18

STEPPER MOTOR - PARALLEL PORT INTERFACE

By

Jose Rene Flores

and

Jaime Zavala

ECE 345

TA: Lee Rumsey

Project #49

04 May 1999
ABSTRACT

This paper reports on the design of a device to rotate a mirror assembly through various angles.

A small stepper motor rotates the mirror. The objective of this project was to design the

necessary circuitry and software to drive the small stepper motor via a laptop computer's parallel

port interface.

There are three key components to the project design: (1) mechanical drive, (2) hardware to

software interface, (3) computer software to drive the stepper motor via a laptop computer. The

three components were successfully integrated to rotate of the stepper motor through forty-five

degree increments.

II
TABLE OF CONTENTS

PAGE

1. INTRODUCTION………………………………………………………………………1

2. DESIGN PROCEDURE /DETAILS………………………..…………………….….…2

2.1. Stepper Motor ……………………………………………………………....2


2.2. Drive Circuitry……………………………………………………………....3
2.3. Computer Software……………………………………………………….....5

3. DESIGN VERIFICATION ……….…..................................................... ………...……7

4. COSTS……………………………………………………………………….……….…9

5. CONCLUSIONS……………………………………………………………………......10

6. APPENDIX 1………………………………………………………………………….11

7. REFERENCES……………………………………………….………………………..12

(JZ)

III
IV
1. INTRODUCTION

This project’s overall goal was to rotate a mirror located inside of a spacecraft. The mirror is

used as a focusing device for a set of sensors taking atmospheric measurements. The project is

not concerned with the design of the sensors, but with the design and implementation of the

mechanical device to turn the mirror, the needed drive circuitry and the controlling software.

The resulting project design goals are:

• Speed – The stepper motor must turn at a reasonably fast rate. Due to the speed

of the spacecraft, the mirror has to quickly focus the sensors in different directions.

• Torque – The stepper motor’s holding torque must be enough to sustain the

weight of the motor assembly.

• Direction – The user must be able to rotate the mirror in two directions (mirror

rotation occurs in one dimension).

The only mechanical component used was a small stepper motor. The shaft of the stepper motor

will be connected to the mount of the mirror for rotation. Using a computer interface,

positioning commands were fed to the stepper motor via a printer cable to the driver hardware.

The hardware amplified the signals and relayed them to the stepper motor. Figure 1below

clearly shows the design flow.

Mirro
Computer Drive circuits Stepper Motor r

Fig. 1 Block diagram of Stepper motor-parallel port interface.


(JRF)

V
2. DESIGN PROCEDURE

2.1 Stepper Motor

The first step in the design process was to understand how the stepper motor works. Stepper

motors behave differently than standard dc motors. Instead of rotating continuously when power

is applied, stepper motors move in small increments or steps. Additionally, a stepper motor is

constructed with several coil windings that must be energized in the proper sequence to achieve

shaft rotation. For this reason, a simple clock signal will not work. Reversal of the energizing

sequence will rotate the shaft in the opposite direction. The stepper motor used in this design is a

unipolar type motor. Two center taps characterize unipolar motors. Since each coil is divided in

two, one center tap represents two phases [2]. In this case, the motor used is a four-phase motor

and thus has two center taps. Figure 2 below shows a simplified diagram of a unipolar motor

and the energizing sequence.

Index 1a 1b 2a 2b
1 1 0 0 0
2 0 0 1 0
3 0 1 0 0
4 0 0 0 1
5 1 0 0 0
6 0 0 1 0
7 0 1 0 0
8 0 0 0 1

Fig. 2 Four-phase unipolar stepper motor energizing sequence coil configuration.

If the control signals are not sent in the correct order, the motor will not turn properly. It may

simply buzz and not move, or it may actually turn, but in a rough or jerky manner [2]. Figure 2

shows the cross section of a motor with an angle resolution of 30 degrees. A permanent magnet

VI
with six poles serves as the rotor, three are north polarized and three are south polarized. The

specific motor used for this project has an angle resolution of 1.8 degrees per step. Higher

resolutions require more poles, 1.8 degrees require 100 poles. Current flows from the center tap

of winding 1 to terminal (a) causes the top stator pole to be a north pole and the bottom stator

pole to be a south pole. Power is then alternated to winding 2 and causes the rotor to turn. Only

one half of each winding is energized at a time.

Stepper motors also have the advantage of producing high torque at low speeds. Direct current

motors do not produce high torque at low speeds, without the aid of gearing mechanisms.

Stepper motors also have holding torque which allows a stepper motor to hold its position firmly

when not turning. This is useful for the intended application where the motor will be starting and

stopping, while the force of the mirror’s momentum acting against the motor remains present.

This eliminates the need for a mechanical brake mechanism. These same principals drive the

specific motor used for this project, the Astrosyn mini-angle stepper. The Astrosyn is a 5V, 1A

per phase, 1.8 degree per step motor.

2.2 Driver circuit

The motor used for this project requires at least 1 ampere per phase, but the computer’s parallel

port can only deliver a few milliamperes of current. Since the computer delivers the motor’s

required 5 volts per phase ,a simple application of Ohm’s law says that a 5Ω resistor will pull

the necessary current. However, most resistors are not capable of pulling current past a few

milliamperes. In addition, resistors cannot handle the fast current switching required by the

stepping sequence. The inductive loads of the coils tend to make the current reverse direction

because of the rapid on and off switching.

VII
Using a Darlington transistor array such as the ULN2003 chip can easily solve these problems.

These arrays are composed of cascaded NPN transistors with suppression diodes attached to

prevent current reversal. Another advantage of the Darlington transistor is its ability to amplify

the computer’s output current from a few milliamperes into a 500mA input to the stepper motor.

Two transistor elements of each pin are needed in parallel to supply the necessary 1A to the

stepper motor. Figure 3 below shows the arrangement of NPN transistors and the pin

assignments on the chip.

Fig. 3 ULN2003 Darlington transistor array representative schematic and pin connections

Figure 4 on the next page shows the parallel connection of the chips’ internal transistors. Pins

1-3 and 4-6 were used as inputs from the computer’s parallel port. These pins received the on

and off sequence discussed in section 2.1. Pins 14 -16 and 11-13serve as the output of the

chips. Current leaving each of the pins was measured to be 344 milliamperes. Only two pins are

needed to supply the necessary500mA, but 3 pins were utilized as a backup feature. As can be

seen from the schematic, each set of outputs is used to feed into one of the stepper motor’ coils,

1a, 1b, 2a, and 2b. (JZ)

VIII
2.3 Computer Interface

The computer’s parallel port was used as the means of communication between the software and

the transistor arrays. A 25-pin male, 36-pin female printer cable was used as the bus for

information transfer. Figure 3 [2] below shows the pinout arrangement of the parallel port.

Fig. 3 Parallel port pinout

The parallel port has three types of output ports[1]; DATA, STATUS, and CONTROL. Figure 3

[2] shows the arrangement of the eight Data pins, D0-D7. Only the DATA pins D0-D3 were

used for this application. The port is equipped with all the necessary hardware and is easy to

control using a C program in a Windows environment. No initialization of the port was required.

Writing to port 0x378 outputs the necessary data. Two motor control functions were written.

All utilized Data pins D0-D3. One function steps the motor clockwise and the other

counterclockwise. The C program can be found at the end of this report in Appendix 1.

The C program allows the user to select the angle and direction of the motor’s motion. The

motor turns in 1.8-degree steps until it reaches 45, 90, 135, or 180 degrees. The program also

tells the user the new position of the motor each time a motion is completed. This feedback is

important in case anything goes wrong with the motor’s operation.

IX
3.0 DESIGN VERIFICATION

We took some data to verify that the output from the Darlington chips was consistent. Table 1 in

the following page shows the results. The input to the Darlington chips had a current values of

approximately 0.0015mA. The current values coming out of each of the output pins were

approximately 0.67A! This is a pretty impressive amplification. When you add up these current

values the result is 2.01A, more than necessary to run the motor. However, the actual current

measured from the parallel arrangement was approximately 1.16A. This makes sense because

the motor only pulls the current it needs from the parallel arrangement.

To show that the data sequence was actually being sent correctly, we generated a plot of Table 1.

This plot can be found in appendix 1.

(JRF)
TABLE 1. DARLINGTON INPUTS TO STEPPER MOTOR

1a 2a 1b 2b
0.0003 0.6804 0.0004 0.0001
0.0003 0.0003 0.6253 0.0002
0.0003 0.0001 0.0003 0.6542
0.6185 0.0001 0.0002 0.0003
0.0001 0.6801 0.0001 0.0003
0.0002 0.0001 0.623 0.0003
0.0003 0.0002 0.0001 0.6354
0.6167 0.0002 0.0002 0.0001
0.0001 0.6811 0.0002 0.0002
0.0002 0.0001 0.6719 0.0002
0.0002 0.0002 0.0001 0.6674
0.6158 0.0002 0.0002 0.0001
0.0002 0.6807 0.0002 0.0002
0.002 0.0003 0.6712 0.0002
0.0003 0.0003 0.0001 0.6565
0.6407 0.0003 0.0002 0.0001
0.0002 0.6805 0.0002 0.0002
0.0002 0.0001 0.6702 0.0002
0.0002 0.0002 0.0003 0.6654
0.6513 0.0002 0.0003 0.0001
0.0001 0.6802 0.0003 0.0002
0.0002 0.0001 0.6606 0.0002
0.0002 0.0002 0.0001 0.6871
0.6514 0.0002 0.0002 0.0001
0.0001 0.6802 0.0002 0.0001

XI
3. COSTS

Table 1 below shows the breakdown of the total parts cost for this project. It was not as
expensive as expected.

TABLE 1 PARTS LIST AND LABOR COSTS

Item Quantity Cost Total Engineer Salary hrs/week


ULN 2003 driver 11 $0.76 $8.36 Jose $27/hr 18
chips

Shipping of chips 2 $5.37 $10.74 Jaime $27/hr 18


TOTAL $34,020
Book - 1 $47.67 $47.67
Programming
the Parallel Port

5.25" Disk drive 1 $16.50 $16.50

25 male, 36 female 1 4.98 4.98


printer cable

TOTAL PARTS COST $88.25 PARTS + LABOR= 34,108.25

XII
CONCLUSIONS

The project worked as expected and most of the design goals were achieved except for the

frequency of rotation. The stepping frequency was 1 step per second. This is unacceptable for

the intended design purpose. The stepping frequency is controlled by the computer software.

Originally, the software did not include any provisions for frequency control. The computer’s

pulse frequency was too fast for the stepper motor coils to energize and react. The result was no

movement of the motor. The solution used was the utilization of the ‘sleep’ command within

the C coding. The sleep command specifies the time delay to execute certain functions. The

fastest frequency attained via the sleep command was one step per second. A faster rate of turn

could have been achieved had there been more time. There were other programming solutions

that could have been pursued, but abandoned because of time constraints.

Another design goal not met was the construction of the mirror itself. Again, time did not permit

the design of a mirror assembly.

The project reached a good degree of functionality. The main design goal, that of getting the

motor to turn via a computer program, was successfully achieved. The main area for

improvement is the frequency of rotation.

This team has gained a tremendous amount of knowledge through the researching and designing

of the stepper motor-parallel port interface. The project was very interesting because of the

opportunity to learn about areas unfamiliar to both project members.

XIII
APPENDIX 2. REFERENCES

[1] Gadre, Dhananjay V.,”Programming the Parallel Port. Interfacing the PC for Data

Acquisition and Control” Lawrence, KS: Miller Freeman Inc.

[2] D. Jones, “Control of Stepping Motors, a tutorial,” October 1998,


http://www.cs.uiowa.edu/~jones/step

XIV
/*STEPPER.c*/
/*This piece of code drives the stepper motor*/

#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include <process.h>
/*#include <stdlib.h>*/

main()
{

int i, direc;
char angle;
int degrees = 0;

void clockwise(int);
void counterclockwise(int);
void ask(int *);

do{
printf("Choose an option from the menu\n\n");
printf("\t A) rotate 45 deg\n");
printf("\t B) rotate 90 deg\n");
printf("\t C) rotate 135 deg\n");
printf("\t D) rotate 180 deg\n");
printf("\t U) unlock motor\n");
printf("\t Q) QUIT \n");
scanf(" %c",&angle);

switch (angle)
{
case 'A':
case 'a':
ask(&direc);
if (direc == 1)
{
degrees += 45;
clockwise(6);
outportb(0x378,0x8);
printf("It's at %d degrees.\n", degrees);
}
else
{
degrees -= 45;
counterclockwise(6);
outportb(0x378,0x1);
printf("It's at %d degrees.\n", degrees);
}
break;

case 'B':

XV
case 'b':
ask(&direc);
if (direc == 1)
{
degrees += 90;
clockwise(12);
outportb(0x378, 0x8);
outportb(0x378, 0x2);
printf("It's at %d degrees.\n", degrees);
}
else
{
degrees -= 90;
counterclockwise(12);
outportb(0x378,0x1);
sleep(1);
outportb(0x378,0x4);
printf("It's at %d degrees.\n", degrees);
}
break;

case 'C':
case 'c':
ask(&direc);
if (direc == 1)
{
degrees += 135;
clockwise(18);
outportb(0x378,0x8);
sleep(1);
outportb(0x378,0x2);
sleep(1);
outportb(0x378,0x4);
printf("It's at %d degrees.\n", degrees);
}
else
{
degrees -= 135;
counterclockwise(18);
outportb(0x378,0x1);
sleep(1);
outportb(0x378,0x4);
sleep(1);
outportb(0x378,0x2);
sleep(1);
printf("It's at %d degrees.\n", degrees);
}
break;

case 'D':
case 'd':
ask(&direc);
if (direc == 1)
{degrees += 180;
clockwise(25);

XVI
printf("It's at %d degrees.\n", degrees);
}
else
{ degrees -= 180;
counterclockwise(25);
printf("It's at %d degrees.\n", degrees);
}
break;

case 'u':
case 'U':
outportb(0x378,0x0);
printf("\nThe motor is unlocked\n");
break;

case 'q':
case 'Q':
printf("\nAdios Shania!");
break;

default:
printf("Invalid angle, enter another\n");
break;
}

} while (angle !='Q' && angle !='q');

return 0;
}
/*------------------------------------------------------------*/
/*this function rotates the motor clockwise. */
void clockwise(int times)
{
int i;

for(i=1; i<=times; i++)


{
outportb(0x378,0x8);
sleep(1);
outportb(0x378,0x2);
sleep(1);
outportb(0x378,0x4);
sleep(1);
outportb(0x378,0x1);
sleep(1);
}
}
/*-----------------------------------------------------*/
/* This function rotates the motor counterclockwise. */
void counterclockwise(int times)
{
int i;

for(i=1; i<=times; i++)


{

XVII
outportb(0x378,0x1);
sleep(1);
outportb(0x378,0x4);
sleep(1);
outportb(0x378,0x2);
sleep(1);
outportb(0x378,0x8);
sleep(1);
}
}
/*-------------------------------------------------------*/
/*This function asks the user for a selection of directions. */
void ask(int *direc)
{
do {
printf("\nIn which direction:\n");
printf("\t1) Clockwise");
printf("\t2) Counterclockwise\n");
scanf("%d", direc);
if (*direc !=1 && *direc != 2)
{
printf("\nNot a valid choice");
}
else
break;
} while (1);
}

XVIII

You might also like