Information

2009-2013 Microchip Technology Inc. DS80000485L-page 11
PIC16(L)F1826/1827
EXAMPLE 3: METHOD 2 – EUSART AUTO-BAUD DETECT WORK AROUND
Affected Silicon Revisions
Similar to Method 1, define default, minimum and maximum auto-baud (SPBRG) values. In firmware, compute a running average of
SPBRG. If the new SPBRG value falls outside the minimum or maximum limits, then use the current running average value
(Average_Baud), otherwise use the auto-baud SPBRG value and calculate a new running average.
For example, if the application runs at 9600 baud at 16 MHz then, the default SPBRG value would be (assuming 16-bit/
Asynchronous mode) 0x67. The minimum and maximum allowed values can be calculated based on the application. In this
example, a +/-5% tolerance is required, so tolerance is 0x67 * 5% = 0x05.
#define SPBRG_16BIT *((*int)&SPBRG; // define location for 16-bit SPBRG value
const int DEFAULT_BAUD = 0x0067; // Default Auto-Baud value
const int TOL = 0x05; // Baud Rate % tolerance
const int MIN_BAUD = DEFAULT_BAUD - TOL; // Minimum Auto-Baud Limit
const int MAX_BAUD = DEFAULT_BAUD + TOL; // Maximum Auto-Baud Limit
int Average_Baud; // Define Average_Baud variable
int Integrator; // Define Integrator variable
Average_Baud = DEFAULT_BAUD; // Set initial average Baud rate
Integrator = DEFAULT_BAUD*15; // The running 16 count average
ABDEN = 1; // Start Auto-Baud
while (ABDEN); // Wait until Auto-Baud completes
Integrator+ = SPBRG_16BIT;
Average_Baud = Integrator/16;
if((SPBRG_16BIT > MAX_BAUD)||(SPBRG_16BIT < MIN_BAUD))
{ // Check if value is within limits
SPBRG_16BIT = Average_Baud; // If out of spec, use previous average
}
else // If in spec, calculate the running
{ // average but continue using the
Integrator+ = SPBRG_16BIT; // Auto-Baud value in SPBRG
Average_Baud = Integrator/16;
Integrator- = Average_Baud;
}
A2 A3 A4 A5 A6
XXXX