dspic33fj128mc506 and PLL

General discussion on mikroC for dsPIC30/33 and PIC24.
Post Reply
Author
Message
marcos_utfpr
Posts: 21
Joined: 05 Aug 2010 17:35
Location: Curitiba, Brazil

dspic33fj128mc506 and PLL

#1 Post by marcos_utfpr » 27 Jul 2011 16:06

Hi...
I have a problem, I wanna run my dspic at 80MHZ(40 MIPS) so I set it like this picture:
Image

I'm using a 8Mhz crystal and I think there's nothing to do anymore, so my code is here:

Code: Select all

void main() 
{
  setup();
  
  TRISB.F6 = 0;

  while(1)
  {
    PORTB.F6 = 1;
    
    PORTB.F6 = 0;
  }
}


It should give me a signal with 10MHz of frequency(Because I think there are 4 intructions there), but It gives me a signal with 6.25MHz, when I run it with a 10MHz crystal It gives me a signal with 7.82MHz and It can't start up, I need to start It up with 8MHz and then to change for a 10MHz. I don't know why this happend because It should start up with internal oscillator as I set.

Could Somebody help me?

Thank you!
Attachments
Set.JPG
Set.JPG (69.41 KiB) Viewed 3991 times

marcos_utfpr
Posts: 21
Joined: 05 Aug 2010 17:35
Location: Curitiba, Brazil

Re: dspic33fj128mc506 and PLL

#2 Post by marcos_utfpr » 28 Jul 2011 15:35

hi guys...
The code for clock switching from datasheet:
A recommended code sequence for a clock switch includes the following actions:
1. Disable interrupts during the OSCCON register unlock-and-write sequence.
2. Execute the unlock sequence for the OSCCON high byte. In 2 back-to-back instructions:
• write 0x78 to OSCCON<15:8>
• write 0x9A to OSCCON<15:8>
3. In the instruction immediately following the unlock sequence, write the new oscillator
source to the NOSC<2:0> Control bits (OSCCON<10:8>).
4. Execute the unlock sequence for the OSCCON low byte. In 2 back-to-back instructions:
• write 0x46 to OSCCON<7:0>
• write 0x57 to OSCCON<7:0>
5. In the instruction immediately following the unlock sequence, set the OSWEN bit
(OSCCON<0>).
6. Continue to execute code that is not clock-sensitive (optional).
7. Check to see if the OSWEN bit (OSCCON<0>) is ‘0’. If it is, the switch was successful.

ok, so I made that in the setup function:

Code: Select all

void setup()
{
   /*
   01111000b = 78h
   10011010b = 9Ah
   01000110b = 46h
   01010111b = 57h
   */
   
   //Set OSCCONH as 78h
   /////////////////////
   OSCCONbits.NOSC0 = 0;
   OSCCONbits.NOSC1 = 0;
   OSCCONbits.NOSC2 = 0;

   OSCCONbits.COSC0 = 1;
   OSCCONbits.COSC1 = 1;
   OSCCONbits.COSC2 = 1;
   /////////////////////

   //Set OSCCONH as 9Ah
   /////////////////////
   OSCCONbits.NOSC0 = 0;
   OSCCONbits.NOSC1 = 1;
   OSCCONbits.NOSC2 = 0;

   OSCCONbits.COSC0 = 1;
   OSCCONbits.COSC1 = 0;
   OSCCONbits.COSC2 = 0;
   /////////////////////

   //Set the new NOSC value, PLL
   OSCCONbits.NOSC0 = 1;
   OSCCONbits.NOSC1 = 1;
   OSCCONbits.NOSC1 = 0;
   
   //Set OSCCONL as 46h
   /////////////////////
   OSCCONbits.OSWEN = 0;
   OSCCONbits.LPOSCEN = 1;
   OSCCONbits.CF = 0;
   OSCCONbits.LOCK = 0;
   OSCCONbits.CLKLOCK = 0;
   /////////////////////

   //Set OSCCONL as 57h
   /////////////////////
   OSCCONbits.OSWEN = 1;
   OSCCONbits.LPOSCEN = 1;
   OSCCONbits.CF = 0;
   OSCCONbits.LOCK = 0;
   OSCCONbits.CLKLOCK = 0;
   /////////////////////

   OSCCONbits.OSWEN = 1;
   
   while(OSCCONbits.OSWEN == 1)
   {}

}


