PIC16F913/914/916/917/946
EXAMPLE 9-1:
CALCULATING BAUD
RATE ERROR
9.2
AUSART Baud Rate Generator
(BRG)
For a device with FOSC of 16 MHz, desired baud rate
of 9600, Asynchronous mode:
The Baud Rate Generator (BRG) is an 8-bit timer that
is dedicated to the support of both the asynchronous
and synchronous AUSART operation.
FOSC
Desired Baud Rate = ---------------------------------------
64(SPBRG + 1)
The SPBRG register determines the period of the free
running baud rate timer. In Asynchronous mode the
multiplier of the baud rate period is determined by the
BRGH bit of the TXSTA register. In Synchronous mode,
the BRGH bit is ignored.
Solving for SPBRG:
FOSC
---------------------------------------------
Desired Baud Rate
X = --------------------------------------------- – 1
64
Table 9-3 contains the formulas for determining the
baud rate. Example 9-1 provides a sample calculation
for determining the baud rate and baud rate error.
16000000
-----------------------
9600
= ----------------------- – 1
64
Typical baud rates and error values for various
asynchronous modes have been computed for your
convenience and are shown in Table 9-3. It may be
advantageous to use the high baud rate (BRGH = 1), to
reduce the baud rate error.
= [25.042] = 25
16000000
Calculated Baud Rate = --------------------------
64(25 + 1)
= 9615
Writing a new value to the SPBRG register causes the
BRG timer to be reset (or cleared). This ensures that
the BRG does not wait for a timer overflow before out-
putting the new baud rate.
Calc. Baud Rate – Desired Baud Rate
Error = --------------------------------------------------------------------------------------------
Desired Baud Rate
(9615 – 9600)
= ---------------------------------- = 0 . 1 6 %
9600
TABLE 9-3:
BAUD RATE FORMULAS
Configuration Bits
Baud Rate Formula
AUSART Mode
SYNC
BRGH
0
0
1
0
1
x
Asynchronous
Asynchronous
Synchronous
FOSC/[64 (n+1)]
FOSC/[16 (n+1)]
FOSC/[4 (n+1)]
Legend:
x= Don’t care, n = value of SPBRG register
TABLE 9-4:
REGISTERS ASSOCIATED WITH THE BAUD RATE GENERATOR
Value on
all other
Resets
Value on
POR, BOR
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
RCSTA
SPBRG
TXSTA
SPEN
BRG7
CSRC
RX9
BRG6
TX9
SREN
BRG5
TXEN
CREN
BRG4
SYNC
ADDEN
BRG3
—
FERR
BRG2
BRGH
OERR
BRG1
TRMT
RX9D
BRG0
TX9D
0000 000x 0000 000x
0000 0000 0000 0000
0000 -010 0000 -010
Legend:
x= unknown, -= unimplemented read as ‘0’. Shaded cells are not used for the Baud Rate Generator.
DS41250F-page 132
© 2007 Microchip Technology Inc.