XC886/888CLM
Timers
User’s Manual
13-2
V1.3, 2010-02
Timers, V 1.0
13.1
Timer 0 and Timer 1
Timer 0 and Timer 1 can function as both timers or counters. When functioning as a
timer, Timer 0 and Timer 1 are incremented every machine cycle, i.e. every 2 input
clocks (or 2 PCLKs). When functioning as a counter, Timer 0 and Timer 1 are
incremented in response to a 1-to-0 transition (falling edge) at their respective external
input pins, T0 or T1.
13.1.1
Basic Timer Operations
The operations of the two timers are controlled using the Special Function Registers
(SFRs) TCON and TMOD. To enable a timer, i.e., allow the timer to run, its control bit
TCON.TRx is set. To select the timer input to be either from internal system clock or
external pin, the input selector bit TMOD is used.
Note: The “x” (e.g., TCON.TRx
)
in this chapter denotes either 0 or 1.
Each timer consists of two 8-bit registers - TLx (low byte) and THx (high byte) which
defaults to 00
H
on reset. Setting or clearing TCON.TRx does not affect the timer
registers.
Timer Overflow
When a timer overflow occurs, the timer overflow flag, TCON.TFx, is set, and an interrupt
may be raised if the interrupt enable control bit, IEN0.ETx, is set. The overflow flag is
automatically cleared when the interrupt service routine is entered.
When Timer 0 operates in mode 3, the Timer 1 control bits, TR1, TF1 and ET1 are
reserved for TH0, see
External Control
In addition to pure software control, the timers can also be enabled or disabled through
external port control. When external port control is used, SFR EXICON0 must first be
configured to bypass the edge detection circuitry for EXINTx to allow direct feed-through.
When the timer is enabled (TCON.TRx = 1) and TMOD.GATEx is set, the respective
timer will only run if the core external interrupt EXINTx = 1. This facilitates pulse width
measurements. However, this is not applicable for Timer 1 in mode 3.
If TMOD.GATEx is cleared, the timer reverts to pure software control.
*