Helpful ReplyHot!execution from SLEEP();

Author
brownt
Super Member
  • Total Posts : 206
  • Reward points : 0
  • Joined: 2015/11/21 14:58:09
  • Location: 0
  • Status: offline
2018/01/10 23:11:35 (permalink)
0

execution from SLEEP();

where does execution begin after SLEEP() is called?
 
PIC16LF18326
 
Assuming SLEEP() is called sometime during program execution, and assuming a IOC is generated on RA3 (MCLR line) to wake from that sleep, where does code execution begin again?
 
 
#1
qɥb
Monolothic Member
  • Total Posts : 1247
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: execution from SLEEP(); 2018/01/10 23:19:32 (permalink)
0
Depends upon your GIE setting.
Read the section "9.2.2 WAKE-UP USING INTERRUPTS" in the datasheet.
 

PicForum "it just works"
#2
jtemples
Super Member
  • Total Posts : 10509
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: execution from SLEEP(); 2018/01/10 23:57:21 (permalink) ☄ Helpfulby brownt 2018/01/11 03:07:27
+1 (1)
Execution always resumes at the instruction after SLEEP; that instruction has already been pre-fetched.  The second instruction after sleep depends on GIE if an interrupt is pending.
#3
brownt
Super Member
  • Total Posts : 206
  • Reward points : 0
  • Joined: 2015/11/21 14:58:09
  • Location: 0
  • Status: offline
Re: execution from SLEEP(); 2018/01/11 03:09:48 (permalink)
0
where does code execution start from after a watch dog reset?
and can execution be made to start elsewhere?
post edited by brownt - 2018/01/11 03:15:26
#4
qɥb
Monolothic Member
  • Total Posts : 1247
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: execution from SLEEP(); 2018/01/11 03:14:48 (permalink)
0
The word "reset" should give you a very big clue! :)
 

PicForum "it just works"
#5
brownt
Super Member
  • Total Posts : 206
  • Reward points : 0
  • Joined: 2015/11/21 14:58:09
  • Location: 0
  • Status: offline
Re: execution from SLEEP(); 2018/01/11 03:54:44 (permalink)
0
I have a program that is in SLEEP() mode until an IOC switch wakes it. It then continues around a while loop in main() indefinitely or until a switch on an I/O line puts it into sleep again. Assuming something locks up in main(), the WDT sends it back to sleep again. Is it possible to have the WDT reset things to after the SLEEP() instruction, rather than the beginning of the program?
#6
1and0
Access is Denied
  • Total Posts : 7488
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: online
Re: execution from SLEEP(); 2018/01/11 04:17:13 (permalink)
0
brownt
Assuming something locks up in main(), the WDT sends it back to sleep again.

The main purpose of the watchdog is to reset to reset vector when things "locks up". 
 
Is it possible to have the WDT reset things to after the SLEEP() instruction, rather than the beginning of the program?

If the device is in sleep mode, a WDT time-out will result in a wakeup. If the device is in run mode executing code, a WDT time-out will result in a reset.
#7
crosland
Super Member
  • Total Posts : 1142
  • Reward points : 0
  • Joined: 2005/05/10 10:55:05
  • Location: Bucks, UK
  • Status: offline
Re: execution from SLEEP(); 2018/01/11 06:27:03 (permalink)
0
brownt
Is it possible to have the WDT reset things to after the SLEEP() instruction, rather than the beginning of the program?

As has been pointed out, the clue is in the name. What you want would not be a reset.
 
If "something has locked up in main()" why do you want to just loop around to the lock up again?
 
What problem are you actually trying to fix.
#8
brownt
Super Member
  • Total Posts : 206
  • Reward points : 0
  • Joined: 2015/11/21 14:58:09
  • Location: 0
  • Status: offline
Re: execution from SLEEP(); 2018/01/11 20:59:31 (permalink)
0
trying to fix a potential problem. perhaps a combination of settings or momentary values that has not been replicated before production. Perhaps stuck in a software loop.
 
I want the system reset, but being that one of the first instructions in the program is SLEEP(), a reset does not keep the system going.
#9
1and0
Access is Denied
  • Total Posts : 7488
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: online
Re: execution from SLEEP(); 2018/01/12 12:25:08 (permalink)
+1 (1)
brownt
trying to fix a potential problem. perhaps a combination of settings or momentary values that has not been replicated before production. Perhaps stuck in a software loop.

So you don't actually have a problem.
 

I want the system reset, but being that one of the first instructions in the program is SLEEP(), a reset does not keep the system going.

If a reset does not fix your potential problem, then you'll have to rethink the design of your firmware.
 
#10
brownt
Super Member
  • Total Posts : 206
  • Reward points : 0
  • Joined: 2015/11/21 14:58:09
  • Location: 0
  • Status: offline
Re: execution from SLEEP(); 2018/01/13 04:07:14 (permalink)
0
OK. Perhaps it is not possible. I don't know how i can start the system from a momentary switch on one of its I/O lines.
What I had done was put it into sleep mode soon after power is applied, and then wake from sleep with an IOC on RA2 (MCLR). During program execution, another signal on that line puts it to sleep again. So, provided power is applied the system never shuts down, but rather sits in sleep mode waiting. So, a WDT timeout simply puts it to sleep again.
 
How else can I start from a momentary switch press without any external components like FETs, if not from sleep mode?
 
 
#11
DavidBLit
Super Member
  • Total Posts : 1510
  • Reward points : 0
  • Joined: 2012/02/18 13:08:48
  • Location: The Land of Confusion
  • Status: offline
Re: execution from SLEEP(); 2018/01/13 07:21:00 (permalink)
0
brownt
...
How else can I start from a momentary switch press without any external components like FETs, if not from sleep mode?
...

Pulse /MCLR?  LoL: LoL

Yeah, "//Code and stuff".
#12
brownt
Super Member
  • Total Posts : 206
  • Reward points : 0
  • Joined: 2015/11/21 14:58:09
  • Location: 0
  • Status: offline
Re: execution from SLEEP(); 2018/01/13 19:39:12 (permalink)
0
can you explain that a bit please David?
#13
DavidBLit
Super Member
  • Total Posts : 1510
  • Reward points : 0
  • Joined: 2012/02/18 13:08:48
  • Location: The Land of Confusion
  • Status: offline
Re: execution from SLEEP(); 2018/01/13 19:48:51 (permalink)
0
Probably not, as it really was just an attempt at some humor. I can’t seem to figure out what the actual requirements are versus the hypotheticals and I’m afraid fixating on the sleeping aspect may be making it worse.

Yeah, "//Code and stuff".
#14
brownt
Super Member
  • Total Posts : 206
  • Reward points : 0
  • Joined: 2015/11/21 14:58:09
  • Location: 0
  • Status: offline
Re: execution from SLEEP(); 2018/01/13 20:14:43 (permalink)
0
I see, fair enough. Perhaps there is a flag that can be or is set, when there is a reset from the watchdog, that is different from a flag that occurs from power on. And hence an if statement can skip the sleep() function when reset occurs from the WDT, based on the condition of that flag.
#15
qɥb
Monolothic Member
  • Total Posts : 1247
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: execution from SLEEP(); 2018/01/13 20:28:00 (permalink)
0
Something like STATUSbits.nTO and PCON0bits.nRWDT ?
 

PicForum "it just works"
#16
Jump to:
© 2018 APG vNext Commercial Version 4.5