9
82C54
A new initial count may be written to a Counter at an y time
without aff ecting the Counter’ s prog rammed Mode in an y wa y.
Counting will be aff ected as described in the Mode definitions.
The new count m ust follo w the prog r ammed count format.
If a Counter is programmed to read/write two-byte counts,
the follo wing precaution applies. A prog ram must not transfer
control between writing the fi rst and second byte to another
routine which also writes into that same Counter. Otherwise ,
the Counter will be loaded with an incorrect count.
READ OPERATIONS
It is often desirable to read the value of a Counter without
disturbing the count in progress. This is easily done in the
82C54.
There are three possible methods for reading the Counters.
The first is through the Read-Back command, which is
ex plained later . The second is a simple read operation of the
Counter, which is selected with the A1, A0 inputs. The only
requirement is that the CLK input of the selected Counter
must be inhibited by using either the GATE inpu t or external
logic. Otherwise, the count may be in process of changing
when it is read, giving an undefined result.
COUNTER LATCH COMMAND
The other method for reading the Counters involves a
special software command called the “Counter Latch
Command”. Like a Control Word, this command is written to
the Control Word Register, which is selected when A1, A0 =
11. Also , like a Control W ord, the SC0, SC1 bits select one of
the three Counters, but two other bits, D5 and D4,
distinguish this command from a Control Word.
.
The selected Counter’s output latch (OL) latches the count
when the Counter Latch Command is received. This count is
held in the latch until i t is read by the CPU (or unti l the Counter
is reprogr ammed). The count is then unlatch ed automatically
and the OL returns to “f ollowing” the counting element (CE).
This allows readin g the contents of the Counte rs “on the fly”
without affecting counting in prog ress. Multip le Cou nter Latch
Commands may be used to latch more than one Cou nter.
Each latched Counter’s OL holds its count until read. Counter
Latch Commands do not affect the programmed Mode of the
Counter in any way.
If a Counter is latched and then, some time later, latched
again before the count is read, the second Counter Latch
Command is ignored. The count read will be the count at the
time the first Counter Latch Command was issued.
With either method, the count must be read according to the
programmed format; specifically, if the Counter is
programmed for two byte counts, two bytes must be read.
The two bytes do not have to be read one right after the
other; read or write or programming operations of other
Counters may be inserted between them.
Another feature of the 82C54 is that reads and writes of the
same Counter may be interleaved; for example, if the
Counter is programmed for two byte counts, the following
sequence is valid.
1. Read least significant byte.
2. Write new least significant byte.
3. Read most significant byte.
4. Write new most significant byte.
If a counter is programmed to read or write two-byte counts,
the follo wing precaution applies: A program MUST NO T
transf er control between reading the first and second byte to
another routine which also reads from that same Counter.
Otherwise, an incorrect count will be read.
READ-BACK COMMAND
The read-back command allows the user to check the count
value, programmed Mode, and current state of the OUT pin
and Null Count flag of the selected counter(s).
The command is written into the Control Word Register and
has the format shown in Figure 5. The command applies to
POSSIBLE PROGRAMMING SEQUENCE
A1 A0
Control Word - Counter 1 1 1
Control Word - Counter 0 1 1
LSB of Count - Counter 1 0 1
Control Word - Counter 2 1 1
LSB of Count - Counter 0 0 0
MSB of Count - Counter 1 0 1
LSB of Count - Counter 2 1 0
MSB of Count - Counter 0 0 0
MSB of Count - Counter 2 1 0
NOTE: In all four examples, all counters are programmed to
Read/Write two-byte counts. These are only four of many
programming sequences.
A1, A0 = 11; CS = 0; RD = 1; WR = 0
D7 D6 D5 D4 D3 D2 D1 D0
SC1SC000XXXX
SC1, SC0 - specify counter to be latched
SC1 SC0 COUNTER
00 0
01 1
10 2
1 1 Read-Back Command
D5, D4 - 00 designates Counter Latch Command, X - Don’t Care.
NOTE: Don’t Care bits (X) should be 0 to insure compatibility
with futu re p ro du ct s.