Page 1 of 1

Crystal frequency incompatible with standard baud settings

PostPosted: Thu Mar 20, 2014 1:47 pm
by philip
I need to use a UART at 115,200 baud. However, the external oscillator on the dsPIC PPM is 8 MHz, so the closest UART setting is 8.0 MHz/64 = 125 kHz. This is enough of a mismatch to cause errors in almost every byte.

The dsPIC has an internal oscillator that's nominally at the correct frequency, 7.3728 MHz, but its accuracy is low. Dividing to get 115.2 kHz resulted in an actual frequency of about 111 kHz, again causing constant errors.

Is there a good way around this problem?

Re: Crystal frequency incompatible with standard baud settin

PostPosted: Fri Mar 21, 2014 11:17 am
by Andrew
Reread the datasheet on the UART and its baud rate generator ... you have full 16-bit resolution on setting baud rates, not only powers-of-2.

Re: Crystal frequency incompatible with standard baud settin

PostPosted: Fri Apr 04, 2014 10:05 am
by philip
From the datasheet, the formula for baud rate in fast mode is (crystal frequency/2)/(4(UxBRG+1)). For the 8 MHz crystal, setting UxBRG to 7 produces 125 kHz, or to 8 produces 111 kHz.

We were able to get communication to work with the internal oscillator, but we would prefer to use the external oscillator for better reliability. Would changing the crystal to 7.3728 MHz cause any problems?

Re: Crystal frequency incompatible with standard baud settin

PostPosted: Fri Apr 04, 2014 2:55 pm
by Andrew
Code: Select all
csk_uart0_open(CSK_UART_115200_N81);
gives you 115200 with a U1BRG of 0x21 for a 32MHz clock, which is what you get when you PLL the 8MHz to 32Mhz.

Net result is 117,600bps, which is plenty close.