![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
gaugeguy
Joined: 05 Apr 2011 Posts: 298
|
PIC24FJ64GA306 oscillator setup |
Posted: Wed Oct 01, 2014 11:46 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
gaugeguy
Joined: 05 Apr 2011 Posts: 298
|
|
Posted: Wed Oct 01, 2014 2:17 pm |
|
|
I heard back from CCS support and
Code: |
setup_oscillator(OSC_SECONDARY, 32768, 32768);
|
makes the compiler happy. |
|
![](templates/subSilver/images/spacer.gif) |
jeremiah
Joined: 20 Jul 2010 Posts: 1329
|
|
Posted: Wed Oct 01, 2014 3:46 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|