herunterladen

2004 Microchip Technology Inc. DS00962A-page 1
AN962
INTRODUCTION
All current dsPIC30F devices have a UART peripheral
with Auto Baud capability. The signal on the UART
receive pin (RX pin) can be internally routed to an Input
Capture module to time the edges of the incoming
signal. From that timing the software can set up the
UART at the correct baud rate.
Auto Baud is useful when the baud rate of the incoming
data is unknown and when the oscillator frequency of
the processor is unknown. RC oscillators are often
inaccurate and drift over time so systems with RC
oscillators are ideal candidates for using Auto Baud.
METHOD
The method for doing Auto Baud relies on known data
being received. It is usually possible to use a
communications protocol that sends data specifically
for Auto Baud. The timing of the received data can be
used to calculate the value for the U1BRG or U2BRG
registers that set the UART baud rates.
The two examples in this application note use incoming
data of 0x55 (ASCII ‘U’) to calculate the baud rate
generator value. This particular data byte provides the
maximum number of edges and therefore the greatest
accuracy. Any data byte can be used and the
calculations adapted to suit the data. In general, the
more edges (bit state changes) in the data, the more
accurate the result.
Signals
UART signals are sent least significant bit first,
preceded by a start bit (zero) and followed by a stop bit
(one). There are usually eight bits of data, but other
sizes are possible, and a parity bit can follow the data.
All of this will impact the Auto Baud calculation, but the
data should always be known in advance.
There will always be at least two edges because of the
start and stop bits, but there could be ten or more. In
our example of 0x55 there are ten edges, as shown in
Figure 1.
FIGURE 1: UART SIGNAL FOR 0x55
Timing And Sampling
Equation 1 can be used to calculate the value for
UxBRG after recording the times of the edges and
removing the offset of t
0
. This equation is derived in
Appendix A using linear regression. The calculation is
performed after the last edge has been recorded and
should be completed before the start bit of the next byte
to ensure that no data is lost. This sets a time limit for
the calculation that should be checked. In some cases
it will be necessary to use a less complex calculation
that can be performed more quickly. Similarly, the time
taken for error checking must also be considered.
EQUATION 1: UxBRG LINEAR REGRESSION CALCULATION
Author: Mike Garbutt
Microchip Technology
Start
t
0
= 0 t
1
t
2
t
3
t
4
t
5
t
6
t
7
t
8
t
9
Stop
D0 D1 D2 D3 D4 D5 D6 D7
UxBRG
2 t
1
2t
2
3t
3
… 9t
9
++++()9 t
1
t
2
t
3
… t
9
+++ +()–
2640
---------------------------------------------------------------------------------------------------------------------------------
1–=
Implementing Auto Baud on dsPIC30F Devices