Counter/Timer Operation
VL-486-4 Reference Manual
CIO Chip – 97
Note
In order to ensure the enabling or disabling of the counter/timer on a particular
rising edge of the clocking signal, sufficient setup time must be allowed. The gate
signal must be valid prior to immediately preceding falling edge of the clocking
signal.
The reaction to triggers occurring during a countdown sequence is determined by the state of the
Retrigger Enable Bit (REB) in the Mode Specification register. If REB is 0, retriggers are
ignored and the countdown continues normally. If REB is 1, each trigger causes the down-
counter to be reloaded and the countdown sequence starts over again. If the output is
programmed is the Square-Wave mode, a retrigger causes the sequence to start over from the
initial load of the time constant.
The state of the down-counter can be determined in two ways: by reading the contents of the
down-counter via the Current Count register or by testing the Count In Progress (CIP) status bit
in the Command and Status register. The CIP status bit is set when the down-counter is loaded: it
is reset when the down-counter reaches 0. The Current Counter register is a 16-bit register,
accessible as two 8-bit registers, which mirrors the contents of the down-counter. This register
can be read at any time. However, reading the register is asynchronous to the counter’s counting,
and the value returned can be guaranteed as valid only if the counter is stopped. The down-
counter can be read reliably while it is counting by first writing a 1 to the Read Counter Control
(RCC) bit in the counter/timer’s Command and Status register. This freezes the value in the
Current Count register until a read of the least-significant byte is performed. A read of RCC
indicates if the CCR is holding a value, or if it is following the down-counter.
E
NDING
C
ONDITION
The Continuous/Single Cycle (C/SC) bit in the Mode Specification register controls operation of
the down-counter when it reaches terminal count (the count following the count of 1). If C/SC is
0 when a terminal count is reached, the countdown sequence stops. If the C/SC bit is 1 each time
the count-down counter reaches 1, the next cycle causes the time constant value to be reloaded.
The time constant value may be changed by the CPU, and on reload, the new time constant value
is loaded. This must be done with care.
Each time the counter reaches terminal count, its Interrupt Pending (IP) bit is set to 1, and if
interrupts are enabled (IE = 1), an interrupt request is generated. If a terminal count occurs while
IP is already set, an internal error flag is set. As soon as IP is cleared, it is forced to a 1 along
with the Interrupt Error (ERR) flag. Errors that occur after the internal flag is set are ignored.
ERR is cleared to 0 when the corresponding IP is cleared.