Permanent sleep


Closed Thread
Results 1 to 40 of 59

Thread: Permanent sleep

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Permanent Sleep eh?.... Well apart from a Sledge Hammer... try...

    @ SLEEP

    The PIC will sleep PERMANENTLY until woken by an interrupt event... this does not mean you have to embed Assembler interrupts or the like, execution of the program 'should' continue from the next instruction when the PIC is woken from it's slumber.

    For example this snippet of code shows (for a 16F628) what Registers you need to set in order to trigger a wake event...

    Code:
    	'
    	'	PIC Low-Power Sleep Routine
    	'	---------------------------
    		'
    		'	Set Sleep Interrupts
    		'	--------------------
    	INTCON=%00011000	' Interrupt Control Register
    				'    7=0 - GIE  - Global Interrupt Enable
    				'    6=0 - PEIE - Peripheral Interrupt Enable
    				'    5=0 - TOIE - TMR0 Overflow Interrupt Enable
                                    '    4=1 - INTE - RB0/INT Enable
    				'    3=1 - RBIE - PORTB change interrupt Enable
    				'    2=0 - TOIF - TMR0 Overflow Flag
    				'    1-0 - INTF - RB0/Ext Interrupt Flag
    				'    0=0 - RBIF - PORTB Interrupt Flag
    	OPTION_REG.6=1		' 1=RB0 Rising-Edge Trigger, 0=Falling-Edge Trigger
    		'
    		'	Reset Interrupt Flags
    		'	---------------------
    	INTCON.1=0		' Reset RB0 Flag
    	INTCON.0=0		' Reset PORTB change Flag
    		'
    		'	Sleep
    		'	-----
    	@ SLEEP
    	Pause 100		' Needed for system Wake-Up
    You can see that I'm setting a wake-up call using either RB0 or PortB inputs. The Pause can be omitted, but works for me, so that the PIC can have a stretch, yawn, light-up a cigarette etc...

  2. #2
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default Simply not working

    Hello Mel,

    I am trying to get this sleep comand to work and it simply does not work.

    my code:
    @ DEVICE PIC16F628A, INTRC_OSC_NOCLKOUT, WDT_OFF, LVP_OFF, PWRT_OFF, PROTECT_OFF, BOD_OFF
    CMCON=7
    VRCON=%01101100 'VRCON bit7 is OFF for no current drain
    OPTION_REG.7 = 0 ' ENABLE INTERNAL PULLUPS
    Trisa = %01111111
    Trisb = %11111111
    LED VAR PORTA.7

    '
    ' PIC Low-Power Sleep Routine
    ' ---------------------------
    '
    ' Set Sleep Interrupts
    ' --------------------
    INTCON=%00011000 ' Interrupt Control Register
    ' 7=0 - GIE - Global Interrupt Enable
    ' 6=0 - PEIE - Peripheral Interrupt Enable
    ' 5=0 - TOIE - TMR0 Overflow Interrupt Enable
    ' 4=1 - INTE - RB0/INT Enable
    ' 3=1 - RBIE - PORTB change interrupt Enable
    ' 2=0 - TOIF - TMR0 Overflow Flag
    ' 1-0 - INTF - RB0/Ext Interrupt Flag
    ' 0=0 - RBIF - PORTB Interrupt Flag
    OPTION_REG.6=1 ' 1=RB0 Rising-Edge Trigger, 0=Falling-Edge Trigger

    CYCLE:
    '
    ' Reset Interrupt Flags
    ' ---------------------
    INTCON.1=0 ' Reset RB0 Flag
    INTCON.0=0 ' Reset PORTB change Flag
    '
    ' Sleep
    ' -----
    LOW LED
    @ SLEEP
    @ nop
    @ nop
    @ nop
    @ nop

    Pause 100 ' Needed for system Wake-Up
    HIGH LED : PAUSE 200 : LOW LED
    GOTO CYCLE

    Maybe I could be missing some thing. The LED just keeps blinking.

    Basically I am trying to incorporate this in a garage code lock project.

    any help ?

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by charudatt View Post

    ' Set Sleep Interrupts
    ' --------------------
    INTCON=%00011000 ' Interrupt Control Register
    ' 7=0 - GIE - Global Interrupt Enable
    ' 6=0 - PEIE - Peripheral Interrupt Enable
    ' 5=0 - TOIE - TMR0 Overflow Interrupt Enable
    ' 4=1 - INTE - RB0/INT Enable
    ' 3=1 - RBIE - PORTB change interrupt Enable
    ' 2=0 - TOIF - TMR0 Overflow Flag
    ' 1-0 - INTF - RB0/Ext Interrupt Flag
    ' 0=0 - RBIF - PORTB Interrupt Flag
    OPTION_REG.6=1 ' 1=RB0 Rising-Edge Trigger, 0=Falling-Edge Trigger

    ?


    Hi, Charudatt

    May be you could simply enable the interrupts before sleeping ... might work better.

    Yess GIE = 1 ... ( INTCON.7 = 1 )



    oh, oh ... you are still asleep ???

    Alain
    Last edited by Acetronics2; - 12th May 2007 at 14:34.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    You are obviously being woken from Sleep, so find out what is causing it...

    ...and ground all the INPUT pins on PortB in case one is floating.

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Heuuu

    No GIE = No Sleep ( RTFDatasheet ... $ 14.8.1 - Greyed Note ), so we set GIE Bit

    Then ... Executes the 1St NOP

    Then ... Branches to location 0004 ...

    But there is a supposed Interrupt stubb here instead of falling into the "program" ...

    a single " DEFINE INTHAND INIT " without any interrupt stubb ( LOL ! ) would push the libs away from the 4 first program locations ... and allow restarting the PIC as a first power up ...

    We could also Branch to the "Pause 100" ... to have some visual effect before re-entering sleep ... ( wich is better ...I think)

    Sooo ...

    we add :

    DEFINE INTHAND _BLINK ' near top of program

    and

    BLINK:

    Before

    Pause 100 ' Needed for system Wake-Up
    HIGH LED : PAUSE 200 : LOW LED
    GOTO CYCLE




    I am right, Mel ???

    Alain

    PS: We are aboard PBC list ... what about interrupts in PBC ???
    Last edited by Acetronics2; - 12th May 2007 at 16:14. Reason: PBC or PBP used ???
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post

    "Super Acetronics" - I think he might be right. He should change his name to Supertronics

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Hehe, Trend ...

    You did not know about the Underscored Inthand name ... I presume.

    Permits LOTS of good things, especially if context must not be saved ( what is lots of encountered situations ...).

    Also REALLY Instant Basic Pseudo-Interrupts !!! ( The return adress MUST be explicitly given )

    Alain
    Last edited by Acetronics2; - 12th May 2007 at 15:45.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8
    Join Date
    Sep 2003
    Location
    Vermont
    Posts
    373


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Heuuu

    No GIE = No Sleep ( RTFDatasheet ... $ 14.8.1 - Greyed Note ), so we set GIE Bit

    Then ... Executes the 1St NOP

    Then ... Branches to location 0004 ...

    But there is a supposed Interrupt stubb here instead of falling into the "program" ...

    a single " DEFINE INTHAND INIT " without any interrupt stubb ( LOL ! ) would push the libs away from the 4 first program locations ... and allow restarting the PIC as a first power up ...

    We could also Branch to the "Pause 100" ... to have some visual effect before re-entering sleep ... ( wich is better ...I think)

    Sooo ...

    we add :

    DEFINE INTHAND _BLINK ' near top of program

    and

    BLINK:

    Before

    Pause 100 ' Needed for system Wake-Up
    HIGH LED : PAUSE 200 : LOW LED
    GOTO CYCLE




    I am right, Mel ???

    Alain
    I am using the '690. In that FM, the processor will still wake from sleep if the flag is set without the GIE set. With the GIE set you have to service the interrupt. Without, it starts up right after the sleep command.

    Ron

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink Always a new feature to discover ...

    Hi Ron,

    You're perfectly right with the '690 ... but, care ... GIE settings do not have the same effects for the '628 ... and GIE *must* be set to enter sleep ( sleep ignored if GIE = 0 ) .

    Alain
    Last edited by Acetronics2; - 12th May 2007 at 17:04.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  10. #10
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default

    Hello Ron and Other,

    I did not understand the Int_handler part. You mean to say , declare a Int_handler without a lable and make the pic reset.

    Well setting GIE made it to go to sleep (LED not blinking but current 6mA) but did not come out of it.

    any further help?

    regards

  11. #11
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by charudatt View Post
    Hello Mel,

    I am trying to get this sleep comand to work and it simply does not work.

    my code:
    @ DEVICE PIC16F628A, INTRC_OSC_NOCLKOUT, WDT_OFF, LVP_OFF, PWRT_OFF, PROTECT_OFF, BOD_OFF
    CMCON=7
    VRCON=%01101100 'VRCON bit7 is OFF for no current drain
    OPTION_REG.7 = 0 ' ENABLE INTERNAL PULLUPS
    Trisa = %01111111
    Trisb = %11111111
    LED VAR PORTA.7

    '
    ' PIC Low-Power Sleep Routine
    ' ---------------------------
    '
    ' Set Sleep Interrupts
    ' --------------------
    INTCON=%00011000 ' Interrupt Control Register
    ' 7=0 - GIE - Global Interrupt Enable
    ' 6=0 - PEIE - Peripheral Interrupt Enable
    ' 5=0 - TOIE - TMR0 Overflow Interrupt Enable
    ' 4=1 - INTE - RB0/INT Enable
    ' 3=1 - RBIE - PORTB change interrupt Enable
    ' 2=0 - TOIF - TMR0 Overflow Flag
    ' 1-0 - INTF - RB0/Ext Interrupt Flag
    ' 0=0 - RBIF - PORTB Interrupt Flag
    OPTION_REG.6=1 ' 1=RB0 Rising-Edge Trigger, 0=Falling-Edge Trigger

    CYCLE:
    '
    ' Reset Interrupt Flags
    ' ---------------------
    INTCON.1=0 ' Reset RB0 Flag
    INTCON.0=0 ' Reset PORTB change Flag
    '
    ' Sleep
    ' -----
    LOW LED
    @ SLEEP
    @ nop
    @ nop
    @ nop
    @ nop

    Pause 100 ' Needed for system Wake-Up
    HIGH LED : PAUSE 200 : LOW LED
    GOTO CYCLE

    Maybe I could be missing some thing. The LED just keeps blinking.

    Basically I am trying to incorporate this in a garage code lock project.

    any help ?
    Change the
    OPTION_REG.7 = 0 ' ENABLE INTERNAL PULLUPS
    to
    OPTION_REG.7 = 1 ' DISABLE INTERNAL PULLUPS

Similar Threads

  1. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 10:00
  2. Battery powered applications
    By NavMicroSystems in forum Off Topic
    Replies: 7
    Last Post: - 22nd June 2009, 08:12
  3. Using Sleep
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th August 2008, 05:05
  4. 16F628A current high during sleep
    By Rubicon in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 9th October 2006, 11:21
  5. Wierd sleep issue
    By orca in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 14th March 2006, 23:06

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