CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How to define the clk speed for a PIC24FJ?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
E_Blue



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

How to define the clk speed for a PIC24FJ?
PostPosted: Mon Apr 01, 2019 10:49 am     Reply with quote

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: 19537

View user's profile Send private message

PostPosted: Mon Apr 01, 2019 11:28 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 01, 2019 12:10 pm     Reply with quote

So the...
Code:
setup_oscillator(OSC_CRYSTAL);


...is not longer needed?
_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Mon Apr 01, 2019 12:50 pm     Reply with quote

No, not unless you are wanting to do some form of oscillator switching.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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