You are on page 1of 8

Lecture # 4

Outline of the Lecture


 I/O Programming in Assembly Language
 Stepper motor application
 Dc motor interfacing

PROGRAMMING THE PPI (MODE 0)

Ex: Configure the ports of 8255 (PPI) as follows: port A=input port
B=output port
CH=output port
CL=input port

(CL=Lower 4 bits of Port C, CH (CU) =Upper 4 bits of Port


C) (Assume that the 8255 PPI is located at 300H)

Sol:

Control register: A CH B CL
1 0 0 0

1 : input
0 : output

A CH B CL
1 0 0 1 0 0 0 1

This program initializes the PPI located at 300H as follows:


; port A : input
; port B : output
; port CH : output
; port CL : input

.MODELSMALL
.CODE
MAIN: MOV AL, 10010001B
MOV DX,303H ;If PPI is at 300H, then Port A=300H,
OUT DX,AL ;Port B =301, Port C=302 and Control reg:303H



MOV AH,4CH
INT 21H
MAIN
END
Interfacing 8255 to 8086 in I/O mapped I/O mode
Interfacing 8255 to 8086 in memory mapped I/O
I/O INTERFACE APPLICATIONS

Application 1: Stepper Motor Control

Stepper motors are used for position control applications, such as for the control of the disk
drives and in robotics.
• The most common stepper motors have four stator windings that are paired with a center
tapped common shown in Figure below (Figure 12.38-39 of the textbook).

• While the conventional motor shaft runs freely, the stepper motor shaft moves in a fixed
repeatable increment, which allows one to move it to a precise position.

Figure 1 below shows a four-coil stepper motor that uses an armature with a single pole.
Notice that the stepper motor is shown four times with the armature (permanent magnetic)
rotated to four discrete places. This is accomplished by energizing the coils, as shown. This
is an illustration of full stepping. The stepper motor is driven by using NPN Darlington
amplifier pairs to provide a large current to each coil. A circuit that can drive this stepper
motor is illustrated in Figure 2, with the four coils shown in place. This circuit uses the
82C55 to provide it with the drive signals that are used to rotate the armature of the motor in
either the right-hand or left-hand direction

Figure 1: The stepper motor showing full-step operation: (a) 45° (b) 135° (c) 225° (d) 315°.
The table below shows a normal 4-step Sequence. Note that once, we start with any of
the sequences in Table below (i.e. step 3 [0110] ) we must continue in the sequence of
steps, 4, 1, 2, and so on.

Clockwise Step # Winding A Winding B Winding C Winding D Counter


| 1 1 0 0 1 Clockwise
| 2 1 1 0 0 /\
| 3 0 1 1 0 |
\/ 4 0 0 1 1 |
Normal 4-Step Sequence

Figure 2: A stepper motor interfaced to the 82C55. This illustration does not show the
decoder.

Ex: Given the 8255 connection to the stepper motor of Figure 2,


- code a program to rotate it continuously.
- press any key on the IBM PC keyboard to stop it.

(Assume that the 8255 PPI is located at 300H)


Use Port A as the output port, then the Control register will contain:

A CH BC L
1 0 0 0

1 : input
0 : output
A CH B CL
1 0 0 0 0 0 0 0

…………
MOV AL,80H ;control word for all 8255 ports as out
MOV DX,303H ;control register address of 8255
OUT DX,AL ;to control register
MOV BL,66H ;or BL=33H, BL=99H or BL=0CCH
AGAIN: MOV AH,01 ;check the key press
INT 16H ;using INT 16
JNZ EXIT ;stop if any key pressed
MOV AL,BL ;otherwise send pulse to the stepper motor
MOV DX,300H ;port A address of 8255
OUT DX,AL
MOV CX,0FFFFH ;(change this value to see rotation speed)
HERE: SUB AH,AH
LOOP HERE ;wait for delay
ROR BL,1 ;rotate for the next step
JMP AGAIN ;and continue until a key is pressed

Input Devices. Input devices are already TTL and compatible, therefore can be connected
to the microprocessor and its interfacing components, or they are switch-based. Most switch
based devices are either open or connected. These are not TTL levels—TTL levels are a logic 0
(0.0 V–0.8 V) or a logic 1 (2.0 V–5.0 V).
For a switch-based device to be used as a TTL-compatible input device, some conditioning must
be applied. Figure 3 shows a simple toggle switch that is properly connected to function as an
input device. Notice that a pull-up resistor is used to ensure that when the switch is open, the
output signal is logic 1; when the switch is closed, it connects to ground, producing a valid logic
0 level. The value of the pull-up resistor is not critical—it merely assures that the signal is at a
logic 1 level. A standard range of values for pull-up resistors is usually anywhere between 1K Ω
and 10K Ω.

