beautypg.com

Texas Instruments MSC1210 User Manual

Page 88

background image

Using Timer 2

8-14

TR2 (bit 2)—Timer 1 Run Control. This bit enables/disables the operation of
Timer 2. Halting this timer will preserve the current count in TH2, TL2.

0 = Timer 2 is halted.

1 = Timer 2 is enabled.

C/T (bit 1)—Counter/Timer Select. This bit determines whether Timer 2 will
function as a timer or counter. Independent of this bit, Timer 2 runs at 2 clocks
per tick when used in baud rate generator mode.

0 = Timer 2 functions as a timer. The speed of Timer 2 is determined by the
T2M bit (CKCON.5).

1 = Timer 2 will count negative transitions on the T2 pin (P1.0).

CP/RL2 (bit 0)—Capture/Reload Select. This bit determines whether the
capture or reload function will be used for Timer 2. If either RCLK or TCLK is
set, this bit will not function and the timer will function in an auto-reload mode
following each overflow.

0 = Auto-reloads will occur when Timer 2 overflows or a falling edge is detected
on T2EX if EXEN2 = 1.

1 = Timer 2 captures will occur when a falling edge is detected on T2EX if
EXEN2 = 1.

8.5.2

Timer 2 in Auto-Reload Mode

The first mode in which Timer 2 may be used is auto-reload. The auto-reload
mode functions just like Timer 0 and Timer 1 in auto-reload mode, except that
the Timer 2 auto-reload mode performs a full 16-bit reload (recall that Timer
0 and Timer 1 only have 8-bit reload values). When a reload occurs, the value
of TH2 is reloaded with the value contained in RCAP2H, and the value of TL2
is reloaded with the value contained in RCAP2L.

To operate Timer 2 in auto-reload mode, the CP/RL2 bit (T2CON.0) must be
clear. In this mode, Timer 2 (TH2/TL2) is reloaded with the reload value
(RCAP2H/RCAP2L) whenever Timer 2 overflows; that is to say, whenever
Timer 2 overflows from FFFF

H

back to 0000

H

. An overflow of Timer 2 causes

the TF2 bit to be set, which causes an interrupt to be triggered (if Timer 2 inter-
rupt is enabled). Note that TF2 will not be set on an overflow condition if either
RCLK or TCLK (T2CON.5 or T2CON.4) are set.

Additionally, by also setting EXEN2 (T2CON.3), a reload will also occur when-
ever a 1−0 transition is detected on T2EX (P1.1). A reload that occurs as a re-
sult of such a transition causes the EXF2 (T2CON.6) flag to be set, triggering
a Timer 2 interrupt, if enabled.