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 support@ccsinfo.com

setup_oscillator and OSC_STATE_STABLE

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



Joined: 23 Apr 2007
Posts: 91
Location: Rochester, England

View user's profile Send private message Visit poster's website

setup_oscillator and OSC_STATE_STABLE
PostPosted: Mon Jul 28, 2014 4:17 am     Reply with quote

Hi folks,

I'm using a PIC18F26J11 and I am putting it into sleep mode.

In order to minimise the current consumption whilst asleep I am slowing the internal oscillator down to 31KHz.

Test = setup_oscillator(OSC_31KHZ);

When I wake up, I then speed back up to internal oscillator

Test = setup_oscillator(OSC_8MHZ);

originally I had the above routines in a do/while loop where I checked the OSC_STATE_STABLE bit, and waited for it to be stable. I had a timeout routine in the loop, to break out if the stable flag was set. (See below).


Code:

         Test = setup_oscillator(OSC_8MHZ);
         do
         {
            Test = setup_oscillator(OSC_8MHZ);
            restart_wdt();
   
            /* BIT 4 IS OSCILLATOR STABLE */
            if (bit_test(Test, OSC_STATE_STABLE) == 1)
            {
               Quit = 1;
            }
   
            LoopDelay++;
            if (LoopDelay >= 20000)
            {
               Quit = 1;
            }
            delay_us(100);
         }while (Quit == 0);



However with a bit of diagnostics, my code always times out - and the stable bit is never set. Looking at the datasheet, it looks like osc stable is only for external oscillators.

so...

Firstly - is the osc stable flag only for external oscillators?

If this is so - what is the recommended method for slowing down/speeding up the system when using an internal oscillator? (ie should I wait for a time period etc...)

Thanks in advance

James
Ttelmah



Joined: 11 Mar 2010
Posts: 19328

View user's profile Send private message

PostPosted: Mon Jul 28, 2014 5:48 am     Reply with quote

Stable, _only_ applies when switching to the primary oscillator.

You are not actually changing oscillators. OSC_31KHz, and OSC_8MHz, are just different divisors off the INTOSC source. Switching is immediate. OSC_31250, is the one that switches to the INT_RC oscilator instead. The time to switch in this case is less than two machine instructions.
JamesW



Joined: 23 Apr 2007
Posts: 91
Location: Rochester, England

View user's profile Send private message Visit poster's website

PostPosted: Mon Jul 28, 2014 9:20 am     Reply with quote

Thanks,

So I can switch speeds, and proceed without any need to wait for anything to stabilise.

That's brilliant.

Cheers

James
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