Professional Documents
Culture Documents
INTRODUCTION
Since its introduction in the mid seventies, the microcomputer has become an important tool which has
impacted on all aspects of our society. Probably the most popular impression of this device is one that
includes wordprocessing, data manipulation, graphics processing, communications, simulation and game
playing. Just as important, but maybe not as visible to the average person, is the role of the microcomputer
and its main constituent part, the microprocessor, in external sensing and control of other devices. Examples
include space shuttles, airliners, ships, modern buildings, automobiles, medical devices, consumer electronics
and appliances, artificial limbs, smart toys and military hardware; the list is growing exponentially.
The purpose of this module is to investigate the use of the microcomputer in data acquisition and
control. This topic is divided into four logical parts which include digital input and output and
analog input and output. To facilitate; this study, the student will use hands on activities as a focus for
each of the four components. These activities will use the Quick Basic language and several dedicated
software applications to interact with the hardware. A prior knowledge of basic electronics would be an
asset but is not essential to the completion of the activities and projects.
Analog vs Digital
Before you begin an investigation of the microcomputer's potential for interfacing to the external world we
will define a few of the terms that are crucial to understanding the basics of this module.
Volt - Defined as the unit of electrical potential energy difference. The power supply of a typical
microcomputer delivers both 5 and 12 volts of direct current (DC).
Digital - Based on discrete, definite values.
Analog - Continuously and smoothly varying
The circuits used in a microcomputer consist of thousands of switches that turn on and off at very high
speeds. For the most part, the switches can only be in two states, either on or off. This corresponds to
voltage levels of +5 volts and 0 volts and of course are represented by the binary number system's digits of 1
and 0. This is the reason that such computers are called digital because their switching can only exist in
either of the two states. Analog is the opposite. It refers to electrical signals that can take any value (of
voltage), can vary continuously and can have positive or negative polarity. A modern microcomputer cannot
handle analog signals WITHOUT SPECIAL CIRCUITS that convert voltages into digital "words". One
method of illustrating this difference is to graph voltage as a function of time. The first example shows a
simple circuit consisting of a 5 volt supply, a switch and a light bulb. As the switch is turned on and off the
Page 1
INTRODUCTION
resulting graph depicts a square wave that changes between the two discrete values of 0 and +5 volts. (This
is the graph of an ideal switch, an actual switch "bounces" when closed and does not provide a clean square
wave graph. Special devices called debouncing circuits are used to clean up the signal generated by a
manual switch such as a keyboard key.)
The example used to illustrate the analog signal is an actual signal generated by a magnetic microphone.
Page 2
Note how the voltage changes in both magnitude and polarity (+ and -) with time.
INTERFACE CARDS
Most microcomputers are already configured to communicate with the outside through printer, serial
(communications) and even game ports. In your investigations of computer interfacing, you will be using
several special interface "cards" which are plugged into the expansion port of a standard PC. One such
card, called the Advanced Interface Board from Sunset Labs, can be used for all four I/O (input/output)
functions listed previously. This circuit board contains three main circuit chips. The 8255
Programmable Peripheral Interface (PPI), used for Digital I/O, an Analog to Digital
Converter (ADC) for analog input and a Digital to Analog Converter (DAC) for analog output.
This card has two output ports that connects these functions for use in external circuits. These ports, 1 and 2,
accept polarized (one way) plugs which are connected by ribbon cables to 16 pin DIP (Dual Inline Package)
connectors which can be plugged into circuit boards (bread boards). Most of the activities will be carried out
on these bread boards. The ports also provide power in the form of 5 and 12 volts DC. The functions of this
card and other interface devices will be explained in greater detail in subsequent sections.
Page 3
You
will
be
using
the
I/O
ports
A and
B to
detect
ON/O
FF
condi
tions. Port C is used for other functions and won't be accessed. The Data Direction Register is a control
register that determines whether an I/O port is to be used for input or output.
Each of the registers is assigned a unique I/O address. By using this address we can communicate directly
with the chip. Since each register has a capacity of 8 bits, the I/O ports have been designated PA0, PA1.....
PA7 (port A - line 0, port A - line 1 etc.) , PB0, PB1......PB7 and PC0, PC1....PC7. As configured, only
four lines for ports A and B are available from the ribbon cable. (A connection can be made on the card to
make all eight lines available). Port C is used for on board functions and will not be used in the activities.
Let's have a closer look at an I/O Port and how it can be used to detect the on/off states of a switch. The
following diagram is a representation of I/O Port A. Each of the 8 I/O lines are shown, with line PA0 on the
Page 4
right.
As stated previously, the I/O ports are 8 bit registers. Each bit reflects the state of the corresponding I/O line.
For example, suppose line PA0 is connected to a 5 volt source as in the next diagram.
The Port A register would contain the bit pattern 00000001. Remember, 5 volts is interpreted by the
computer as the binary digit 1. The I/O line is said to be in a high state. You might recognize the 8 bit
pattern as a
byte. Let's
stop for a
moment and
review the
binary system.
Each digit
(bit) of the
byte has a
place value.
The bit on the far right is called the least significant bit or LSB . It has a place value of 20 which is
equal to a decimal value of 1. The bit on the far left is called the most significant bit or MSB. It has a
place value of 27 or 128 decimal. Starting with the MSB the place values are
27
or
26
25
24
23
22
21
20
Page 5
128
64
32
16
contents of a particular I/O register is. That is, to be able to detect when a switch has been closed and 5 volts
applied to a particular I/O line. One procedure is to use Quick Basic, a high level language which, by now,
you probably have some familiarity with. To read the I/O ports and to set the Data Direction Register
requires that you know the I/O address of these registers. The advanced interface board has fixed
addresses for these locations which are as follows:
Data Direction Register
819
I/O Port A
816
I/O Port B
817
These are decimal numbers, although hexadecimal equivalents can also be used. You will need to do a
number of activities to place this theory into practise.
ACTIVITY 1
Materials:
Make sure the computer is turned off before you make any connections.
Connect the DIP plug to the bread board and plug into Port #1 of the AIB board. Connect the other
components according to the next illustration. A schematic diagram is also shown for your information.
When you have connected the circuit, have it checked by your teacher before you turn on the computer. The
circuit is connected to the power supply and damage could occur if it is not configured correctly.
Page 7
Page 8
PROGRAM COMMENTS
This is a fairly simple program but it contains several important concepts crucial to your understanding of
interfacing. We will look at this program in detail. In subsequent activities, comments will be made on new
concepts.
OUT 819, 154
PORT A
PORT B
154
INPUT
INPUT
152
INPUT
OUTPUT
138
OUTPUT
INPUT
136
OUTPUT
OUTPUT
DO WHILE....
Sets up a loop that will execute until the enter key is pressed. (Chr$(13) is the
character code for a carriage return, i. e. the enter key.)
N = INP(816)
The INP statement "looks at" or returns the contents of a particular address. In
this example the address 816 is I/O PORT A. When you press the switch you
are placing 5 volts on I/O line PA0 which forces the line "high". This means a
binary 1 is placed in the PORT A register in this position. In this example we are
assigning the contents of I/O PORT A to the simple variable N.
IF (N AND 1) = 1 THEN
RESULT
Check the Sunset Labs manual for further information on possible configurations for the DDR.
Page 9
As you can see from the table, the only time the result is 1 is when
both digits are 1. How does this apply to our example? Since no other
switches are connected, the contents of I/O Port A can only be
00000000 (switch open) or 000000001 (switch closed). If we AND
the contents of I/O Port A with the number 1 (00000001 binary) there
can only be two results:
00000000
00000001
------------00000000
00000001
00000001
------------00000001
Therefore this line checks the contents of the Port A register to see if the
switch has been closed. If you are a little confused at this point, don't
worry. You are going to do several more activities which should make
this procedure routine. The rest of this program is straight forward and
should not require further comment.
ACTIVITY 2
Materials:
Make sure the computer is turned off before you make any connections.
Connect the DIP plug to the bread board and plug into Port #1 of the AIB board. Connect the other
components according to the next illustration. Again, have your teacher check the circuit before you turn on
the computer.
Page 10
This activity is
identical to Activity 1,
except that you will
connect the switch to
I/O line 2 (PA2).
When your set-up has been checked, turn on the computer, run Quick Basic and enter the edit screen. Type
in the following basic program:
Page 11
N = INP(816)
IF (N AND 4) = 4 THEN
PRINT "SWITCH IS CLOSED"
ELSE
PRINT "SWITCH IS OPEN"
ENDIF
LOOP
Check the program and then run it. Press the switch several times.
What do you observe? Press the enter key to stop the program,
PROGRAM COMMENTS
The only difference in this program is that we are checking for a switch closure on I/O line 2 of Port A
(PA2). In fact, this is the third I/O line as the numbering starts at 0. Lets investigate the third line in the
program.
IF (N AND 4) = 4
The difference is that we are using the AND operator with the decimal number 4
which is 00000100 binary. Remember you have connected the switch to I/O line
2 (PA2). When the switch is pressed the bit pattern 00000100 is placed in the
PORT A register. To review the function of the AND operator consider the
following.
00000000
00000100
------------00000000
00000100
00000100
------------00000100
YOUR TURN
Modify the circuit and the program so that a switch connected to I/O line 1 of PORT A (ie. PA1) is detected
by the program. Again make sure the computer is turned off and your circuit is double checked before you
proceed.
Questions:
1.
What number did you AND with N (INP(816)) to detect the switch closing.
2.
Use eight bit binary numbers to show how the AND operator works for your example.
ACTIVITY 3
Page 12
Materials:
Advanced
Interface
Board
(installed)
Microcompu
ter
Ribbon
cable with
connectors
Activity 3: Bread board setup
Bread board
21 kS resistor, watt
2 - momentary switch
Jumper wires
Make sure the computer is turned off before you make any connections.
Connect the DIP plug to the bread board and plug into Port #1 of the AIB board. Connect the other
components according to the next illustration. Again, have your teacher check the circuit before you turn on
the computer.
This activity is a combination of Activity 1 and Activity 2. You will connect two switches and use an
appropriate program to detect the individual switch closures.
Page 13
When your set-up has been checked, turn on the computer, run Quick Basic and enter the edit screen. Type
in the following basic program:
819, 154
OUT
DO
WHILE
INKEY$
<>
CHR$(13
)
N=
INP(816)
(N AND 1) = 1 THEN
IF
END IF
LOOP
Check the program and then run it. Press each switch several times.
Page 14
What do you observe? Press the enter key to stop the program,
PROGRAM COMMENTS
This is a combination of the first two programs. It is important that the brackets are used in the IF and
ELSEIF lines or the decision cannot be made correctly. Try adding these lines to each part of the program
shown. These new lines activate the computer's built in speaker and provide audio feedback of a switch
closure.
IF (N AND 1) = 1 THEN
PRINT "SWITCH A IS CLOSED"
BEEP : BEEP
ELSEIF (N AND 4) = 4 THEN
PRINT "SWITCH B IS CLOSED"
BEEP : FOR I = 1 TO 500 : NEXT I : BEEP
YOUR TURN
1.
Modify the circuit and the program so that the switches are connected to I/O line 1 of PORT A
(PA1) and I/O line 3 (PA3) and their individual closure is detected by the program. Again make
sure the computer is turned off and your circuit is double checked before you proceed.
2.
Modify the program in #1 or the original program so that the program reports "BOTH
SWITCHES CLOSED" if both switches are pressed together. (This is not hard to do, but
you should know the IF...ELSEIF....ELSE block structure. Check Page 12 of the
"Programming in Basic" section of the Microsoft Quick Basic Manual for some information on this
structure.
Page 15
ACTIVITY 4
Materials:
Make sure the computer is turned off before you make any connections.
Connect the DIP plug to the bread board and plug into Port #1 of the AIB board. Connect the other
components according to the next illustration. Again, have your teacher check the circuit before you turn on
the computer.
NOTE: The Phototransistor has a plastic tab closest to the emitter lead. For this type of transistor, the
emitter is connected to the ground (0 volts). If the photo transistor is reversed it will not operate properly.
The Infrared LED has a flat on the circular base. This is closest to the cathode, which is also connected to
ground. If it is reversed it also will not operate. If you are not sure, connect a visible red LED to make sure
the circuit is working (you can't see the infrared light from the IR LED). You can then replace it with the IR
LED as the phototransistor is not very sensitive to the visible red light. The 330 S resistor limits the current
in the LED.
Page 16
YOUR TURN
Page 17
1.
Modify the circuit and the program so that the photo transistor is connected to I/O line 1 of PORT A
(PA1). Again make sure the computer is turned off and your circuit is double checked before you
proceed.
2.
Physically move the photo transistor (or the LED) to see what kind of range you can get. Make
sure the electrical connections are correct. A strong flash light or a small laser can also be used as a
light source.
Page 18
PROJECTS
1.
Simulate a computerized security system that protects two doors and two windows in a building.
Use switches for three of the openings and the photo transistor for the fourth. Make sure your
program can tell the security guard which of the windows or doors has been opened.
2.
Design a program and configure the hardware to count the number of times the light beam is
broken. The running total should be displayed on the screen. Use the photo transistor and the
infrared diode. You don't have to make it large enough for people, just simulate it on the bread
board.
Page 19
Page 20
ACTIVITY 5
Materials:
Make sure the computer is turned off before you make any connections.
Connect the DIP plug to the bread board and plug into Port #2 of the AIB board. Connect the other
components according to the next illustration. Again, have your teacher check the circuit before you turn on
the computer.
NOTE: The red LED has a flat on the circular base. This is closest to the cathode, which is connected to
ground. If it is reversed it will not operate. The 7406 chip has a dot that identifies pin #1. Make sure it is in
the right place on the bread board.
Page 21
computer. Note: the LED should light. If it does not, recheck your circuit. Run Quick Basic and enter the
edit screen. Type in the following basic program:
OUT 819, 136
OUT 817, 0
Run the program. The LED should go out.
PROGRAM COMMENTS
This very short program tests to see if your interface is correctly wired. The first out statement places the
decimal number 136 in the Data Direction Register (also called the Control Register). Check the table in
Activity 1. This value causes I/O PORTS A and B to be used as OUTPUTS. The second line places a 0
(00000000 binary) in PORT A, which causes the LED to go out.
If your circuit is working, type in the following programs. Each is an example of different techniques to
control an external device, in this case the LED.
OUT 819, 136
X = 300
Y = 300
DO WHILE INKEY$ <> CHR$(13)
OUT 817, 1
FOR J = 1 TO X : NEXT J
OUT 817, 0
FOR J = 1 TO Y : NEXT J
LOOP
Run this program. You should now have a miniature lighthouse.
Note: The line OUT 817,1 (00000001 binary) places a 1 on line 0 (PB0) of I/O PORT B. This causes the
7406 chip to turn the LED on.
What is the function of the FOR...NEXT loops? What will happen if you make changes to the values of the
variables X and Y? Change them and see. If you know how, try replacing X and Y with random numbers.
The next two programs use keyboard keys to turn the LED on and off. Which one is better?
OUT 819, 136
CLS
PRINT "Press the A key to turn light on"
PRINT "Press the B key to turn light off"
Page 22
PRINT
PRINT "Press the ENTER key to end"
DO WHILE INKEY$ <> CHR$(13)
IF INKEY$ = "A" THEN
OUT 817, 1
ELSEIF INKEY$ = "B" THEN
OUT 817, 0
END IF
LOOP
Did your program work. If it didn't, you may not have the cap lock on! The program is looking for a
capital A and B. Try modifying for lower case or investigate the UCASE$ function.
OUT 819, 136
CLS
PRINT "Press F1 to turn light on"
PRINT "Press F2 to turn light off"
PRINT
PRINT "Press the ENTER key to end"
DO WHILE INKEY$ <> CHR$(13)
ON KEY(1) GOSUB LIGHTON
ON KEY(2) GOSUB LIGHTOFF
KEY(1) ON
KEY(2) ON
LOOP
END
LIGHTON:
OUT 817, 1
RETURN
LIGHTOFF:
OUT 817, 0
RETURN
The KEY statement allows access to the keyboard keys. Did you leave out the colon (:) in the subroutine
labels? You can try other keys as well as combinations of keys eg. CTRL O. See page 235 to 239 in the
"Programming in Basic" section of the Quick Basic manual.
Page 23
ACTIVITY 6
Materials:
Make sure the computer is turned off before you make any connections.
Connect the DIP plug to the bread board and plug into Port #2 of the AIB board. Connect the other
components according to the next illustration. Again, have your teacher check the circuit before you turn on
the computer.
NOTE: The red LED has a flat on the circular base. This is closest to the cathode, which is connected to
ground. If it is reversed it will not operate. The 7406 chip has a dot that identifies pin #1. Make sure it is in
the right place on the bread board. This is a similar activity to #5 except you will be using 2 LEDS. Take
note of how the I/O PORT is accessed to control the second LED.
Page 24
When your
set-up has been checked, turn on the computer. Note: Both LEDs should light. If they do not, recheck your
circuit. Run Quick Basic and enter the edit screen. Type in the following basic program. (Note: If you have
saved the second program from Activity 5, you can open it and make a few changes.)
OUT 819, 136
X = 300
Y = 300
DO WHILE INKEY$ <> CHR$(13)
OUT 817, 1
FOR J = 1 TO X : NEXT J
OUT 817, 0
FOR J = 1 TO Y : NEXT J
Page 25
OUT 817, 4
FOR J = 1 TO X : NEXT J
OUT 817, 0
FOR J = 1 TO Y : NEXT J
LOOP
PROGRAM COMMENTS
The line, OUT 817, 4 is really the only difference in this activity. The decimal number 4 is 00000100
binary. This number forces the third I/O line of Port B (PB2) to go to a high level and turns on the second
LED.
YOUR TURN
1.
Using a red, a green and a yellow LED as well as the Quick Basic program, simulate the operation
of a traffic light. Make sure the LEDs are on in the correct sequence and for the approximate times.
You might want to use input statements to enter the sizes of the timing loops.
Because you are increasing the number of parts on the bread board, be extra careful that all
connections are correct and that you have used the appropriate current limiting resistors with the
LEDs. Have someone double check the circuit before applying power.
2.
Page 26
Many traffic lights have a blinking arrow for a left turn which comes on before the light turns
green. Add a second green LED to the first circuit and simulate this light. Make it rapidly blink as
in the real thing. Again, observe the precautions listed above before turning on the computer.
Up to now you have been using the computer and interface card to operate a low current device, the LED.
With the addition of a few parts you can control devices that require larger current such as motors,
incandescent light bulbs, heaters, electromagnets.
In activity #5 you were introduced to the 7406 hex inverter. One of its functions was to switch enough
current to operate the LED. The basic building block that comprises the 7406 and in fact all electronic
devices is the transistor. You have already used a photo transistor (activity #4 ) as a switch which is
activated by light. A common transistor is activated by a small current. In the next few activities you will
use a power transistor to control the current to several external devices. The following is a diagram of a
silicon, NPN power transistor, the TIP29A, made by Texas Instruments.
Page 27
switch is closed,
current will flow
and the motor will
turn.
Page 28
In the previous diagram, the transistor's base was not connected. Here the base is connected to one of the I/O
Lines. The emitter is connected to the computer's ground pin to complete the control circuit. The transistor
is switched on when a positive potential (+5 volts) is placed on the base. This is done by placing a 1 on the
appropriate place of the I/O Port register which forces the corresponding line to go high.
The next set of activities will make use of the current switching property of the transistor.
ACTIVITY 7
Materials:
Make sure the computer is turned off before you make any connections.
Connect the DIP plug to the bread board and plug into Port #2 of the AIB board. Connect the other
Page 29
components according to the next illustration. Again, have your teacher check the circuit before you turn on
the computer.
If the motor
runs when
you turn on
the
computer,
immediatel
y turn it off
and check
Page 30
your connections.
You will use a simple program to test your circuit. If you have saved your programs from previous
activities, you can load and modify the third program from activity 5. If you haven't, type in and run the
following:
OUT 819, 136
CLS
PRINT "Press F1 to turn motor on"
PRINT "Press F2 to turn motor off"
PRINT
PRINT "Press the ENTER key to end"
DO WHILE INKEY$ <> CHR$(13)
ON KEY(1) GOSUB MOTORON
ON KEY(2) GOSUB MOTOROFF
KEY(1) ON
KEY(2) ON
LOOP
END
MOTORON:
OUT 817, 1
RETURN
MOTOROFF:
OUT 817, 0
RETURN
When you have tested the motor control, press the enter key.
The comments for the programs in activity 5 apply to this activity. You have used a different device to
control the current to the external device, but the programming of the I/O Port is the same.
Page 31
You have just used a simple circuit to switch current from an external power supply, in this case, a battery.
The transistor used there is limited to about 1 ampere of current and a potential of 100 volts DC. What if you
needed to control a more powerful device such as an electric heater, a furnace or a large AC motor? The
device most widely used to switch high current is called an electromagnetic relay. It is also the oldest
of the devices you will connect to the computer, dating back to the last century. In fact the first electro
mechanical computer, invented in the 1930's, used the relay as its active component. You may have already
studied the operation of this device in a general science or physics course. We will summarize its operation
briefly for those who haven't. Consider the following illustration:
When current
flows through
the
electromagnet
, the moving
arm is
attracted and
the contact points close. The contact points make up a switch which can be used to control an external
circuit. When the current stops, the return spring opens the contact points and therefore breaks whatever
external circuit to which the relay is connected. Most modern relays are sealed, many in an inert
environment of nitrogen gas. You will use a small breadboard mounted relay to simulate the control of large
devices.
You will also be using another device called an opto isolator. In activity
#4 you set up a photo transistor and an LED to form a control device with which the computer could sense
the blocking and unblocking of a light beam. An opto isolator consists of both these components placed in a
6 pin, DIP package which looks very much like an integrated circuit chip. What is the opto islolator used
for? It has several functions. The name opto isolator translates to optically isolated. This means that you
can electrically isolate one part of a circuit from another. The control signals from one part of the circuit are
coupled to another part optically, that is by light. (This device is also called an opto coupler.) This is a safety
feature, in that, if you connect something incorrectly in the circuit, the computer itself is isolated from the
mistake and will not be damaged. It also isolates the computer from any electrical "noise" that may be
generated in the external circuit. This noise can cause false signals to disrupt the computer's operation.
There is another reason for your use of the opto coupler in the next activity. The 7406 chip can only handle
30 milliamperes (.030 ampere) of current. If you are going to use a relay whose electromagnet (called a
Page 32
coil) requires more than this current, then you must use some other device to supply it. You could use a
transistor as you did in the last activity, but for the other reasons already given, you will use the isolator. The
NPN photo transistor in the device can safely handle 150 ma (milliamperes) which is more than adequate for
the relay. The relay will be used to control a small incandescent light but you can also connect a motor, etc.
The next illustration shows the internal parts of the opto isolator. Note which pins connect to the LED and
the photo transistor.
Page 33
ACTIVITY 8
Materials:
Make sure the computer is turned off before you make any connections.
Connect the DIP plug to the bread board and plug into Port #2 of the AIB board. Connect the other
components according to the next illustration. Again, have your teacher check the circuit before you turn on
the computer. This circuit is the most detailed to date. Work slowly and double check each connection.
Page 34
You
can
use the same program as in the previous activity to control the light. Modify it slightly so that it will display
"Print F1 to turn light on" etc. Try replacing the light with the motor. When the you activate the circuit
listen for a faint clicking sound as the points of the relay open and close.
Questions
1.
Trace the operation of the external circuit from the I/O line to the light.
2.
3.
If you were to use this circuit to control a large motor, for example a conveyer belt in a factory,
what would you have to change in the circuit shown above? Explain why.
Page 35
ACTIVITY 9
Materials:
Make sure the computer is turned off before you make any connections.
Connect one of the DIP plugs into the left side of the bread board (see next diagram) and plug into Port #1
of the AIB board. Plug the other DIP plug into the right side of the bread board and plug into Port #2 of
the AIB board. Connect the other components according to the diagram. Again, have your teacher check
the circuit before you turn on the computer.
Page 36
Type the
following program.
Page 37
This line places 152 in the data direction register. If you check the table
in activity #1, 152 sets I/O PORT A as an input port and I/O PORT B as
an output port.
Note also that both I/O addresses 816 and 817 are used which correspond to the two ports.
If your circuit is connected properly (and your program is working) the motor should start when you break
the infrared beam. If the motor starts without the beam being interrupted, the LED may not be squarely
facing the photo transistor.
Page 38
YOUR TURN
1.
Modify the program so that the motor is on only when the beam is blocked.
2.
Make a modification to do the opposite, that is the motor is only off if the beam is blocked.
3.
Modify the program so that the motor turns on only after the beam is blocked twice in a row. That
is the motor remains off after the first pass through the beam and activates the second time the beam
is blocked. (You may have to install time delays to allow the computer to count the number of
times the beam is blocked.
4.
CHALLENGE: Can you think of a way to make the motor run in reverse as well as forward.
Please show your circuit ideas to your teacher before you proceed.
Page 39
ACTIVITY 10 (OPTIONAL)
Materials:
BACKGROUND:
In previous activities you used a small DC motor which was configured to run under computer control. This
type of motor usually runs at a set, high speed for a given voltage. The stepper motor is different in that it
can be controlled to turn in small increments or steps either forward or in reverse. This kind of motor forms
the basis of the very accurate drive components found in printers, disk drives, computer controlled industrial
machines, robots and aircraft control. The bipolar stepper motor has four electromagnets or coils and one
permanent magnet that is connected to the motor shaft. The permanent magnet can move in a clockwise or
counter clockwise steps when the electro magnets are turned on in order. Diagram. 1 shows part of the
sequence.
The stepper motor can be connected to the computer through many types of interface circuits. The simplest
configuration, however, is to use a special integrated circuit (ic) that is designed for this purpose. The
SAA1042 found in your kit, can be used to drive a small 12 V (or less) with very few external parts added.
This chip can control the 4 electromagnets or coils in the motor. The computer is used to send pulses to pin 7
of this chip. Each pulse causes the stepper motor to make one step. The faster the pulses arrive, the faster
the motor steps. The computer can generate a pulse by turning on an I/O Line and then quickly turning it
off. By placing a low 0 (0 V) or a high 1 (5 V) on pin 10, the motor can be made to turn clockwise or
counter clockwise. Diagram 2 is an illustration of what happens in the circuit. A 7406 hex inverter is used to
make sure the on-off pulses are "clean" and cause no confusion for the SAA1042 chip.
Page 40
Make sure the computer is turned off before you make any connections.
Connect the DIP plug into the left side of the bread board (see next diagram) and plug into Port #2 of the
AIB board. Connect the other components according to the diagram. Again, have your teacher check the
circuit.
The two breadboard illustrations that follow are for the same setup. The first diagram does not show the
motor hookup. The second diagram is an enlarged drawing of the right side of the bread board.
Page 41
Page 42
X=1
Y=0
RETURN
BACKWARD:
X=3
Y=2
RETURN
Run the program and verify that the motor is turning. If any components on the bread board get very hot,
check the circuit diagram.
PROGRAM COMMENTS
OUT 817, X & OUT 817, Y
YOUR TURN
1.
2.
Try changing the value 200 in the timing loop to run the motor slower or faster. What is the
smallest value that will still run the motor?
What would the program look like if you use PB2 and PB3 instead of PB0 and PB1 to control the
stepper motor controller chip.?
PRINT
PRINT SPC (10) "Press F3 to run motor faster"
PRINT
PRINT SPC (10) "Press F4 to run motor slower"
DO WHILE INKEY$ <> CHR$(13)
ON KEY(1) GOSUB FORWARD
ON KEY(2) GOSUB BACKWARD
ON KEY(3) GOSUB FASTER
ON KEY(4) GOSUB SLOWER
KEY(1) ON
KEY(2) ON
KEY(3) ON
KEY(4) ON
OUT 817, X
OUT 817, Y
FOR J = 1 TO T : NEXT J
LOOP
END
FORWARD:
X=1
Y=0
RETURN
BACKWARD:
X=3
Y=2
RETURN
FASTER:
IF T > 10 THEN
T = T - 20
END IF
RETURN
SLOWER:
T = T + 20
RETURN
YOUR TURN
1.
2.
Modify your program so that some indicator of speed is printed on the screen.
Page 45
3.
Create a program that will allow the user to input the number of steps to turn the motor in either
direction. The motor should then turn the required number of steps and stop.
4.
Modify the program in #3 to allow the user to input the turn angle in degrees. Hint: How many
steps does your stepper motor need to make a full turn 3600. (Dividing 3600 by the number of steps
gives the resolution of your motor in degrees. That is the finest step it is capable of. This is one
specification you need to know if you are buying a motor for a particular application.
PROJECTS
The stepper motor is an excellent start point for project work. Robot arms, smart conveyer belts, positioning
tables, sun trackers, and a variety of other devices can be controlled. See your teacher for help in identifying
some applications.
Page 46