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

PIC24FJ64GA306 oscillator setup

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



Joined: 05 Apr 2011
Posts: 303

View user's profile Send private message

PIC24FJ64GA306 oscillator setup
PostPosted: Wed Oct 01, 2014 11:46 am     Reply with quote

I am trying to switch between the primary crystal oscillator and the secondary oscillator for a lower power operation mode. I have done this frequently with PIC18 processors and I am trying to do the same on the PIC24.

The built-in function seems to not be accepting the OSC_SECONDARY option, which was copied from the processor include file.
I have sent a report to CCS but thought someone here may have some insight if I am missing something obvious.
Code:

#include <24FJ64GA306.h>
#device ADC=12
#build(STACK=512)

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WINDIS                   //Watch Dog Timer in non-Window mode
#FUSES NOLVR                    //Low Voltage Regulator Disabled
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOJTAG                   //JTAG disabled
#FUSES NOIOL1WAY                //Allows multiple reconfigurations of peripheral pins
#FUSES NOOSCIO                  //OSC2 is clock output
#FUSES CKSFSM                   //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES VREFNORM_CVREFNORM       //VREF and CVREF are mapped to their default pins
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES WPFP                     //Write/Erase Protect Page Start/End Location, set to last page or use WPFP=x to set page
#FUSES VBATBOR                  //VBAT BOR Enabled
#FUSES SOSC_SEL                 //SOSC circuit selected
#FUSES WDTWIN_25%               //Watchdog Window is 25% of WDT period
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES WPDIS                    //All Flash memory may be erased or written
#FUSES NOWPCFG                  //Configuration Words page is not erase/write-protected
#FUSES WPEND                    //Flash pages WPFP to Configuration Words page are write/erase protected
#FUSES DSWDT_25DAYS             //DSWDT uses 1:68719476736 Postscale (25.7Days)
#FUSES DSWDTCK_LPRC             //DSWDT uses LPRC as reference clock
#FUSES DSBOR                    //BOR enabled in Deep Sleep
#FUSES DSWDT                    //Deep Sleep Watchdog Timer enabled
#FUSES DS_SW                    //Deep Sleep is controlled by the register bit DSEN

#device ICSP=1
#use delay(clock=32Mhz,crystal=8MHz)


void  main()
{
   delay_ms(2000);
   setup_oscillator(OSC_SECONDARY);       // error message Option invalid :: No Internal Osc
   delay_ms(2);
   setup_oscillator(OSC_INTERNAL,31000);
   delay_ms(2);
   setup_oscillator(OSC_CRYSTAL,32000000,8000000);
}


Compiler version is 5.024
gaugeguy



Joined: 05 Apr 2011
Posts: 303

View user's profile Send private message

PostPosted: Wed Oct 01, 2014 2:17 pm     Reply with quote

I heard back from CCS support and
Code:

setup_oscillator(OSC_SECONDARY, 32768, 32768);

makes the compiler happy.
jeremiah



Joined: 20 Jul 2010
Posts: 1358

View user's profile Send private message

PostPosted: Wed Oct 01, 2014 3:46 pm     Reply with quote

One thing you should be careful of going forward is that you are not specifying your primary oscillator's fuses. If you are lucky, the compiler will pick the right ones, but I have been bitten by this before. There are 2 fuses of interest:

#FUSES PR_PLL //tells the PIC the default clock source is an external clock/osc with PLL
#FUSES HS //tells the PIC to use the high speed oscillator circuit.

On the second one, I didn't have the Datasheet in front of me, so I assumed 8MHz is an HS type circuit. If it is not, then it would be

#FUSES PR_PLL
#FUSES XT

while you might be ok as is with the defaults, it is always good to specify.
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