English
Language : 

SM59D03G2 Datasheet, PDF (38/67 Pages) SyncMOS Technologies,Inc – 8-Bits Micro-controller
10.4 Using Timer 2 to Generate Baud Rates.
SM59D03G2
8-Bits Micro-controller
8KB+ ISP Flash & 1KB RAM embedded
In the SM59D03G2, Timer 2 is selected as the baud rate generator by setting TCLK and/or RCLK in
T2CON. Note then the baud rates for transmit and receive can be simultaneously different. Setting
RCLK and/or TCLK puts Timer 2 into its baud rate generator mode.
The baud rate generator mode is similar to the auto-reload mode, in that a rollover in TH2 causes
the Timer 2 registers to be reloaded with the 16-bit value in registers RCAP2H and RCAP2L, which
are preset by software.
Now, the baud rates in Modes1 and 3 are determined by Timer 2’s overflow rate as follows:
Modes 1, 3
Baud Rate = Timer 2 overflow rate
16
The timer can be configured for either “timer” or “counter” operation. In the most typical applications,
it is configured for “timer” operation (C/T2 = 0). “Timer” operation is a little different for Timer 2 when
it’s being used as a baud rate generator. Normally, as a timer, it would increment every machine
cycle (thus at 12 oscillator cycles in 12T, or 6 cycles in 6T). As a baud rate generator however, it
increments in every system frequency. In that case, the baud rate is given by the formula
Modes 1, 3
Baud Rate =
System Frequency
16 ×[65536 - (RCAP2H, RCAP2L)]
Where (RCAP2H, RCAP2L) is the content of RCAP2H and RCAP2L taken as a 16-bit unsigned
integer.
Timer 2 as a baud rate generator is shown in Figure 10-1. This Figure is valid only if RCLK + TCLK
= 1 in T2CON. Note that a rollover in TH2 does not set TF2, and will not generate an interrupt.
Therefore, a Timer 2 interrupt does not have to be disabled when Timer 2 is in the baud rate
generator mode. Please also note that if EXEN2 is set, a 1-to-0 transition in T2EX will set EXF2 but
will not cause a reload from (RCAP2H, RCAP2L) to (TH2, TL2). Thus when Timer 2 is in use as a
baud rate generator, T2EX can be used as an extra external interrupt, if desired.
We should keep mind that when Timer 2 is running (TR2 = 1) in “timer” function in the baud rate
generator mode, one should not try to read or write TH2 or TL2. Under these conditions the timer is
being incremented every state time, and the results of a read or write may not be accurate. The
RCAP registers may be read, but shouldn’t be written to, because a write might overlap a reload
and cause write and/or reload errors. In this case, turn the timer off (clear TR2) before accessing
the Timer 2 or RCAP registers.
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFD-M030
38
Ver.C SM59D03G2 07/2009