nairitb
Junior Member level 1
- Joined
- Mar 25, 2014
- Messages
- 18
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 154
Hello,
First of all, I am new to PIC microcontrollers.
I made a pcb with dsPIC33EP512MU810 as the microcontroller. I have written a code to turn on a LED connected to PortF.0. For that, I first select the internal FRC and then switch to primary oscillator with PLL. But when debugging, I found that it gets stuck in "while(OSCCONbits.COSC!= 0x03);"
Can you please check where have I made mistake? I have attached a debug screenshot showing the values of OSCCON, PLLFBD & CLKDIV registers.
First of all, I am new to PIC microcontrollers.
I made a pcb with dsPIC33EP512MU810 as the microcontroller. I have written a code to turn on a LED connected to PortF.0. For that, I first select the internal FRC and then switch to primary oscillator with PLL. But when debugging, I found that it gets stuck in "while(OSCCONbits.COSC!= 0x03);"
Can you please check where have I made mistake? I have attached a debug screenshot showing the values of OSCCON, PLLFBD & CLKDIV registers.
Code:
// Crytal is 24MHz.
// Configure the oscillator to operate the device at 51 MIPS using PLL
#include <stdio.h>
#include <stdlib.h>
#include <p33EP512MU810.h>
#include "clockSwitch.h"
// DSPIC33EP512MU810 Configuration Bit Settings
#include <xc.h>
// Select Internal FRC at POR
_FOSCSEL(FNOSC_FRC & IESO_OFF);
// Enable Clock Switching and Configure Primary Oscillator in HS mode
_FOSC(FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMD_HS);
_FWDT(FWDTEN_OFF); // Watchdog Timer Enabled/disabled by user software
#pragma config ICS = PGD3 // ICD Communication Channel Select bits (Communicate on PGEC3 and PGED3)
int main()
{
// Disable Watch Dog Timer
RCONbits.SWDTEN=0;
// Configure PLL prescaler, PLL postscaler, PLL divisor
PLLFBD= 32; // M=34
CLKDIVbits.PLLPOST= 0; // N2=2
CLKDIVbits.PLLPRE= 4; // N1=6
CLKDIVbits.DOZE= 0;
// Initiate Clock Switch to Primary Oscillator with PLL (NOSC=0b011)
//OSCCON=0x301; //Oscillator Control Register
__builtin_write_OSCCONH(0x03);
__builtin_write_OSCCONL(OSCCON | 0x01);
// Wait for Clock switch to occur
while (OSCCONbits.COSC!= 3);
// Wait for PLL to lock
while (OSCCONbits.LOCK!= 1);
TRISF=0;
while(1)
{
PORTF = 0x01;
}
}