Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Interfacing Timer

Topics to be covered Definitions


• Timer IC 8253/54 • The programmable interval timer
Programmable Interval generates accurate time delays
Timer (PIT) and can be used for applications
• Serial I/O 8251 such as RTC, event counter,
• Parallel I/O 8255 digital one shot, square-wave
• A/D Converters generator and complex waveform
• D/A Converter generator
• Arithmetic Coprocessors • 8254 is upgraded version of 8253
• System level interfacing and they are pin compatible
design • It has three identical 16-bit
counters that can operate
independently in any one of the
six modes 1
Block Diagram of 8254

2
• Selection of CWR A1 A0 Selection
and Counters:
0 0 Counter 0
0 1 Counter 1
1 0 Counter 2
1 1 Control Register
•Control Word D7 D6 D5 D4 D3 D2 D1 D0
Format SC1 SC0 RW1 RW0 M2 M1 M0 BCD

SC1 SC0 Selection RW1 RW0 Action


0 0 Counter 0
0 0 Counter latch command
0 1 Counter 1 0 1 R/W LSB only
1 0 Counter 2 1 0 R/W MSB only
1 1 Read-Back 1 1 R/W LSB first, then MSB
Command 3
MODE: BCD:
M2 M1 M0 Mode 0 Binary Counter 16-Bits
0 0 0 Mode 0 1 BCD Counter
0 0 1 Mode 1
X 1 0 Mode 2
X 1 1 Mode 3
1 0 0 Mode 4
1 0 1 Mode 5

4
Modes
Initially OUT is low. Once a count is loaded, the
MODE 0:
counter is decremented every cycle and when the
INTERRUPT
count reaches zero, out goes high which can be
ON TC
used as interrupt
MODE1: OUT is initially high. When the GATE is triggered,
HW-RETRI the out goes low and at the end of the count, the
GG-ERABLE out goes high again, thus generating a one-shot
ONE-SHOT pulse
This mode is used to generate a pulse equal to the
MODE 2: clock period at a given interval. When a count is
RATE loaded, the out stays high until the count reaches 1,
GENERATO and then the out low for one clock period. The
R count is reloaded automatically and the pulse is
generated continuously
5
MODE 3: When a count is loaded, OUT is high. The count is
SQUARE-WAVE decremented by two at every clock cycle, and
GENERATOR when it reached zero, the OUT goes low and the
count is reloaded again. This is repeated
continuously, thus a cont. square wave is
generated
MODE 4: OUT is initially high; it goes low for one clock
SOFTWARE-TRIGG period at the end of the count. The count must be
ERED STROBE reloaded for subsequent outputs.

MODE 5: Similar to Mode 4 except that it is triggered by the


HARDWARE-TRIG rising pulse at the gate. Initially OUT is low and
GERED STROBE when the gate pulse is triggered from low to high,
the count begins. At the end of the count, the OUT
goes low for one clock period
6
Programming the 8254
Write Operation
• Write a CW into the CR
• Load the low-order byte of a count in the counter
register
• Load the high-order byte of a count in the counter
register
With a clock and appropriate gate signal the above
steps should start the counter
Read Operation
• Reading after stopping counter
• Reading counter on fly

7
Programming of 8254
As a Counter: Write a subroutine to Initialize counter 2 in mode 0 with a count
50,000d. Read the count on fly. When the count reaches 0 it should return to main
program.
• Control Word: 10110000 = B0H
• Subroutine:
MVI A, B0H; CW to initialize counter 2
OUT 83H; write in CR
MVI A, LOBYTE; LO Byte of 50,000
OUT 82H; Load Counter 2 with LO Byte
MVI A, HIBYTE; HO Byte of 50,000
OUT 82H; Load Counter 2 with HO Byte
READ: MVI A, 80H; CW to Latch a count
OUT 83H; Write in CR
IN 82H; Read LO Byte
MOV D,A; Save LO Byte in D
IN 82H; Read HO Byte
ORA D; OR LO and HO Bytes to set Z flag
JNZ READ
RET

8
Write instructios to generate a pulse every 50us
from counter0.
1. Mode : Mode-2
2. CW: D7 D6 D5 D4 D3 D2 D1 D0
0 0 0 1 0 1 0 0
Counter0 Load 8-bit Mode-2 Binary
count count

3. Count = 50 x 10E-6/0.5 x 10E-6 = 64H


(pulse width)/(clock duration)

9
4. Program
PULSE: MVI A, 14H; control word
OUT 83H; write in control register
MVI A, 64H; LO Byte of the count
OUT 80H; load Counter0 with LO Byte
HALT

10
Square-Wave Generator
Write instructions to generate a 1kHz
square-wave from Counter1.
1. CW: D7 D6 D5 D4 D3 D2 D1 D0
0 1 1 1 0 1 1 0
Select counter1 Load 16-bit Mode-3 Binary
count count

2. Count: 10E-3/0.5E-6 = 2000 = 07D0H

11
Program:
SQWAVE: MVI A, 76H; control word
OUT 83H; write in control register
MVI A, D0H; LO byte of the count
OUT 81H; load counter 1 with LO byte
MVI A, 07H; HO byte of the count
OUT 81H; load counter1 with LO byte
HALT

12

You might also like