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

Wake up from Sleep()

 
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

Wake up from Sleep()
PostPosted: Wed Jan 14, 2015 2:29 pm     Reply with quote

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



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Wed Jan 14, 2015 3:47 pm     Reply with quote

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



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

PostPosted: Wed Jan 14, 2015 7:59 pm     Reply with quote

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