HT45B0F
Baud Rate Generator
·
Calculating the baud rate and error values
To setup the speed of the serial data communication,
the UART function contains its own dedicated baud rate
generator. The baud rate is controlled by its own internal
free running 8-bit timer, the period of which is deter-
mined by two factors. The first of these is the value
placed in the baud rate register BRG and the second is
the value of the BRGH bit with the control register
UCR2. The BRGH bit decides if the baud rate generator
is to be used in a high speed mode or low speed mode,
which in turn determines the formula that is used to cal-
culate the baud rate. The value N in the BRG register
which is used in the following baud rate calculation for-
mula determines the division factor. Note that N is the
decimal value placed in the BRG register and has a
range of between 0 and 255.
For a clock frequency of 4MHz, and with BRGH set to
²0² determine the BRG register value N, the actual
baud rate and the error value for a desired baud rate
of 4800.
From the above table the desired baud rate BR =
fCLKI
[64 (N+ 1)]
fCLKI
(BRx64)
Re-arranging this equation gives N =
- 1
4000000
Giving a value for N =
- 1 = 12.0208
(4800x64)
To obtain the closest value, a decimal value of 12 should
be placed into the BRG register. This gives an actual or
4000000
calculated baud rate value of BR=
= 4808
UCR2 BRGH Bit
0
1
[64(12 + 1)]
fCLKI
fCLKI
Baud Rate (BR)
4
8
-
0
4
8
8
0
[64 (N+ 1)]
[16 (N+ 1)]
Therefore the error is equal to
= 0.16%
0
4
8
0
By programming the BRGH bit which allows selection of
the related formula and programming the required value
in the BRG register, the required baud rate can be setup.
Note that because the actual baud rate is determined
using a discrete value, N, placed in the BRG register,
there will be an error associated between the actual and
requested value. The following example shows how the
BRG register value N and the error value can be calcu-
lated.
The following tables show the actual values of baud rate and error values for the two value of BRGH.
Baud Rates for BRGH=0
Baud
Rate
K/BPS
fCLKI=4MHz
fCLKI=3.579545MHz
fCLKI=7.159MHz
Kbaud Error (%)
BRG
207
51
25
12
6
Kbaud Error (%)
BRG Kbaud Error (%)
BRG
¾
92
46
22
11
5
0.3
1.2
0.300
1.202
2.404
4.808
8.929
20.833
¾
0.16
0.16
0.16
0.16
-6.99
8.51
¾
185
46
22
11
5
0.300
1.190
2.432
4.661
9.321
18.643
¾
0.00
-0.83
1.32
-2.90
-2.90
-2.90
¾
¾
¾
1.203
0.23
2.4
2.380
-0.83
1.32
4.8
4.863
9.6
9.322
-2.90
-2.90
-2.90
-2.90
-2.90
19.2
38.4
57.6
115.2
2
2
18.643
32.286
55.930
111.859
2
¾
0
¾
0
62.500
¾
8.51
¾
55.930
¾
1
-2.90
¾
0
¾
¾
Baud Rates and Error Values for BRGH = 0
Rev. 1.10
12
September 24, 2012