PIC32MX Wake from Sleep/Idle and resume execution of code
I have tried a number of approaches to having my code resume after a "Wait" command when a Watch Dog timer interrupt occurs, all without success.
If I understand the section 9 Watch Dog Timer correctly, it appears there is a way to resume code execution after a "Wait" command if the Osccon is set correctly. This "return" requires code to do a check of RCON at the start of the program to determine whether a WDT interrupt occurred and whether the MCU was in "Sleep" or "Idle" mode. They give an excellent example of how to do this in Section 9 page 9 code example 9-2
Here is an extract of Section 9 supporting that approach:
9.4.2 Watchdog Timer NMI
When the WDT module expires in Sleep or Idle, a NMI is generated. The NMI causes the CPU
code execution to jump to the device reset vector. Although the NMI shares the same vector as
a device Reset, registers and peripherals are not reset.
To detect a wake from a power-saving mode by the WDT, the WDTO bit (RCON<4>), SLEEP bit
(RCON<3>) and IDLE bit (WDTCON<2>) must be tested. If the WDTO bit is a ‘1’, the event was
caused by a WDT time-out. The SLEEP and IDLE bits can then be tested to determine if the WDT
event occurred in Sleep or Idle modes.
To cause a WDT time-out in Sleep mode to act like an interrupt, a return from interrupt instruction
(RETFIE) may be used in the start-up code after the event was determined to be a WDT
wake-up. This will cause code execution to continue with the opcode following the
WAIT instruction that put the device into the power-saving mode. Refer to Example 9-2.]
Is this approach still valid? I can get the WDT reset but it always resumes at the start point of the code rather than after the "Wait" command. Has anyone attempted this code and was successful with a restart after the "Wait" command?