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

Waking from sleep

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



Joined: 12 Mar 2010
Posts: 10

View user's profile Send private message

Waking from sleep
PostPosted: Wed Sep 18, 2013 5:15 pm     Reply with quote

I am using a PIC24fj256GB110 and 5.012 compiler. Most of my past projects have been with PIC18's, so forgive me if this is an ignorant question.

It appears that when the chip is awoken from sleep (in my case using a INTR_CN_PIN), it continues executing code, not from the instruction just after the sleep command, but instead it starts from the top of the main function. I can differentiate between a fresh power cycle and coming out of sleep by checking the sleep bit of the RCON register. However, it would be much more convenient if the processor started executing the commands after the sleep command. I have done this in other processors, but for some reason I can't get it to work on this one. I have tried both enabling and disabling the global interrupt flag before going to sleep, but no luck. The data sheet seems to be quite vague on this subject. Any thoughts? I can post some code if it would help.

Thanks!
SteveW



Joined: 27 Sep 2005
Posts: 25

View user's profile Send private message

PostPosted: Wed Sep 18, 2013 5:43 pm     Reply with quote

Yes, the PIC24FJ-series parts act a bit differently from the some other versions. It sounds like you are waking from "sleep full", which results in essentially a power-up boot. If you select the "sleep idle", then you will resume operation where you left off, but the idle version uses much more power.

I am just finishing a project with the same processor and made a few interesting observations upon waking from full sleep. It only kind-of does a complete reset. If variables are initialized when they are defined (e.g., "int8 dog = 0;", they may or may not reset to their defined values upon waking (i.e., they appear to sometimes reset, but other times retain their previous values -- if there is a pattern, I haven't found it). I suggest that you make sure that any flags that you expect to be reset are specifically defined in your initialization routine.

Steve
Zachr



Joined: 12 Mar 2010
Posts: 10

View user's profile Send private message

PostPosted: Thu Sep 19, 2013 9:36 am     Reply with quote

Thanks Steve!

Yes, I am going to deep sleep e.g. sleep(SLEEP_FULL).

Did you have any issues with variables (mainly concerned with static and global) loosing their values after a deep sleep, when they were not initialized along with their declaration?

I assume the stack must be cleared, otherwise if you called a sleep command from within a function, and the instruction pointer resets without clearing the stack, the return address would be stuck on the stack.

Did you find any documentation (beyond the data sheet and Sec 9 of the Family ref manual) that covers this chip and what it does coming out of deep sleep?
SteveW



Joined: 27 Sep 2005
Posts: 25

View user's profile Send private message

PostPosted: Sun Sep 22, 2013 12:55 pm     Reply with quote

Yes, I had trouble with global and static variables losing their values, and this situation appeared to be inconsistent. I now re-initialize everything upon waking, and save/restore parameters to/from external EEPROM.

I can't comment on you question about the stack. Since the part essentially does a POR on upon waking (well almost), I assume that the stack is cleared.

Regarding additional documentation regarding the sleep functions, no I didn't find any, and had to learn the hard way with a few tid-bits of info for the PIC24 that I found in this forum. I also found that with this particular device, the restart_cause() function returns a 16 when waking, whereas the header file only defines codes up to 15. Magic?

Steve
SteveW



Joined: 27 Sep 2005
Posts: 25

View user's profile Send private message

Waking from Sleep - Update
PostPosted: Fri Oct 04, 2013 11:24 am     Reply with quote

In my last post in this thread I stated something that turns out to be only partially true. Per the data sheet for PIC24FJ256GB110 series of parts:

9.2.1 SLEEP MODE
...On wake-up from Sleep, the processor will restart with the same clock source that was active when Sleep mode was entered.

9.2.2 IDLE MODE
...On wake-up from Idle, the clock is reapplied to the CPU and instruction execution begins immediately, starting with the instruction following the PWRSAV instruction or the first instruction in the ISR.

I interpreted the above words under SLEEP MODE "processor will restart..." as meaning the processor will essentially do a POR upon wake-up. That is correct, but only sometimes. Upon reviewing the PIC24 Family Reference Manual (FRM) on Power Saving, http://ww1.microchip.com/downloads/en/DeviceDoc/39698a.pdf, I see that the part either resets or continues where it left off depending on how it is awakened. That explains why I saw what appeared to be inconsistent operation. I simply added a reset_cpu() command immediately following the sleep(FULL_SLEEP) command, and now operation is predictable.

Steve
Zachr



Joined: 12 Mar 2010
Posts: 10

View user's profile Send private message

PostPosted: Fri Oct 04, 2013 11:45 am     Reply with quote

Awesome! Thanks for the follow up.
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