Page 1 of 1

dsPIC33 PLL

Posted: Fri Jul 31, 2026 9:03 am
by jay_dee
Hi Guys,
Maybe someone with more dsPIC experiance can help, i'm new to poking around at this level. :)

I have a dsPIC33EV with an external 8MHz XTAL I wish to run this at 80Mhz. I'm using FC to set most of my registers, via build options.
Then the first line on my FC is C Code.

Code: Select all

CLKDIVbits.PLLPRE = 0;  // N1 (0=Divide by 2) 
PLLFBDbits.PLLDIV = 40;  //M  Multiply F Xtal 
CLKDIVbits.PLLPOST = 0; //N2 (0= Divide by 2)
(F XTAL * M ) / (2x2) = (8 * 40)/4 = 80
A) is it OK to change the PLL setting at this point? i.e. within flowcode main.

I test this by outputting a 10mS pulse and measuring with a scope.

B) Can I change an the PIC's FCD to allow me to select 80MHz in project options? Since I only get 40, 48, 64 options and so my FC delays are out.
Using a FC clock speed of 40, I get what looks like a sensible halved value. so I must be close.

C)
However I can't get my UART to output a stable 115200 serial stream.
Do other users find they have to tune the oscillator to get a PLL clock close to 80MHz ? or are the base settings generally OK.

I would like to stay at 80MHz (unless there is a good reason not too), since I'll be using CAN and it should be easier to calculate my TQ settings if the FOsc is simply 4x faster than the std settings.
Thanks, J.

Re: dsPIC33 PLL

Posted: Fri Jul 31, 2026 12:33 pm
by BenR
Hello,

Here is how we do a similar clock speed switch on our dsPIC devices, hopefully helps to show the way.

Code: Select all

//Setup configuration for 70MIPs using 7.37MHz internal osc
PLLFBD = 68;// M=70
CLKDIVbits.PLLPOST = 0;// N1=2
CLKDIVbits.PLLPRE = 0;// N2=2
OSCTUN = 23;//Tune FRC oscillator from 7.37Mhz to 8.00566MHz

//Disable Watch Dog Timer
RCONbits.SWDTEN = 0;

// Clock switching to incorporate PLL
__builtin_write_OSCCONH(0x01);// Initiate Clock Switch to FRC with PLL

// Oscillator with PLL (NOSC=0b011)
__builtin_write_OSCCONL(0x01);// Start clock switching
while(OSCCONbits.COSC != 0b001);

// Wait for Clock switch to occur
while(OSCCONbits.LOCK != 1);
You should be able to type 80 into the project options clock speed assuming the chip can run that fast. I think they can go up to 140MHz.