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

Pic24FJ64GB002 - External Oscillator 12 Mhz

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



Joined: 07 Jul 2013
Posts: 16
Location: Greece

View user's profile Send private message Send e-mail Visit poster's website

Pic24FJ64GB002 - External Oscillator 12 Mhz
PostPosted: Mon Jul 15, 2013 12:41 pm     Reply with quote

Hello everyone...

I have a problem with this microcontroller. I want to make a simple program with an external oscillator using a crystal. I made firstly a program with internal oscillator at 8 MHz but i want to add a crystal 12 MHz so that I can use USB without any problem later. I am a beginner with that kind of PIC so I need your help. There is no kind of example in CCS with my microcontroller... Can anyone help me with the fuses??? The datasheet is a little bit complicated and i cannot understand that.
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Mon Jul 15, 2013 1:16 pm     Reply with quote

Key question. What compiler version do you have?...

This is vital, because fully programming the oscillator has only worked quite recently. If your's is a slightly older compiler, you will need to manually set the divisor ratios etc.. Code for this has been posted here. Several of the examples do setup the clocks for other chips in the same family, and these have the same basic clock.
Key is to let the compiler do it for you!.
Code:

#include <24FJ64GB002.h>
#fuses NOWDT, NOIESO //enable any things you want like watchdog here
#use delay(crystal=12Mhz, clock=32MHz)
//This says your crystal is 12Mhz, so divide this to feed the USB prescaler,
//program the PLL output division to give 32Mhz to the CPU (you can
//change this is you
//want to run slower, 16, 8 or 4MHz), and generate the 48Mhz for the USB

If you compile with this, and look at the .lst, you will find the compiler selects the crystal oscillator, primary, PLL, 96MHzPLL, & prescale divsion by three, to give the required 4MHz to the PLL.
If you have an older compiler, then search the forum for the tools to program the PLL.

Best Wishes
asiklariskostas



Joined: 07 Jul 2013
Posts: 16
Location: Greece

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Mon Jul 15, 2013 1:51 pm     Reply with quote

Hello, Ttelmah.

Thanks for your reply.

The version of my C Compiler is: CCS PCD C Compiler, Version 4.130

It doesn't work for me. I don't know if the reason is the properly version, but i added some fuses that may make this work. The program doesn't work. This program works with internal osc. I've connected properly the 2 capacitors and the crystal with my Pic. Are these the right fuses to make my Pic to work???

Code:

#include <24FJ64GB002.h>
#fuses NOWDT, NOIESO, HS, PR, PR_PLL, PLL96MHZ, PLLDIV3 //enable any things you want like watchdog here
#use delay(crystal=12Mhz, clock=32MHz)
//This says your crystal is 12Mhz, so divide this to feed the USB prescaler,
//program the PLL output division to give 32Mhz to the CPU (you can
//change this is you
//want to run slower, 16, 8 or 4MHz), and generate the 48Mhz for the USB
jeremiah



Joined: 20 Jul 2010
Posts: 1348

View user's profile Send private message

PostPosted: Mon Jul 15, 2013 2:02 pm     Reply with quote

PR and PR_PLL are options for the same field. You need to select one or the other (PR_PLL).

When you say it doesn't work, what do you mean? How does it not work specifically?

Try:

Code:

#include <24FJ64GB002.h>
#fuses NOWDT, NOIESO, HS, PR_PLL, PLL96MHZ, PLLDIV3 //enable any things you want like watchdog here
#use delay(crystal=12Mhz, clock=32MHz)
//This says your crystal is 12Mhz, so divide this to feed the USB prescaler,
//program the PLL output division to give 32Mhz to the CPU (you can
//change this is you
//want to run slower, 16, 8 or 4MHz), and generate the 48Mhz for the USB

void main(){
   while(TRUE){
      delay_ms(500);
      output_high(PIN_B7);  //pic a pin that you want here instead
   }
}


You should get a 1Hz signal out on whatever pin you select. If not, what speed is it outputting at?
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Mon Jul 15, 2013 2:34 pm     Reply with quote

Jeremiah's settings should work.
Are you absolutely sure you have the crystal connected and working properly?.
If it won't work try:
Code:

#fuses NOWDT, CKFSM, HS, PR
#use delay(crystal=12Mhz)


Then use a flash program like Jeremiah has posted, and time the flash. If it gives 1 second, then the crystal is working. If it gives 1.5seconds, then there is a problem with your crystal hardware somewhere (it'll drop back to 8MHz).

Best Wishes
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Mon Jul 15, 2013 3:38 pm     Reply with quote

From experience, some of the 33 series dsPICs cannot directly start oscillation from an external crystal > 8MHz. In those cases you must first start with the internal oscillator, then perform an internal to external oscillator changeover.
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Tue Jul 16, 2013 12:36 am     Reply with quote

Correct.
This is done to give 'fast boot', given the long time it takes the crystal to start.
However the compiler/chip should do this automatically, if you use the #use delay settings the way I originally showed. Done like this on chips that need it, the compiler generates the code to switch clock once started as well - it won't if you manually select the fuses instead.
On chips like this, there is no option to start on the primary, FRC, is usually the only 'boot' oscillator, and what you have to do is setup the primary, boot, then use a setup_oscillator call to switch to the primary. However this chip is not one to which this applies. It is capable of waking on the primary oscillator.
I should say at this point, I have a board here using the 24FJ64GB004. The original method I showed, was directly from the code being used on this, only change crystal=20MHz, and 4.141.

Best Wishes
asiklariskostas



Joined: 07 Jul 2013
Posts: 16
Location: Greece

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Jul 16, 2013 3:03 pm     Reply with quote

Thanks guys for all the information that you gave me...

So, i tried everything except to update my Compiler to 4.141 Version. Is it easy to oscillate from internal oscillator first and then to oscillate from external? It is simple to oscillate the internal, but then, how can you turn on external oscillator???

PS_1: I run a program that make a LED to blink in 2 Seconds. With internal osc I can make it, but not with external.

PS_2: I have my crystal connected between PIN 9 and 10, and two capacitors. One between Pin 9 and Ground, and the other between Pin 10 and Ground.
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Tue Jul 16, 2013 3:31 pm     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=47757&highlight=crystal
asiklariskostas



Joined: 07 Jul 2013
Posts: 16
Location: Greece

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Jul 25, 2013 8:55 am     Reply with quote

Thanks Smile that was really helpful.
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