You are on page 1of 25

Programmable Interval Timer

T.Shakeel, Lovely Professional University.


IC 8254 is an programmable interval
Timer, whose function is similar to software
program(counter and Time delay).
Applications are
Used to generate time delay
Clock pulses
Square wave generators and etc

T.Shakeel, Lovely Professional University.
T.Shakeel, Lovely Professional University.
8254 consists of 3- 16 bit counters, which works
individually.
This counters operates in 6 different modes
8254 is a 24 pin dual in line package IC
It requires +5v power supply.
To operate as an counter, 16 bit count value is to
be stored in register and required command should
be given to start the decrement operation
When the count is decrement to zero, and signal is
given to MPU( consider as a interrupt).
We can also read the contents of counter while its
value is decrementing.




T.Shakeel, Lovely Professional University.
8254 consists of 3 individual counter
register(0,1,2).
Data bus (D7-D0)
R/W control logic
Control register

Counter is having 2 input pins and one output
pin.
Input pins: CLOCK(CLK) and GATE
Output Pins: OUT
Data pins are connected to the data bus pins of MPU

T.Shakeel, Lovely Professional University.
In 8254 , 5 control logic pins are present
RD(AL):
WR(AL):
RD and WR control lines are connected with IOM, IOR,
MEMR and MEMW control lines of MPU.
CS(AL): This pins is used to Disable and enable
the 8254 chip and this is done by decoding the
address lines
A1,A0: This lines are used to select the 3 different
counter.
T.Shakeel, Lovely Professional University.
Each counter is assigned with individual
port address.
Control register is
Common to all
counters and has its
own port address.
T.Shakeel, Lovely Professional University.
T.Shakeel, Lovely Professional University.

8254 can be programmed to provide various types of output through write operation
and we can also check the count while counting through Read operation.

Write Operation:
To initialize a Counter, following steps are required
Write a control word into control register
Load the low-order byte of count in the counter register
Load the high-order byte of count in the counter register
Read Operation:
This operation can be done in 2 ways:
1. Reading the count after stopping the counter
2. Second method involves reading a count, while count is in progress(
READING ON FLY).



T.Shakeel, Lovely Professional University.
Problem Statement:
1. Identify the port addresses of the control register and counter 2
below.
2. Write a subroutine to initialize counter 2 in mode 0 with a count of
50,000. The sub routine should also include reading a counts on
the fly, when the count reaches zero, it should return to the main
program.
T.Shakeel, Lovely Professional University.
COUNTER: MVI A, B0H; control word initialization to c2
OUT 83H;Write in the control register
MVI A, LOWBYTE; move lower byte value into A
OUT 82H; load the lower value of count
MVI A, HIBYTE ; move upper byte value into A
OUT 82H; load the upper byte value of count
READ: MVI A, 80H; control word for reading a count
OUT 83H; write in the control register
IN 82H; read lower order byte from 8254
MOV D,A; store lower order byte in D
IN 82H; read higher order byte from 8254
ORA D; or operation to set zero flag
JNZ READ; if counter not equal to 0 go back to
READ
RET

T.Shakeel, Lovely Professional University.
Mode 0 Interrupt on terminal count
Mode 1 Programmable one-shot
Mode 2 Rate Generator
Mode 3 Square wave rate generator
Mode 4 Software triggered strobe
Mode 5 Hardware trigger strobe
T.Shakeel, Lovely Professional University.
The output in this mode is initially low, and will
remain low for the duration of the count if
GATE = 1.
Width of low pulse = NT
Where N is the clock count loaded into counter,
and T is the clock period of the CLK input.
T.Shakeel, Lovely Professional University.
When the terminal (zero)count is reached, the output will go
high and remain high until a new control word or new count
number is loaded.
In this mode, if GATE input becomes low at the middle of
the count, the count will stop and the output will be low.
The count resumes when the gate becomes high again.

T.Shakeel, Lovely Professional University.

T.Shakeel, Lovely Professional University.
This mode is also called hardware triggerable one-shot.
The triggering must be done through the GATE input by sending a 0-
to-1 pulse to it.
The following two steps must be performed:
1. Load the count registers.
2. A 0-to-1 pulse must be sent to the GATE input to trigger the counter.
Contrast this with mode 0, in which the counter produces the output
immediately after the counter is loaded as long as GATE = 1.
In mode 1 after sending the 0-to-1 pulse to GATE, OUT becomes low
and stays low for a duration of NT, then becomes high and stays
high until the gate is triggered again.
T.Shakeel, Lovely Professional University.

T.Shakeel, Lovely Professional University.
Mode 2 is also called divide-by-N counter.
In this mode, if GATE = 1, OUT will be high for the NT clock period,
goes low for only one clock pulse, then the count is reloaded
automatically, and the process continues indefinitely.
T.Shakeel, Lovely Professional University.

T.Shakeel, Lovely Professional University.
In this mode if GATE = 1, OUT is a square wave where the high pulse is
equal to the low pulse if N is an even number.
In this case the high part and low part of the pulse have the same
duration and are equal to (N/2)T (50% duty cycle)
If N is an odd number, the high pulse is one clock pulse longer.
This mode is widely used as a frequency divider and audio-tone
generator.
T.Shakeel, Lovely Professional University.

T.Shakeel, Lovely Professional University.
In this mode if GATE = 1, the output will go high upon loading the
count.
It will stay high for the duration of NT.
After the count reaches zero (terminal count), it becomes low for one
clock pulse, then goes high again and stays high until a new command
word or new count is loaded.
To repeat the strobe, the count must be reloaded again.
Mode 4 is similar to mode 2, except that the counter is not reloaded
automatically.
In this mode, the count starts the moment the count is written into the
counter.
T.Shakeel, Lovely Professional University.

T.Shakeel, Lovely Professional University.

This mode is similar to mode 4 except that the trigger must be done
with the GATE input.
In this mode after the count is loaded, we must send a low-to-high
pulse to the gate to start the counter.
T.Shakeel, Lovely Professional University.

T.Shakeel, Lovely Professional University.

You might also like