Author Topic: dsPIC Oscillator PLL  (Read 8099 times)

0 Members and 1 Guest are viewing this topic.

Offline arixroboticsTopic starter

  • Full Member
  • ***
  • Posts: 119
  • Helpful? 3
    • TalasTronics WCIT KL2008 Fund Raising
dsPIC Oscillator PLL
« on: July 20, 2009, 06:27:03 AM »
Hi all,

I've just bought the 28-pins Development Board from Microchip. I'm using it with dsPIC33FJ128MC802.

I've tried running the demo program that came with it (resend characters received through UART with quotation marks) and it worked perfect at first.

I then used an existing code I got, did a few more runs and then something went wrong.

I tried to run the demo program again, but it no longer worked. It seems that the pic was stuck at PLL locking here:


Code: [Select]
// Wait for PLL to lock
while(OSCCONbits.LOCK!=1) {};


Somehow OSCCONbits.LOCK!=1 is always true now. When I try to comment out this line, the LEDs doesn't flash at the rate it should have. And UART doesn't work anymore.

Can someone tell me what's going on? I've tried changing chips but the same problem is there. Could it be the power supply? I'm using a 12VDC plugpack.

Help please..

Offline jka

  • Full Member
  • ***
  • Posts: 78
  • Helpful? 4
Re: dsPIC Oscillator PLL
« Reply #1 on: July 23, 2009, 01:14:56 AM »
OSCCONbits.LOCK is used for setting up the oscillator. What are you doing before the while() loop? I have used thiscode with success:

   PLLFBD=22;
   _PLLPRE=1;

   _PLLPOST=0;

   __builtin_write_OSCCONH(0x03);

   __builtin_write_OSCCONL(0x01);

   

   while(OSCCONbits.COSC != 0x03);

   while(OSCCONbits.LOCK != 0x01);

Offline arixroboticsTopic starter

  • Full Member
  • ***
  • Posts: 119
  • Helpful? 3
    • TalasTronics WCIT KL2008 Fund Raising
Re: dsPIC Oscillator PLL
« Reply #2 on: July 23, 2009, 08:46:51 PM »
It was the demo code from Microchip.

Code: [Select]
int main(void)
{

// Configure Oscillator to operate the device at 40Mhz
// Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
// Fosc= 7.37*43/(2*2)=79.23MHz
PLLFBD=41; // M=43
CLKDIVbits.PLLPOST=0; // N1=2
CLKDIVbits.PLLPRE=0; // N2=2

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

// Wait for PLL to lock
while(OSCCONbits.LOCK!=1) {};

Somehow after I restart the computer, it worked again. And then after some time and some more programming, it gets stuck at this loop again. I'm pretty sure its the oscillator going crazy.

Since it worked everytime after I restart the computer, I guess it must have been the computer not programming the chip correctly :-\