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

PIC24 and setup_oscillator()

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



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

PIC24 and setup_oscillator()
PostPosted: Sun Oct 04, 2015 7:23 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Oct 04, 2015 10:30 pm     Reply with quote

Search the forum archives for: 24fj* switch oscillator*
Set it to "Search for all terms".
Get this result:
http://www.ccsinfo.com/forum/viewtopic.php?t=52957
soonc



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

Thanks I already did that
PostPosted: Mon Oct 05, 2015 7:49 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Oct 05, 2015 7:58 am     Reply with quote

Look again at what was posted. Not OSC_INTERNAL, but OSC_SECONDARY.
soonc



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

Solution (is not good) Does anyone have a better idea
PostPosted: Mon Oct 05, 2015 8:13 am     Reply with quote

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

View user's profile Send private message

yes but...!
PostPosted: Mon Oct 05, 2015 9:14 am     Reply with quote

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

View user's profile Send private message

Re: Solution (is not good) Does anyone have a better idea
PostPosted: Mon Oct 05, 2015 9:29 pm     Reply with quote

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.
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