Shop OBEX P1 Docs P2 Docs Learn Events
Return from Interrupt After Sleep (Using WKEN) — Parallax Forums

Return from Interrupt After Sleep (Using WKEN)

ZootZoot Posts: 2,227
edited 2007-11-03 23:47 in General Discussion
If you enable an edge-detect wakeup on a pin (using WKEN_B), after the ISR runs, will the main program resume with the PC set to the instruction following SLEEP?

Quasi-related -- say I'm running an RTCC ISR, but I want to shut down the RTCC ISR, enable wakeup from a pin-driven interrupt, then sleep, then restart the RTC ISR after wakeup,·would I do something like the following:

  MOV !OPTION,#%1100_1000        ; turn off ISR 
  MODE $09                       ; clear pending
  MOV !RB,#%0000_0000           
  MODE $0A                       ; falling edge detect
  MOV !RB,#%1111_1111           
  MODE $0B                       ; enable wakeup int from button RB.4 - active low
  MOV !RB,#%1110_1111           

  SLEEP                          ; return below after int?

  MODE $0B                       ; turn off wakeup int
  MOV !RB,#%1111_1111           
  MODE $09                       ; clear pending
  MOV !RB,#%0000_0000           
  MOV !OPTION,#%1000_1000        ; restore original RTCC settings



And if I didn't need to seize control of the RTCC interrupt upon wakeup, could I leave it at:

  MODE $09                       ; clear pending
  MOV !RB,#%0000_0000           
  ; default MODE $0A                       ; falling edge detect
  ; default MOV !RB,#%1111_1111           
  MODE $0B                       ; enable wakeup int from button RB.4 - active low
  MOV !RB,#%1110_1111           

  SLEEP                          ; return below after int?

  MODE $0B                       ; turn off wakeup int
  MOV !RB,#%1111_1111           
  MODE $09                       ; clear pending



The project I'm working on doesn't need to deal with the wakeup in the ISR.

Last, one thing I *think* I'm clear on with WKPND -- whenever you write to WKPND, you are *always* swapping with W?

So

MODE $09
MOV !RB,#%0000_0000

would put current WKPND into W and put 0 in WKPND? and

CLR W
MODE $09
MOV !RB, W

would effectively do the same thing, and

MODE $09
MOV !RB, someVar

would put someVar into WKPND, and put WKPND into W, leaving someVar in it's original state?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-11-03 06:23
    After a reset, execution starts at the reset entry point.
    See attached appnote how to distinguish between different
    types of reset.

    regards peter
  • BeanBean Posts: 8,129
    edited 2007-11-03 13:38
    Like Peter said, after reset or wake-up the SX starts executing from the beginning again. NOT at the instruction after SLEEP.

    "MOV !RB,W" will always swap the values. There is no such instruction as "MOV !RB,#0" or "MOV !RB,someVar", they are compound instructions.
    So "MOV !RB,#0" becomes "MOV W,#0" & "MOV !RB,W"
    And "MOV !RB,someVar" becomes "MOV W,someVar" & "MOV !RB,W", so no the WKPND values does NOT end up in someVar unless you do "MOV !RB,someVar", then "MOV someVar,W"

    You have to watch those compound instructions, they are handy, but they can really trip you up.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • ZootZoot Posts: 2,227
    edited 2007-11-03 14:06
    Thanks gentlemen, you've cleared up a serious point of confusion. smile.gif That AppNote is the handiest doc I've seen in days.

    A few points I wish to have clarified then:

    - an input wakeup, then, is essentially a "soft" reset, and I can take advantage of unchanged registers and the PD and TO bits to decide what to do differently from a hard reset (if I choose), keeping in mind that some registers will be unchanged from before the sleep state (rather than undefined as they might be on powerup).

    - since I use SX/B for the startup and main portions of my code, and ASM for the nitty-gritty, I would presume that an input wakeup will skip the powerup portion of SX/B's startup code

    - in SX/B if I write:

    WKPND_B = %0000_00000

    In my src file I see:

    MODE $09 ; clear pending
    MOV !RB,#%0000_0000

    Bean, it sounds like you are saying the above is really a compound instruction, e.g.:

    MODE $09
    MOV W, #0 ; set up W for swap
    MOV !RB, W ; any move into WKPND swaps WKPND and W

    This is done by the assembler?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • BeanBean Posts: 8,129
    edited 2007-11-03 15:21
    Zoot,
    If you are using SX/B then make sure you use the NOSTARTUP option on the PROGRAM line. Like "PROGRAM Start NOSTARTUP" this will prevent SX/B from clearing all the variables duing a wake-up.

    A wake-up input only has an effect if the SX is in sleep mode. Otherwise it does nothing.

    Yes, the ONLY instruction that exists to change !RB is "MOV !RB,W" so anything else is a compound instruction that get expanded by the assembler.

    Look at my "Magic 8 Ball" code for an example of using the Watchdog wake-up. Most will apply to using a wake-up pin too.
    http://forums.parallax.com/showthread.php?p=670447

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • ZootZoot Posts: 2,227
    edited 2007-11-03 23:47
    Perfectly clear. Thanks Bean. Thanks Peter.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
Sign In or Register to comment.