View previous topic :: View next topic |
Author |
Message |
soonc
Joined: 03 Dec 2013 Posts: 215
|
PIC24 and setup_oscillator() |
Posted: Sun Oct 04, 2015 7:23 pm |
|
|
I'm trying to switch to the internal FRC oscillator using :
The 24FJ128GA306.h does not have a define for FRC so I assumed it is
OSC_INTERNAL.
Code: |
// compiler V5.050
#include <24FJ128GA306.h>
#use delay(clock=29491200, crystal=7372800)
At some point in my long code I need to reduce current by switching to a slower clock.
setup_oscillator(OSC_INTERNAL, 1000000, OSC_INTERNAL);
while(1)
{
output_high(PIN_B5); // checked with scope still running at full speed
output_low(PIN_B5);
}
|
I've also tried setup_oscillator(OSC_INTERNAL, 1000000); but the speed remains the same.
What is the trick to switching oscillators with the PIC24 ?
I found it real easy with PIC18. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
soonc
Joined: 03 Dec 2013 Posts: 215
|
Thanks I already did that |
Posted: Mon Oct 05, 2015 7:49 am |
|
|
Thanks PCM Prpgrammer.
I normally do well on searching and only post when I can't move forward.
I forgot to show the #FUSES for my example code.
Here is the complete test program.
Code: |
#include <24FJ128GA306.h>
#FUSES HS
#FUSES PR_PLL
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
#FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES NOBROWNOUT //No brownout reset
#device ICD=2
#build (stack=512)
#use delay(clock=29491200, crystal=7372800)
void main()
{
int32 TO=0;
output_high(PIN_F0); // keep alive my hardware specific
setup_adc_ports( NO_ANALOGS );
do{
output_high(PIN_B5); // 140nS
output_low(PIN_B5);
TO++;
}while( TO < 10000000 ); // about 8-10 second delay
/////////////////////////
// change clock
// setup_oscillator(OSC_INTERNAL, 1000000); // does not work
setup_oscillator(OSC_INTERNAL, 1000000, 1000000); // does not work
while(1)
{
output_high(PIN_B5); // still 140nS should be a longer !
output_low(PIN_B5); // switching oscillator did not happen
}
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Mon Oct 05, 2015 7:58 am |
|
|
Look again at what was posted. Not OSC_INTERNAL, but OSC_SECONDARY. |
|
|
soonc
Joined: 03 Dec 2013 Posts: 215
|
Solution (is not good) Does anyone have a better idea |
Posted: Mon Oct 05, 2015 8:13 am |
|
|
I called CCS Tech Support.
It appears the PIC24 has a problem switching oscillator in Debug mode.
I removed #device ICD=2 compiled and loaded the test code and sure enough the clock switching works.
This is not good as I'm porting code from PIC18 to PIC24 and I know I'll need to do some code changes when the chip is running at slow speed.
Has anyone run into this problem and is there any fix for it ?
Maybe time to consider a different PIC24 unless they all have that issue ! |
|
|
soonc
Joined: 03 Dec 2013 Posts: 215
|
yes but...! |
Posted: Mon Oct 05, 2015 9:14 am |
|
|
Ttelmah wrote: | Look again at what was posted. Not OSC_INTERNAL, but OSC_SECONDARY. |
OK I'll search again.
I can't use the OSC_SECONDARY as it's too slow it's at 32KHz.
The FRC is what I need to use.
See my earlier post there seems to be an issue with the PIC24 in debug mode. I confirmed clocking switching works in release mode but that is not going to make it easy to debug code. Clocking switching has to happen on the fly while monitoring real time data.
Clock switching on the PIC18 works in debug mode ! |
|
|
soonc
Joined: 03 Dec 2013 Posts: 215
|
Re: Solution (is not good) Does anyone have a better idea |
Posted: Mon Oct 05, 2015 9:29 pm |
|
|
soonc wrote: | I called CCS Tech Support.
Maybe time to consider a different PIC24 unless they all have that issue ! |
I was told ALL PIC24 series have this same problem !
Does not look good for my project. |
|
|
|