8254 Programmable Interval Timer
Dr A Sahu
Dept of Comp Sc & Engg.
IIT Guwahati
Hierarchy of I/O Control Devices
8155
I/O + Timer
8255
I/O
8253/54
Timer
2 Port (A,B),
No Bidirectional
HS mode (C)
4 mode timer
2 Port (A,B)
A is Bidirectional
HS mode (C)
Extra controls
6 mode timer
8259
Interrupt controller
8237
DMA controller
8251
Serial I/O USART controller
Outline
8155: Timer Modes Output
CLK
WR
Mode 00
Mode 01
Mode 10
Mode 11
N/2
N/2
N/2
N/2
N/2
N/2
N
N
N
8254: Brief
The 8254 PIT
8254 Block Diagram
Data
Bus
Buffer
Read/
Write
Logic
Counter
0
CLK 0
GATE 0
OUT 0
Internal
Bus
Control Word
Register
Counter
1
CLK 1
GATE 1
OUT 1
Counter
2
CLK 2
GATE 2
OUT 2
D0-D7
RDb
WRb
A0
A1
CSb
Control Logic
A1 | A0 | Selection |
0 | 0 | Counter 0 |
0 | 1 | Counter 1 |
1 | 0 | Counter 2 |
1 | 1 | Control Register |
Control Register
D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
SC1 | SC2 | RW1 | RW0 | M2 | M1 | M0 | BCD |
Select Counter 00: Counter 0 01: Counter 1 10: Counter 2 11: Read-Back Command | Read Write 00: Counter latch Command 01:RW LSByte only 10: RW MSByte only 11:RW LSByte first then Msbyte | 000 : Mode 0 001 :Mode 1 X10 :Mode 2 X11 :Mode 3 100 :Mode 4 101 : Mode 5 | 0/1 = Binary / BCD Mode | ||||
Programming Counters
Modes of 8254 Counter
Mode 0: Interrupt on Terminal Count
CLK
OUT
Count of 7 loaded
Mode 1: Hardware Retriggerable One Shot
CLK
GATE
OUT
Triggered with count of 5
Mode 2: Rate Generator
CLK
OUT
Count of 5 loaded
Write instruction to generate pulse every 50mcroS from Ctr0
PULSE: MVI A 14H ; Control word
OUT CTRAdd 83H
MVI A,64H ;Count value
OUT 80H ; load counter 0 with low
order byte
HALT
Mode 3: Square wave generator
CLK
OUT
Count of 6 loaded
Write instruction for 1KhZ square wave at Ctr 1
MVI A,76H ; load Control word for Ctr 1 mode 3
OUT 83H ; write to Ctrl reg
MVI A, D0H; lower order byte cnt
OUT 81H
MVI A,07H ; higher order byte
OUT 81H
HLT
D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
SC1 | SC2 | RW1 | RW0 | M2 | M1 | M0 | BCD |
01 | Load 16 bit (11) | 011 (mode 3) | 0 | ||||
Mode 4: Software Triggered Strobe
CLK
OUT
Triggered with count of 8
Mode 5: Hardware Triggered Strobe
H/W trigger with count of 8
CLK
OUT
Gate Setting of Counter
Modes | Low or Going Low | Rising | High |
Mode 0 | Disable Counting | - | Enable Counting |
Mode 1 | ----- | 1. Initiate Counting 2. Reset O/P after next Clock | --- |
|
|
| Enable Counting |
|
| Initiates Counting | Enable Counting |
| Disable Counting | | Enable Counting |
| | Initiates Counting | |
Read-Back Command
D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
SC1 | SC2 | COUNTb | STATUSb | CNT2 | CNT1 | CNT0 | 0 |
11: Read-Back Command | If (D5=0) count is lateched | D3=1 select counter 2 D2=1 select counter 1 D1=1 select counter 0 | | ||||
Read-Back Command
D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
OUTPUT | NULL COUNT | RW1 | RW0 | M2 | M1 | M0 | BCD |
Write a SR to generate an interrupt every 1 Second
Control word
D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
SC1 | SC2 | RW1 | RW0 | M2 | M1 | M0 | BCD |
01 | Load 16 bit (11) | 010 (mode 2) | 0 | ||||
D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
SC1 | SC2 | RW1 | RW0 | M2 | M1 | M0 | BCD |
10 | Load 8 bit (01) | 010 (mode 2) | 0 | ||||
Instruction to set up 1s interrupt
MVI A , 74H ; Mode for 1st CTR
OUT 83H ;Write in control register
MVI A,94H ; Mode for 2nd CTR
OUT 83H ; Write to control register
MVI A,50 ; low byte of CTR1=C350
OUT 81H ; load to CTR1 low byte
MVI A,C3 ; high byte of CTR1=C350
OUT 81H ; load to CTR1 high byte
MVI A,28H ; Count for Counter 2
OUT 82H ; Load Counter 2
RET
Thanks