Pumpkin, Inc.

Pumpkin User Forums

Crystal frequency incompatible with standard baud settings

For issues specific to the PIC24 MCU and dsPIC DSC line of microcontrollers from Microchip, including compiler (e.g. MCC 30) and IDE (e.g. MPLAB) issues.

Crystal frequency incompatible with standard baud settings

Postby philip » Thu Mar 20, 2014 1:47 pm

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?
philip
 
Posts: 3
Joined: Tue Sep 13, 2011 11:49 am

Re: Crystal frequency incompatible with standard baud settin

Postby Andrew » Fri Mar 21, 2014 11:17 am

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.
Andrew
Site Admin
 
Posts: 68
Joined: Mon Nov 30, 2009 6:43 pm

Re: Crystal frequency incompatible with standard baud settin

Postby philip » Fri Apr 04, 2014 10:05 am

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?
philip
 
Posts: 3
Joined: Tue Sep 13, 2011 11:49 am

Re: Crystal frequency incompatible with standard baud settin

Postby Andrew » Fri Apr 04, 2014 2:55 pm

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.
Andrew
Site Admin
 
Posts: 68
Joined: Mon Nov 30, 2009 6:43 pm


Return to PIC24 & dsPIC

Who is online

Users browsing this forum: No registered users and 1 guest

cron