Hot!PIC32MX Wake from Sleep/Idle and resume execution of code

Author
Ed Anderson
Starting Member
  • Total Posts : 58
  • Reward points : 0
  • Joined: 2013/07/23 05:31:39
  • Location: 0
  • Status: offline
2019/01/12 09:11:32 (permalink)
0

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?
 
Thanks
 
 
#1

5 Replies Related Threads

    al_bin
    Super Member
    • Total Posts : 163
    • Reward points : 0
    • Joined: 2011/02/11 06:28:47
    • Location: 0
    • Status: offline
    Re: PIC32MX Wake from Sleep/Idle and resume execution of code 2019/01/12 14:05:46 (permalink)
    0
    Everything is OK except main() is not first things CPU doing.
    See Compiler user's guide about runtime startup code.
     
    Albert
     
    post edited by al_bin - 2019/01/12 14:17:55
    #2
    Mysil
    Super Member
    • Total Posts : 3214
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: online
    Re: PIC32MX Wake from Sleep/Idle and resume execution of code 2019/01/12 14:47:44 (permalink)
    0
    Hi,
    What programming language and compiler are you trying to use? Pascal?
     
    If you are using anything else than XC32,
    then you depend upon the startup code of the compiler and linker you are using,
    to handle testing of RCON as explained in datasheet and FRM section 9, and to not reinitialize the program to start main.
     
        Mysil
    post edited by Mysil - 2019/01/12 15:11:38
    #3
    Ed Anderson
    Starting Member
    • Total Posts : 58
    • Reward points : 0
    • Joined: 2013/07/23 05:31:39
    • Location: 0
    • Status: offline
    Re: PIC32MX Wake from Sleep/Idle and resume execution of code 2019/01/13 08:47:19 (permalink)
    0
    Thanks for the response, guys.
     
    Yes, Mysil I am using the Mikro Pro32 Pascal compiler.  Your response is may indeed indicate why the code which appears to work in "C" does not work with my Pascal Compiler even though I get no errors when complying the assembly code taken from "C".
     
    I have the feeling that the "erie" command may not be functioning in the compiler I am using and that is why I get no resumption of the code past the "Wait" command.
     
    The "Wait" Command appears to work, the check for RCON to determine whether WDT time out (either in sleep or idle mode) appears to work, however, it does not return me to the code immediately following the "Wait" command.  That leads me to suspect that the "Return" function is not functioning as expected.
     
    So just may be beating my head against the brick wall in this case.
     
    Thanks again
     
     
    #4
    Mysil
    Super Member
    • Total Posts : 3214
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: online
    Re: PIC32MX Wake from Sleep/Idle and resume execution of code 2019/01/13 10:31:37 (permalink)
    4 (1)
    Hi,
    In my opinion, you should forward this question as a formal support request to Mikro Elektronika.
     
        Mysil
    #5
    Ed Anderson
    Starting Member
    • Total Posts : 58
    • Reward points : 0
    • Joined: 2013/07/23 05:31:39
    • Location: 0
    • Status: offline
    Re: PIC32MX Wake from Sleep/Idle and resume execution of code 2019/01/19 09:57:56 (permalink)
    0
    Hi Mysil,
     
    I did as you suggested and thought you might be interested in the reply (below) I received after several iterations with my compiler support team.
     
    Hopefully they will include the start up code now missing so I can use the WDT as advertised.  They have been very responsive in the past when such omissions were found.
     
    thanks again for you comments and suggestion
     
    Best Regards
     
    Ed
     

    Hi Ed,

    I have been working on this for some time today and I came to the realization that datasheet information is a little bit misleading.
    It is written under assumption that one is using their MPLAB C32 compiler, which automatically adds a start-up code which executes before the main() function, and in that start-up code there is a line that checks for and handles the NMI that WDT generates during sleep/idle mode.

    Our compiler uses the System library for this, but that library does not check for nor handle the NMI caused by the WDT.
    I will attempt to address this by modifying the System library, but if the compiler itself needs to be modified then my hands are tied and I will have to forward this to our developers, so they could have a look at it and eventually address this in a future update.

    I sincerely apologize for the inconvenience caused by this.

    Kind regards,
    #6
    Jump to:
    © 2019 APG vNext Commercial Version 4.5