• AVR Freaks

AnsweredPIC24FJ Baud Rate Issues / Crystal Selection

Author
tass2001
New Member
  • Total Posts : 8
  • Reward points : 0
  • Joined: 2018/11/08 15:12:19
  • Location: 0
  • Status: offline
2019/06/19 08:52:37 (permalink)
0

PIC24FJ Baud Rate Issues / Crystal Selection

All,
 
I'm using a PIC24FJ1024GA606 and I'm using the internal Fast RC Oscillator. Here is my config:
// FOSCSEL
#pragma config FNOSC = FRCPLL // Oscillator Source Selection (FRC with PLL module)
#pragma config PLLMODE = PLL96DIV2 // PLL Mode Selection (96 MHz PLL. (8 MHz input))
#pragma config IESO = OFF // Two-speed Oscillator Start-up Enable bit (Start up with user-selected oscillator source)

// FOSC
#pragma config POSCMD = NONE // Primary Oscillator Mode Select bits (None)
#pragma config OSCIOFCN = OFF // OSC2 Pin Function bit (OSC2 is clock output)
#pragma config SOSCSEL = OFF // SOSC Power Selection Configuration bits (SOSC is not used)
#pragma config PLLSS = PLL_FRC // PLL Secondary Selection Configuration bit (PLL is fed by the FRC)
#pragma config IOL1WAY = ON // Peripheral pin select configuration bit (Allow many reconfigurations)
#pragma config FCKSM = CSDCMD // Clock Switching Mode bits (Both Clock switching and Fail-safe Clock Monitor are disabled)

 
The issue I'm running into is that 115200 baud UART has a high error rate when sending data sequentially (my bootloader flashes firmware via UART at 115200 baud).
 
From what I've read, the Internal Oscillator isn't really up to the task when it comes to low error rates for high speed UART and I need to use an external crystal. It should be noted that if I set the baud rate to 111000, where my BRG (currently 8) has a low deviation from the baud rate, everything works fine and there are no errors.
 
 
My questions are:
First of all, is this diagnosis of my problem correct?
If yes, what kind of oscillator should I use so that I can effectively use 115200 baud?
 
If it matters: I'm also using a timer with a 1ms interrupt rate and another timer with a 1us interrupt rate. My FCY is 16,000,000.
 
-Ted
#1
mbrowning
Just a Member
  • Total Posts : 1424
  • Reward points : 0
  • Joined: 2005/03/16 14:32:56
  • Location: Melbourne, FL
  • Status: online
Re: PIC24FJ Baud Rate Issues / Crystal Selection 2019/06/19 09:06:51 (permalink) ☼ Best Answerby tass2001 2019/06/19 09:17:41
5 (1)
Your diagnosis is incorrect. The oscillator has a max 2% error which is more than good enough for UART.
Your UART setup is poor. Use BRGH = 1, then baud = Fcy / (4*(BRG+1))
Thus with BRG = 34 you get 114,286 baud   ( 16MHz / 4(34+1)  ) which is 0.8% low
 
Worst case 2.8% will give you no problems.

Oh well - there's always next year
#2
tass2001
New Member
  • Total Posts : 8
  • Reward points : 0
  • Joined: 2018/11/08 15:12:19
  • Location: 0
  • Status: offline
Re: PIC24FJ Baud Rate Issues / Crystal Selection 2019/06/19 09:18:13 (permalink)
0
@mbrowning,
 
Perfect -- Somehow I had glossed over the BRGH parameter in the datasheet. Thanks so much!
#3
Jump to:
© 2019 APG vNext Commercial Version 4.5