Question about "@ SLEEP"


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2007
    Posts
    67

    Default Question about "@ SLEEP"

    Finding Darrel's very helpful post here.....
    http://www.picbasic.co.uk/forum/show...ighlight=sleep

    and reading the data sheet about sleeping (PIC 16F616), I've got a few questions....

    I just want the pic to sleep forever until a high input is found on the RA2/INT pin, then resume operating at the line of code just following the @SLEEP command.

    1. I understand an "interrupt" is generated when in this case, the RA2/INT pin goes high (button press) as per the "Wake from sleep" section... but where does the program execution actually continue in the code? Does it always execute the line following the @ SLEEP command?

    2. Fig 12-9 notes "GIE = 1" is assumed, processor jumps to "0004h", if GIE=0, execution will continue in-line. Can I write to the GIE bit? It looks like I'd set GIE=0 just before the sleep to insure execution picks up with the instruction following.

    3. 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? Is there anything special I need to do with the WDT to make sure it doesn't wake the pic?

    4. 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.

    That's too many things that start with "INT" in one paragraph to make any sense out of them. lol. I'm confused.

    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?

    Much appreciated.


    Sidenote: I've also considered just naping in a loop, waking, checking the switch, and naping again about a second appart - which is kind of a dirty way of doing it, but it gets the job done. Just uses more juice over time. I'm sure all those little 2 uS wake / sleep cycles do add up after a while.

  2. #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
    __________________

  3. #3
    Join Date
    Aug 2007
    Posts
    67


    Did you find this post helpful? Yes | No

    Default

    Outstanding! Thank you so much Paul. That's everything I needed. Makes much sense now.

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