Hello,
Can someone please help me with this code. I'm trying to get the dsPIC33FJ256GP710 (Explore 16) to run at 40Mhz. This is part of the code I've found but it gets stuck at the line "while (OSCCONbits.COSC != 0b011); // Wait for Clock switch to occur". ie it's not switching. It did give me a warning saying something about cycling power before starting, but me no comprendo.
_FOSCSEL(FNOSC_FRC); // FRC Oscillator
_FOSC(FCKSM_CSECMD & OSCIOFNC_OFF & POSCMD_NONE);
_FWDT(FWDTEN_OFF); // Watchdog Timer Enabled/disabled by user software
int main(void)
{
/* Configure Oscillator to operate the device at 40Mhz */
// Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
// Fosc= 7.37M*43(2*2)=80Mhz for 7.37M input clock
PLLFBD=41; // M=43
CLKDIVbits.PLLPOST=0; // N1=2
CLKDIVbits.PLLPRE=0; // N2=2
OSCTUN=0; // Tune FRC oscillator, if FRC is used
// Disable Watch Dog Timer
RCONbits.SWDTEN=0;
// Clock switching to incorporate PLL
__builtin_write_OSCCONH(0x03); // Initiate Clock Switch to Primary
// Oscillator with PLL (NOSC=0b011)
__builtin_write_OSCCONL(0x01); // Start clock switching
while (OSCCONbits.COSC != 0b011); // Wait for Clock switch to occur
// Wait for PLL to lock
while(OSCCONbits.LOCK!=1) {};