|
|
View previous topic :: View next topic |
Author |
Message |
yokos2271
Joined: 29 Apr 2008 Posts: 5
|
PIC24HJ PLL clock confusion |
Posted: Mon Jun 17, 2013 3:52 pm |
|
|
Hello ,
I would like to use HS crystal 16MHz in PLL configuration getting 64MHz.
MCU is use is PIC24HJ64GP206.
I'm confused because looks like PPL input can be only 0.8-8 MHz based on spec pdf p.123
http://ww1.microchip.com/downloads/en/DeviceDoc/70175H.pdf
I'm 100% sure i'm reading the spec wrongly .
What fuses should i use to get 64 MHz with 16 Mhz Crystal ?
#FUSES HS
#FUSES PR_PLL
#use delay(clock=64M, oscillator=16M)
Thanks |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1345
|
|
Posted: Mon Jun 17, 2013 6:01 pm |
|
|
If you look at the diagram on the spec, the 0.8-8MHz requirement is after the PLLPRE block with is divided by N1, so that shouldn't be a problem. The #use delay() call will calculate that for you with the parameters you specified, or at least should.
In your description, you mention using a crystal, but in your code snippet you specify an oscillator. Which are you using? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19500
|
|
Posted: Tue Jun 18, 2013 9:24 am |
|
|
The core 'problem' here is one of the way CCS has evolved.
Historically, #use delay, just specified a clock rate. Nothing else.
The user then had to setup the fuses to match.
Then with chips supporting things like basic PLL's a new feature was added, and the clock statement could also be told the nature of the clock source. On the early chips there was only a siimple *4 PLL, so you then had two choices:
1) Specify the fuse to enable the PLL in the fuses, and still just specify the clock.
2) Specify the clock speed, and the source in the #use delay only.
This has evolved, and now is essential, where chips like this one have programmable dividers that have to be setup 'after boot' (they are not done in the fuses), and allow a huge range of PLL rates. However with it comes the same restrictions as on fuses, that the keywords used have to match what you are doing. The clock settings will override fuse settings, and there is no warning when this occurs.
With your chip, you don't need to specify any fuses at all!.
Simply using:
#use delay(CLOCK=64M, CRYSTAL=16M)
Tells the compiler everything it needs to know:
1) Use the crystal oscillator.
2) Final frequency does not match crystal, so use the PLL.
3) Crystal requires HS fuse.
4) Divide crystal by two to give legitimate frequency to feed the PLL (8MHx).
5) Set PLL to *16 to give the output frequency between 100, and 200MHz as required. 128MHz.
6) Set postscaler to /2, to give the 64MHz.
The chip always boots using the internal RC oscillator, and then PLLDIV PLLPRE, and PLLPOST are programmed before switching to the primary oscillator.
The key is the choice of the word 'oscillator', versus 'crystal'. Selecting oscillator sets everything up the same, except the clock source. This is instead set to 'EC' (external oscillator)..... This is what Jeremiah is pointing out.
You can always tell what is actually happening, by looking at the fuses at the end of the .lst file.
Best Wishes |
|
|
yokos2271
Joined: 29 Apr 2008 Posts: 5
|
|
Posted: Tue Jun 18, 2013 9:28 am |
|
|
Copy and paste mistake .
Should be:
#use delay(clock=64Mhz, crystal=16Mhz)
Is it possible to use not even PLL like 3x :
#use delay(clock=48Mhz, crystal=16Mhz)
Thanks |
|
|
yokos2271
Joined: 29 Apr 2008 Posts: 5
|
|
Posted: Tue Jun 18, 2013 9:32 am |
|
|
Thank you jeremiah and Ttelmah for detail explanation. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19500
|
|
Posted: Tue Jun 18, 2013 11:08 am |
|
|
The PLL on this doesn't work like those on simple chips.
You have, a programmable divider. Gives /2 to /33. Requirement is that the output of this must be in the range 0.8MHz to 8MHz.
This is followed by the PLL, which gives *2 to *513. Again programmable. Requirement here is that the output must be between 100, and 200MHz.
This is followed by another divider, which gives /2, /4 or /8. Output must be between 12.5, and 80MHz.
So from a 16MHz crystal, initial divisions by /2 to /20 can be used, giving frequencies from 0.8MHz to 8MHz.
These can then be multiplied, allowing potentially outputs of 1.6 to 4104MHz. However only values between 100, and 200MHz are 'legal' here. So you could have (for instance), the crystal/16, to give 1MHz, and then *160 to give 160MHz. Then /2 for the final divider, allows 80MHz (maximum allowed).
Yes 48MHz can be done using /2 *12 /2
The magic thing is that the range available is enormous. In all there are about 46000 possible ratios available, but usually perhaps 90% of these are not available from a given source, because of the limits. There are also often 'duplicates', with multiple routes to the same value.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|