View previous topic :: View next topic |
Author |
Message |
soonc
Joined: 03 Dec 2013 Posts: 215
|
Wake up from Sleep() |
Posted: Wed Jan 14, 2015 2:29 pm |
|
|
Planning to use a PIC18F26K22 and I need to put the chip to sleep for power saving.
I have the main interrupt available just for this purpose (Pin_B0).
I intend to issue a command for the chip to execute the Sleep() and the external circuity will do the wake up interrupt on Pin_B0.
Pseudo Code:
Code: |
int a=0;
switch(Command)
{
case 'S': // go to sleep command
Sleep();
a=1; //next line of code after sleep
break;
}
|
When the interrupt occurs will the chip execute the next line of code after the Sleep() when it wakes up ?
If the next line is executed should I delay_ms(100 or so) to give the chip time to wake up ?
If not what happens after the chip wakes up ?
Is the stack preserved as it was prior to the Sleep() call ?
Thanks for advice. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19375
|
|
Posted: Wed Jan 14, 2015 3:47 pm |
|
|
You need to put a NOP instruction as the next instruction (delay_cycles(1);). The instruction after, is 'prefetched' when you go to sleep. If it is one half of something like a memory data movement, this can cause problems. Hence you are advised to always ensure this instruction effectively does nothing. The single 'delay_cycles' instruction codes as a NOP. A longer delay won't.
Everything will then continue as normal. Stack, RAM etc., are all preserved.
Depending on your clock source, you should wait for the oscillator to re-stabilise. Check the status from the oscillator if it is something like a crystal. |
|
![](templates/subSilver/images/spacer.gif) |
soonc
Joined: 03 Dec 2013 Posts: 215
|
|
Posted: Wed Jan 14, 2015 7:59 pm |
|
|
Ttelmah wrote: | You need to put a NOP instruction as the next instruction (delay_cycles(1);). The instruction after, is 'prefetched' when you go to sleep. If it is one half of something like a memory data movement, this can cause problems. Hence you are advised to always ensure this instruction effectively does nothing. The single 'delay_cycles' instruction codes as a NOP. A longer delay won't.
Everything will then continue as normal. Stack, RAM etc., are all preserved.
Depending on your clock source, you should wait for the oscillator to re-stabilise. Check the status from the oscillator if it is something like a crystal. |
Thanks for the advice. Sleep() is something I have never used. |
|
![](templates/subSilver/images/spacer.gif) |
|