Figure 3: A single pole, single-throw switch Interfaced as a TTL device.

Mechanical switch contacts physically bounce when they are closed, which can create a
problem if a switch is used as a clocking signal for a digital circuit. To prevent problems with
bounces, The circuit of figure 4, functions in the following manner: Suppose that the switch is
currently at position . If it is moved toward Q but does not yet touch Q, the Q output of the
circuit is logic 0. The logic 0 state is remembered by the inverters. The output of inverter B
connects to the input of inverter A. Because the output of inverter B is a logic 0, the output of
inverter A is a logic 1. The logic 1 output of inverter A maintains the logic 0 output of inverter B.
The flip-flop remains in this state until the moving switch-contact first touches the Q connection.
As soon as the Q input from the switch becomes a logic 0, it changes the state of the flip-flop. If
the contact bounces back away from the Q input, the flip-flop remembers and no change occurs,
thus eliminating any bounce.

Figure 4: Denouncing switch contacts

Output Devices: Output devices are far more diverse than input devices, but many are interfaced
in a uniform manner. Before any output device can be interfaced, we must understand what the
voltages and currents are from the microprocessor or a TTL interface component. The voltages
are TTL-compatible from the microprocessor of the interfacing element. (Logic 0 = 0.0 V to 0.4
V; logic 1 = 2.4 V to 5.0 V.) The currents for a microprocessor and many microprocessor
interfacing components are less than for standard TTL components. (Logic 0 = 0.0 to 2.0 mA;
logic 1 = 0.0 to 400 μA.).
Once the output currents are known, a device can now be interfaced to one of the outputs. Figure
5 shows how to interface a simple LED to a microprocessor peripheral pin. Notice that a
transistor driver is used in Figure 5 (a) and a TTL inverter is used in Figure 5 (b). The TTL
inverter (standard version) provides up to 16 mA of current at a logic 0 level, which is more than
enough to drive a standard LED. A standard LED requires 10 mA of forward bias current to
light. In both circuits, we assume that the voltage drop across the LED is about 2.0 V.

Figure 5: Interfacing an LED: (a) using a transistor and (b) using an inverter.
The data sheet for an LED states that the nominal drop is 1.65 V, but it is known from
experience that the drop is anywhere between 1.5 V and 2.0 V. This means that the value of the
current limiting resistor is 3.0 V ÷ 10 mA or 300 Ω. Because 300 Ω is not a standard resistor
value (the lowest cost), a 330 Ω resistor is chosen for this interface.
In the circuit of Figure 5 (a), we elected to use a switching transistor in place of the TTL buffer.
The 2N2222 is a good low-cost, general-purpose switching transistor that has a minimum gain of
100. In this circuit, the collector current is 10 mA, so the base current will be 1/100 of the
collector current of 0.1 mA. To determine the value of the base current–limiting resistor, use the
0.1 mA base current and a voltage drop of 1.7 V across the base current–limiting resistor. The
TTL input signal has a minimum value of 2.4 V and the drop across the emitter-base junction is
0.7 V. The difference is 1.7 V, which is the voltage drop across the resistor. The value of the
resistor is1.7 V ÷ 0.1 mA or 17K Ω. Because 17K Ω is not a standard value, an 18K Ω resistor is
chosen.

Suppose that we need to interface a 12 V DC motor to the microprocessor and the motor current
is 1A. Obviously, we cannot use a TTL inverter for two reasons: The 12 V signal would burn out
the inverter and the amount of current far exceeds the 16 mA maximum current from the
inverter. We cannot use a 2N2222 transistor either, because the maximum amount of current is
250 mA to 500 mA, depending on the package style chosen. The solution is to use a Darlington-
pair, such as a TIP120. The TIP120 costs 25¢ and with the proper heat sink can handle 4A of
current. Figure 6 illustrates a motor connected to the Darlington-pair. The Darlington-pair has a
minimum current gain of 7000 and a maximum current of 4A. The value of the bias resistor is
calculated exactly the same as the one used in the LED driver. The current through the resistor is
1.0 A ÷ 7000, or about 0.143 mA. The voltage drop across the resistor is 0.9 V because of the
two diode drops (base/emitter junctions) instead of one. The value of the bias resistor is 0.9 V ÷
0.143 mA or 6.29K Ω. The standard value of 6.2 K Ω is used in the circuit. The Darlington-pair
must use a heat sink because of the amount of current going through it. Typically any device that
passes more than 1⁄2 A of current needs a heat sink. The diode must also be present to prevent
the Darlington-pair from being destroyed by the inductive kickback from the motor. This circuit
is also used to interface mechanical relays or just about any device that requires a large amount
of current or a change in voltage.

Figure 7: A DC motor interfaced to a system by using a Darlington-pair.

You might also like