|
|
View previous topic :: View next topic |
Author |
Message |
Zachr
Joined: 12 Mar 2010 Posts: 10
|
Waking from sleep |
Posted: Wed Sep 18, 2013 5:15 pm |
|
|
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
|
|
Posted: Wed Sep 18, 2013 5:43 pm |
|
|
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
|
|
Posted: Thu Sep 19, 2013 9:36 am |
|
|
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
|
|
Posted: Sun Sep 22, 2013 12:55 pm |
|
|
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
|
Waking from Sleep - Update |
Posted: Fri Oct 04, 2013 11:24 am |
|
|
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
|
|
Posted: Fri Oct 04, 2013 11:45 am |
|
|
Awesome! Thanks for the follow up. |
|
|
|
|
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
|