Professional Documents
Culture Documents
By
and
Jaime Zavala
ECE 345
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
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.
• 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
• Direction – The user must be able to rotate the mirror in two directions (mirror
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
Mirro
Computer Drive circuits Stepper Motor r
V
2. DESIGN PROCEDURE
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
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
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
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
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
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
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,
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.
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
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.
(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.
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 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
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
XIII
APPENDIX 2. REFERENCES
[1] Gadre, Dhananjay V.,”Programming the Parallel Port. Interfacing the PC for Data
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;
}
return 0;
}
/*------------------------------------------------------------*/
/*this function rotates the motor clockwise. */
void clockwise(int times)
{
int 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