Permanent sleep


Closed Thread
Results 1 to 40 of 59

Thread: Permanent sleep

Hybrid View

  1. #1
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107

    Question Permanent sleep

    This is my first PIC project. I am using PBC with a 16F627A. Sleep is defined for periods from 1 to 65535, but what happens if I use SLEEP 0? I want the PIC to go into low power mode until power is cycled off and on. If I let the program go to END, is that equivalent to sleep?

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    no, and it will be in low current consumption.

    BTW, who'll know that if you set the SLEEP to it's maximum and do a loop... few usec in hours in not low consumption...
    Code:
    GoodNight:
        SLEEP 65535
        goto GoodNight
    Last edited by mister_e; - 19th January 2006 at 02:10.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    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...

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

  5. #5
    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 13: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 " !!!
    *****************************************

  6. #6
    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.

  7. #7
    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, 09:00
  2. Battery powered applications
    By NavMicroSystems in forum Off Topic
    Replies: 7
    Last Post: - 22nd June 2009, 07:12
  3. Using Sleep
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th August 2008, 04:05
  4. 16F628A current high during sleep
    By Rubicon in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 9th October 2006, 10:21
  5. Wierd sleep issue
    By orca in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 14th March 2006, 22: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