View previous topic :: View next topic |
Author |
Message |
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
How to define the clk speed for a PIC24FJ? |
Posted: Mon Apr 01, 2019 10:49 am |
|
|
I'm playing with a PIC24FJ1024GB610 to learn how it works.
I have a Microchip board to play; that board have an 8MHz crystal for the main oscillator.
I tried by using
Code: |
#use delay(clock=8M)
void main()
{
unsigned int32 x;
long y=8;
long z=150;
setup_oscillator(OSC_CRYSTAL);
for(x=0;x<153600;x++)
{
y+=z;
}
while(1)
{
delay_ms(1);
}
}
|
But I get an error:
Error#99 Option invalid No PLL Option
I don't even try to use the PLL at this moment.
First I want to run at 8MHz, then, I will try to start the PLL.
I read the 24FJ1024GB610.h file and there are only five options and none of them specify the PLL or the MHz from the internal clock as in PIC18F family.
Code: |
#define OSC_INTERNAL 32
#define OSC_CRYSTAL 1
#define OSC_CLOCK 2
#define OSC_RC 3
#define OSC_SECONDARY 16 |
There's any info about how to handle the oscillator configurations in PIC24FJ family? _________________ Electric Blue |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19509
|
|
Posted: Mon Apr 01, 2019 11:28 am |
|
|
Unlike simpler chips, there is no simple crystal feeds clock setup.
The default setting is to always use the PLL (since this is required for
USB). To not use this you have to explicitly Say. Once you use the PLL
there are restrictions on what can be done.
Now the reason the fuse lack the normal settings is that the PLL is all
setup is in software immediately after boot (before your code starts).
The key is that you have to specify the clock, and the frequency to be generated from it.
So (for instance), for the inetrnal oscillator:
#use delay(INTERNAL=32MHz)
Tells it you are using the internal oscillator, and to setup the divider and
PLL to give 32MHz.
In your case:
#use delay(CRYSTAL=8MHz, CLOCK=32MHz)
Specifies to setup the PLL from an 8MHz crystal to give 32MHz.
To get 8MHz without the PLL, use
#FUSES XT
#use delay(CRYSTAL=8MHz)
With your just 'CLOCK' deifnition, it doesn't know how to acheive this,
since you are not specifying which oscillator should actually give it... |
|
|
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
|
Posted: Mon Apr 01, 2019 12:10 pm |
|
|
So the...
Code: | setup_oscillator(OSC_CRYSTAL); |
...is not longer needed? _________________ Electric Blue |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19509
|
|
Posted: Mon Apr 01, 2019 12:50 pm |
|
|
No, not unless you are wanting to do some form of oscillator switching. |
|
|
|