Interfacing Timer
Topics to be covered
• Timer IC 8253/54
Programmable Interval
Timer (PIT)
• Serial I/O 8251
• Parallel I/O 8255
• A/D Converters
• D/A Converter
• Arithmetic Coprocessors
• System level interfacing
design
Definitions
• The programmable interval timer
generates accurate time delays
and can be used for applications
such as RTC, event counter, digital
one shot, square-wave generator
and complex waveform generator
• 8254 is upgraded version of 8253
and they are pin compatible
• 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
and Counters:
• Control Word
Format
3
A1 A0 Selection
0 0 Counter 0
0 1 Counter 1
1 0 Counter 2
1 1 Control Register
D7 D6 D5 D4 D3 D2 D1 D0
SC1 SC0 RW1 RW0 M2 M1 M0 BCD
SC1 SC0 Selection
0 0 Counter 0
0 1 Counter 1
1 0 Counter 2
1 1 Read-Back
Command
RW1 RW0 Action
0 0 Counter latch command
0 1 R/W LSB only
1 0 R/W MSB only
1 1 R/W LSB first, then MSB
M2 M1 M0 Mode
0 0 0 Mode 0
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
0 Binary Counter 16-Bits
1 BCD Counter
MODE: BCD:
Modes
MODE 0:
INTERRUPT
ON TC
Initially OUT is low. Once a count is loaded, the
counter is decremented every cycle and when the
count reaches zero, out goes high which can be
used as interrupt
MODE1:
HW-
RETRIGG-
ERABLE
ONE-SHOT
OUT is initially high. When the GATE is triggered,
the out goes low and at the end of the count, the
out goes high again, thus generating a one-shot
pulse
MODE 2:
RATE
GENERATO
R
This mode is used to generate a pulse equal to the
clock period at a given interval. When a count is
loaded, the out stays high until the count reaches 1,
and then the out low for one clock period. The
count is reloaded automatically and the pulse is
generated continuously 5
6
MODE 3: SQUARE-
WAVE
GENERATOR
When a count is loaded, OUT is high. The count is
decremented by two at every clock cycle, and
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:
SOFTWARE-
TRIGGERED
STROBE
OUT is initially high; it goes low for one clock
period at the end of the count. The count must be
reloaded for subsequent outputs.
MODE 5:
HARDWARE-
TRIGGERED
STROBE
Similar to Mode 4 except that it is triggered by the
rising pulse at the gate. Initially OUT is low and
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
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:
3. Count = 50 x 10E-6/0.5 x 10E-6 = 64H
(pulse width)/(clock duration)
9
D7 D6 D5 D4 D3 D2 D1 D0
0 0 0 1 0 1 0 0
Counter0 Load 8-bit
count
Mode-2 Binary
count
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:
2. Count: 10E-3/0.5E-6 = 2000 = 07D0H
11
D7 D6 D5 D4 D3 D2 D1 D0
0 1 1 1 0 1 1 0
Select
counter1
Load 16-bit
count
Mode-3 Binary
count
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

Interfacing with Timer IC.pptx interfacing with timer ic

  • 1.
    Interfacing Timer Topics tobe covered • Timer IC 8253/54 Programmable Interval Timer (PIT) • Serial I/O 8251 • Parallel I/O 8255 • A/D Converters • D/A Converter • Arithmetic Coprocessors • System level interfacing design Definitions • The programmable interval timer generates accurate time delays and can be used for applications such as RTC, event counter, digital one shot, square-wave generator and complex waveform generator • 8254 is upgraded version of 8253 and they are pin compatible • It has three identical 16-bit counters that can operate independently in any one of the six modes 1
  • 2.
  • 3.
    • Selection ofCWR and Counters: • Control Word Format 3 A1 A0 Selection 0 0 Counter 0 0 1 Counter 1 1 0 Counter 2 1 1 Control Register D7 D6 D5 D4 D3 D2 D1 D0 SC1 SC0 RW1 RW0 M2 M1 M0 BCD SC1 SC0 Selection 0 0 Counter 0 0 1 Counter 1 1 0 Counter 2 1 1 Read-Back Command RW1 RW0 Action 0 0 Counter latch command 0 1 R/W LSB only 1 0 R/W MSB only 1 1 R/W LSB first, then MSB
  • 4.
    M2 M1 M0Mode 0 0 0 Mode 0 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 0 Binary Counter 16-Bits 1 BCD Counter MODE: BCD:
  • 5.
    Modes MODE 0: INTERRUPT ON TC InitiallyOUT is low. Once a count is loaded, the counter is decremented every cycle and when the count reaches zero, out goes high which can be used as interrupt MODE1: HW- RETRIGG- ERABLE ONE-SHOT OUT is initially high. When the GATE is triggered, the out goes low and at the end of the count, the out goes high again, thus generating a one-shot pulse MODE 2: RATE GENERATO R This mode is used to generate a pulse equal to the clock period at a given interval. When a count is loaded, the out stays high until the count reaches 1, and then the out low for one clock period. The count is reloaded automatically and the pulse is generated continuously 5
  • 6.
    6 MODE 3: SQUARE- WAVE GENERATOR Whena count is loaded, OUT is high. The count is decremented by two at every clock cycle, and 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: SOFTWARE- TRIGGERED STROBE OUT is initially high; it goes low for one clock period at the end of the count. The count must be reloaded for subsequent outputs. MODE 5: HARDWARE- TRIGGERED STROBE Similar to Mode 4 except that it is triggered by the rising pulse at the gate. Initially OUT is low and 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
  • 7.
    Programming the 8254 WriteOperation • 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
  • 8.
    Programming of 8254 Asa 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
  • 9.
    Write instructios togenerate a pulse every 50us from counter0. 1. Mode : Mode-2 2. CW: 3. Count = 50 x 10E-6/0.5 x 10E-6 = 64H (pulse width)/(clock duration) 9 D7 D6 D5 D4 D3 D2 D1 D0 0 0 0 1 0 1 0 0 Counter0 Load 8-bit count Mode-2 Binary count
  • 10.
    4. Program PULSE: MVIA, 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
  • 11.
    Square-Wave Generator Write instructionsto generate a 1kHz square- wave from Counter1. 1. CW: 2. Count: 10E-3/0.5E-6 = 2000 = 07D0H 11 D7 D6 D5 D4 D3 D2 D1 D0 0 1 1 1 0 1 1 0 Select counter1 Load 16-bit count Mode-3 Binary count
  • 12.
    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