View previous topic :: View next topic |
Author |
Message |
JamesW
Joined: 23 Apr 2007 Posts: 91 Location: Rochester, England
|
setup_oscillator and OSC_STATE_STABLE |
Posted: Mon Jul 28, 2014 4:17 am |
|
|
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: 19539
|
|
Posted: Mon Jul 28, 2014 5:48 am |
|
|
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
|
|
Posted: Mon Jul 28, 2014 9:20 am |
|
|
Thanks,
So I can switch speeds, and proceed without any need to wait for anything to stabilise.
That's brilliant.
Cheers
James |
|
|
|