Question about "@ SLEEP"


Results 1 to 3 of 3

Threaded View

  1. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    >> but where does the program execution actually continue in the code? Does it always execute the line following the @ SLEEP command?

    If wake up by WDT or RA2 then it will always execute the line following the sleep command

    >> Can I write to the GIE bit?

    whether high or low, it will always execute the line after the sleep command. The difference is if it is low, the program will continue on after the line after the sleep command. If GIE is high and the INTE bit is set, the program will go to the interrupt vector after completing the line after the sleep command. You can set the GIE bit like this

    INTCON.7 = 1 ' GIE = 1

    You can set the INTE bit like this

    INTCON.4 = 1

    >> If I have the WDT running (as a fail safe if the external resonator goes out) - will the pic wake from sleep after each WDT cycle?

    YES

    >> Is there anything special I need to do with the WDT to make sure it doesn't wake the pic?

    TURN IT OFF

    >> Section 12.4.1 in the datasheet talks about this interrupt on RA2/INT. It notes the INTF bit of INTCON is set when the valid edge appears, the interrupt can be disabled by clearing the INTE bit of INTCON (which I don't think I want in this case). It then says the INTF bit must be cleared before re-enabling the interrupt, and it sounds like I'd need to re-set the INTE bit prior to the next sleep cycle also.

    YES (you need to clear it, not re-set it)



    Can anyone extrapolate a list of the flags I need to set or clear before executing @SLEEP so that pic will goto sleep, and stay sleeping forever (days, months, years, etc) until that button is pressed driving RA2 high again? And to make the program resume right after the @SLEEP without jumping to some other place as a result of the interrupt?


    (Configure WDT off)
    PORTA = 0 ; PortA low
    ANSEL = 0 ; PortA digital
    TRISA = 4 ; RA2 = input
    INTCON.7 = 0 ; turn off global interrupts
    OPTION_REG.6 = 1 ; wake on rising edge

    Code Here

    INTCON.1 = 0 ; clear RA2 interrupt flag in case set (right before @ Sleep command)
    @ SLEEP
    continues here when RA2 goes high (unless goto or branch, etc)
    and then here (unless goto or branch etc)
    and then here (unless goto or branch etc)

    EDIT:

    if you have your heart set on using the WDT, you can test bit 4 of the OPTION register to see what woke the PIC from sleep. If this bit is zero, you can put the PIC immediately back to sleep. The danger is you might miss the RA2 high while testing the Option bit (if RA2's high duration is short).
    Last edited by paul borgmeier; - 8th January 2008 at 07:29. Reason: Info on WDT
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

Similar Threads

  1. ADCIN question
    By Greg McFadden in forum General
    Replies: 4
    Last Post: - 16th September 2008, 02:53
  2. AN Question for "word" variable read The serial port
    By redfoen in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th December 2007, 17:39
  3. Crystals & Caps - Super noob question??
    By kevj in forum General
    Replies: 4
    Last Post: - 24th September 2007, 17:11
  4. Question for a math guru
    By Christopher4187 in forum General
    Replies: 3
    Last Post: - 22nd November 2006, 09:45
  5. Please answer my first question
    By John_001 in forum Off Topic
    Replies: 1
    Last Post: - 15th September 2006, 06:49

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts