8254
Mode Definitions
The following are defined for use in describing the
operation of the 8254.
CLK Pulse: a rising edge, then a falling edge, in
that order, of a Counter’s CLK in-
put.
Trigger: a rising edge of a Counter’s GATE
input.
Counter loading: the transfer of a count from the CR
to the CE (refer to the ‘‘Functional
Description’’)
MODE 0: INTERRUPT ON TERMINAL COUNT
Mode 0 is typically used for event counting. After the
Control Word is written, OUT is initially low, and will
remain low until the Counter reaches zero. OUT then
goes high and remains high until a new count or a
new Mode 0 Control Word is written into the Coun-
ter.
GATE
e
1 enables counting; GATE
e
0 disables
counting. GATE has no effect on OUT.
After the Control Word and initial count are written to
a Counter, the initial count will be loaded on the next
CLK pulse. This CLK pulse does not decrement the
count, so for an initial count of N, OUT does not go
high until N
a
1 CLK pulses after the initial count is
written.
If a new count is written to the Counter, it will be
loaded on the next CLK pulse and counting will con-
tinue from the new count. If a two-byte count is writ-
ten, the following happens:
1) Writing the first byte disables counting. OUT is set
low immediately (no clock pulse required)
2) Writing the second byte allows the new count to
be loaded on the next CLK pulse.
This allows the counting sequence to be synchroniz-
ed by software. Again, OUT does not go high until
N
a
1 CLK pulses after the new count of N is written.
If an initial count is written while GATE
e
0, it will
still be loaded on the next CLK pulse. When GATE
goes high, OUT will go high N CLK pulses later; no
CLK pulse is needed to load the Counter as this has
already been done.
MODE 1: HARDWARE RETRIGGERABLE
ONE-SHOT
OUT will be initially high. OUT will go low on the CLK
pulse following a trigger to begin the one-shot pulse,
and will remain low until the Counter reaches zero.
OUT will then go high and remain high until the CLK
pulse after the next trigger.
After writing the Control Word and initial count, the
Counter is armed. A trigger results in loading the
Counter and setting OUT low on the next CLK pulse,
thus starting the one-shot pulse. An initial count of N
will result in a one-shot pulse N CLK cycles in dura-
tion. The one-shot is retriggerable, hence OUT will
remain low for N CLK pulses after any trigger. The
one-shot pulse can be repeated without rewriting the
same count into the counter. GATE has no effect on
OUT.
If a new count is written to the Counter during a one-
shot pulse, the current one-shot is not affected un-
less the counter is retriggered. In that case, the
Counter is loaded with the new count and the one-
shot pulse continues until the new count expires.
MODE 2: RATE GENERATOR
This Mode functions like a divide-by-N counter. It is
typically used to generate a Real Time Clock inter-
rupt. OUT will initially be high. When the initial count
has decremented to 1, OUT goes low for one CLK
pulse. OUT then goes high again, the Counter re-
loads the initial count and the process is repeated.
Mode 2 is periodic; the same sequence is repeated
indefinitely. For an initial count of N, the sequence
repeats every N CLK cycles.
GATE
e
1 enables counting; GATE
e
0 disables
counting. If GATE goes low during an output pulse,
OUT is set high immediately. A trigger reloads the
Counter with the initial count on the next CLK pulse;
OUT goes low N CLK pulses after the trigger. Thus
the GATE input can be used to synchronize the
Counter.
After writing a Control Word and initial count, the
Counter will be loaded on the next CLK pulse. OUT
goes low N CLK Pulses after the initial count is writ-
ten. This allows the Counter to be synchronized by
software also.
Writing a new count while counting does not affect
the current counting sequence. If a trigger is re-
ceived after writing a new count but before the end
of the current period, the Counter will be loaded with
the new count on the next CLK pulse and counting
will continue from the new count. Otherwise, the
new count will be loaded at the end of the current
counting cycle. In mode 2, a COUNT of 1 is illegal.
MODE 3: SQUARE WAVE MODE
Mode 3 is typically used for Baud rate generation.
Mode 3 is similar to Mode 2 except for the duty cycle
of OUT. OUT will initially be high. When half the
10