10-5
TIMER/COUNTER UNIT
10.2 TCU OPERATION
Each counter can operate in any one of six operating modes. These modes are described in sec-
tions 10.2.1 through 10.2.6. In all modes, the counters decrement on the falling edge of CLKINn.
In modes 0, 1, 4, and 5, the counters roll over to the highest count, either 0FFFFH for binary
counting or 9999 for BCD counting, and continue counting down. However, the state of the
OUTn is only affected by the first run through the counter and does not change on subsequent
runs. Modes 2 and 3 are periodic modes; in these modes, when the counter reaches terminal count
it is reloaded with the currently programmed count value.
To specify a counter’s operating mode, write to the TMRCON register’s control word format.
Writing to this register initiates counting. To specify a count, write to the counter’s TMRn regis-
ter’s write format. In modes 0 and 4, the count is loaded on the falling edge of CLKINn. Modes
1 and 5 require a rising edge on a counter’s GATEn signal (or gate-trigger) to load the count. In
modes 2 and 3, the count is loaded when the counter reaches terminal count or when the counter
receives a gate-trigger, whichever is first.
The GATEn signal affects the counting operation for each mode differently (Table 10-3). For
modes 0, 2, 3, and 4, GATEn is level sensitive, and the logic level is sampled on the rising edge
of CLKINn. The action then occurs on the falling edge of the next CLKINn. In these modes,
GATEn must be high for counting to begin. During a counting sequence, a low level at GATEn
suspends counting, while a high level at GATEn resumes counting.
For modes 1, 2, 3, and 5, GATEn is rising-edge sensitive. In these modes, a rising edge at GATEn
sets an edge-sensitive flip-flop in the counter. This flip-flop is then sampled on the next rising
edge of CLKINn; the flip-flop is reset immediately after it is sampled. In this way, a trigger is
detected no matter when it occurs - a high level does not have to be maintained until the next ris-
ing edge of CLKINn. Therefore, a rising edge on GATEn that occurs between two rising CLKINn
edges is recognized as a gate-trigger. The operation caused by a gate-trigger occurs on the falling
CLKINn edge following the trigger. Note that in modes 2 and 3, the GATEn input is both edge-
and level-sensitive. In modes 1, 2, 3, and 5, a gate-trigger causes the counter to load new count
values.