void main() 
{
  setup();
  
  TRISB.F6 = 0;

  while(1)
  {
    PORTB.F6 = 1;
    
    PORTB.F6 = 0;
  }
}
In the edit project I set Oscilator mode as (XT, HS, EC), Primary Osclillator source as HS and clock switching is enable.

I also tried this:

Code: Select all

void setup()
{
   OSCCON = 0x78;
   OSCCON = 0x9A;
   
   //Set the new NOSC value, PLL
   OSCCONbits.NOSC0 = 1;
   OSCCONbits.NOSC1 = 1;
   OSCCONbits.NOSC1 = 0;

   OSCCONL = 0x46;
   OSCCONL = 0x57;
   
   OSCCONbits.OSWEN = 1;

   while(OSCCONbits.OSWEN == 1)
   {}

}


But I continue to get a signal from PORTB.F6 with 1Mhz.
*I'm using 8MHz crystal.

Why I can't change to pll mode?

Thanks and sorry for my english!

marcos_utfpr
Posts: 21
Joined: 05 Aug 2010 17:35
Location: Curitiba, Brazil

Re: dspic33fj128mc506 and PLL

#3 Post by marcos_utfpr » 03 Aug 2011 23:12

Hello...
If You have the same problem that I had, please check the "Basic Connection Requirements" in data sheet...
I didn't have connected all vss and vdd...

Code: Select all

void Setup_40MIPS()
{
   CLKDIVbits.PLLPOST0 = 0; // Setup PLL post scaler
   CLKDIVbits.PLLPOST1 = 0; // Setup as div by 2
   CLKDIVbits.PLLPRE0 = 0; // set up PLL prescaler to default divide by 2
   CLKDIVbits.PLLPRE1 = 0; // Will produce a Fref vaule of 5MHz ie 10MHz/2
   CLKDIVbits.PLLPRE2 = 0;
   CLKDIVbits.PLLPRE3 = 0;
   CLKDIVbits.PLLPRE4 = 0;
   PLLFBD = 30; // configure PLL feedback divisor to be 32
  //------------------------------------------------------------------------------

  // Place the New Oscillator Selection (NOSC=0b011) in W0
  asm MOV #0x03,w0
  //OSCCONH (high byte) Unlock Sequence
  asm MOV #0x0743, w1
  asm MOV #0x78, w2
  asm MOV #0x9A, w3
  asm MOV.B w2, [w1] // Write 0x78
  asm MOV.B w3, [w1] // Write 0x9A
  // Set New Oscillator Selection
  asm MOV.B w0, [w1]
  // Place 0x01 in W0 for setting clock switch enabled bit
  asm MOV #0x01, w0
  // OSCCONL (low byte) Unlock Sequence
  asm MOV #0x0742, w1
  asm MOV #0x46, w2
  asm MOV #0x57, w3
  asm MOV.B w2, [w1] // Write 0x46
  asm MOV.B w3, [w1] // Write 0x9A
  // Enable Clock Switch
  asm MOV.B w0, [w1] // Request Clock Switching by Setting OSWEN bit

  //------------------------------------------------------------------------------
  OSCCON.OSWEN = 1; // Request Oscillator switch for New config
  while (OSCCON.OSWEN); // Wait until switchover is completed
  while (!OSCCON.LOCK_); // Wait for PLL lock status
}


void main() 
{
  Setup_40MIPS();
  
  AD1PCFGL = 0xFFFF;

  TRISB.F6 = 0;

  PORTB.F6 = 1;
  
  while(1)
  {
    PORTB.F6 = 1;
    
    PORTB.F6 = 0;
  }

}
oscillator mode: Primary oscillator(XT, HS, EC)
Two Speed oscillator start-up: disable
Primary oscillator source: XT oscillator mode
Clock switching enable and monitor disable

Now I have a wave with 10MHz frequency on PORTB.F6...

I hope this can help someone!
See you...

mariofulvio62
Posts: 3
Joined: 23 Nov 2011 09:12

Re: dspic33fj128mc506 and PLL

#4 Post by mariofulvio62 » 04 May 2012 08:31

This post has been very helpfull for me :D
Thank you to everybody!

Mario

Post Reply

Return to “mikroC for dsPIC30/33 and PIC24 General”