VRS51L1050
Generating UART Baud Rates with Timer 2
UART Baud Rates
Timer 2 is often preferred to generate the baud rate, as
it can be easily configured to operate as a 16-bit timer
with auto-reload. This allows for better resolution
compared to using Timer 1 in 8-bit auto-reload mode.
In Mode 0, the baud rate is fixed and can be
represented by the following formula:
Mode 0 Baud Rate = Oscillator Frequency
12
The baud rate using Timer 2 is defined as:
In Mode 2, the baud rate depends on the value of the
SMOD bit in the PCON SFR. The formula below
demonstrates that if SMOD = 0 (which is the value on
reset), the baud rate is 1/32 the oscillator frequency.
Mode 1,3 Baud Rate = Timer 2 Overflow Rate
16
The timer can be configured as either a timer or a
counter in any of its three running modes. In typical
applications, it is configured as a timer (C/T2 is set to
0).
Mode 2 Baud Rate = 2SMOD x (Oscillator Frequency)
64
To operate Timer 2 as a baud rate generator, the
TCLK and RCLK bits of the T2CON register must be
set to 1. Baud rate generator mode is similar to auto-
reload mode in that an overflow in TH2 causes the
Timer 2 registers to be reloaded with the 16-bit value
in registers RCAP2H and RCAP2L, which are preset
by the software. However, when Timer 2 is configured
as a baud rate generator, its clock source is Osc/2.
The Timer 1 and/or Timer 2 overflow rate determines
the baud rates in modes 1 and 3.
Generating UART Baud Rate with Timer 1
When Timer 1 functions as a baud rate generator, the
baud rate in modes 1 and 3 are determined by the
Timer 1 overflow rate.
The following formula can be used to calculate the
baud rate in modes 1 and 3 using Timer 2:
Modes 1, 3 Baud Rate = 2SMODx Timer 1 Overflow Rate
32
Modes 1, 3 Baud Rate =
Oscillator Frequency
32x[65536 – (RCAP2H, RCAP2L)]
Timer 1 must be configured as an 8-bit timer (TL1) with
auto-reload with an TH1 value when an overflow
occurs (Mode 2). In this application, the Timer 1
interrupt should be disabled.
The formula below is used to define the reload value to
put into the RCAP2h, RCAP2L registers to achieve a
given baud rate.
The following formulas can be used to calculate the
baud rate and the reload value to be written into the
TH1 register.
(RCAP2H, RCAP2L) =
65536 - Fosc
32x[Baud Rate]
Modes 1, 3 Baud Rate =
2SMOD x Fosc
32 x 12(256 – TH1)
In the above formula, RCAP2H and RCAP2L are the
content of RCAP2H and RCAP2L, taken as a 16-bit
unsigned integer.
The value to be written into the TH1 register is defined
by the following formula:
Note that a rollover in TH2 does not set TF2, and will
not generate an interrupt. Because of this, Timer 2
interrupt does not have to be disabled when Timer 2 is
configured in baud rate generator mode.
TH1 =
256 - 2SMODx Fosc
32 x 12x (Baud Rate)
Furthermore, when Timer 2 is configured as a UART
baud rate generator and running (TR2 is set to 1), the
user should not try to perform read or write operations
to the TH2 or TL2 and RCAP2H, RCAP2L registers.
______________________________________________________________________________________________
www.ramtron.com page 25 of 49