Incorrectly calculating UART Baud Rate
Posted: Thu Apr 18, 2019 4:09 pm
MCU: PIC18F67K22-I/PT
FREQ: 64 MHz
It appears that Flowcode V7 is incorrectly calculating the UART (EUSART) Baud Rate when I compile code with a baud rate lower than 4 kHz.
I believe that the issue might stem from a possible Flowcode miscalculation of the 'SPBRGH2' register.
Here's the Microchip baud calculation...
Solving for SPBRGHx:SPBRGx:
X = ((FOSC/Desired Baud Rate)/64) – 1
= ((64000000/4000)/64) – 1
= 249
249 fits easily into the SPBRG2 register (with SPBRGH2 register set to 0)
If I use a baud rate lower than 4 kHz, I get random baud rates (measured by my o-scope).
For example...
Solving for SPBRGHx:SPBRGx:
X = ((FOSC/Desired Baud Rate)/64) – 1
= ((64000000/2400)/64) – 1
= 416
I'm assuming that rollover of 'SPBRG2' is occurring, and 'SPBRGH2' is not being updated within Flowcode.
I get a host of random (higher) baud rates if I choose anything lower than 4 kHz. Here are some examples of rates I captured with my o-scope:
Flowcode: O-Scope:
240 Hz = 14.0 KHz
600 Hz = 7.62 KHz
700 Hz = 6.72 KHz
800 Hz = 4.42 KHz
900 Hz = 11.5 KHz
1000 Hz = 4.31 KHz
1500 Hz = 6.49 KHz
2000 Hz = 4.10 KHz
2360 Hz = 5.95 KHz
2400 Hz = 6.22 KHz
2600 Hz = 7.81 KHz
3000 Hz = 12.8 KHz
3500 Hz = 33.3 KHz
4000 Hz = 4.00 KHz
4800 Hz = 4.79 KHz
240000 Hz = 236. KHz
FREQ: 64 MHz
It appears that Flowcode V7 is incorrectly calculating the UART (EUSART) Baud Rate when I compile code with a baud rate lower than 4 kHz.
I believe that the issue might stem from a possible Flowcode miscalculation of the 'SPBRGH2' register.
Here's the Microchip baud calculation...
Solving for SPBRGHx:SPBRGx:
X = ((FOSC/Desired Baud Rate)/64) – 1
= ((64000000/4000)/64) – 1
= 249
249 fits easily into the SPBRG2 register (with SPBRGH2 register set to 0)
If I use a baud rate lower than 4 kHz, I get random baud rates (measured by my o-scope).
For example...
Solving for SPBRGHx:SPBRGx:
X = ((FOSC/Desired Baud Rate)/64) – 1
= ((64000000/2400)/64) – 1
= 416
I'm assuming that rollover of 'SPBRG2' is occurring, and 'SPBRGH2' is not being updated within Flowcode.
I get a host of random (higher) baud rates if I choose anything lower than 4 kHz. Here are some examples of rates I captured with my o-scope:
Flowcode: O-Scope:
240 Hz = 14.0 KHz
600 Hz = 7.62 KHz
700 Hz = 6.72 KHz
800 Hz = 4.42 KHz
900 Hz = 11.5 KHz
1000 Hz = 4.31 KHz
1500 Hz = 6.49 KHz
2000 Hz = 4.10 KHz
2360 Hz = 5.95 KHz
2400 Hz = 6.22 KHz
2600 Hz = 7.81 KHz
3000 Hz = 12.8 KHz
3500 Hz = 33.3 KHz
4000 Hz = 4.00 KHz
4800 Hz = 4.79 KHz
240000 Hz = 236. KHz