Permanent sleep


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 59

Thread: Permanent sleep

  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,614


    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
    May 2004
    Location
    NW France
    Posts
    3,614


    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 15: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 " !!!
    *****************************************

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

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


    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 14: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 " !!!
    *****************************************

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

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


    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 16: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 " !!!
    *****************************************

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

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    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
    I did check the '628 book and you are correct sir! I reread it twice to catch it.
    Ron

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

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


    Did you find this post helpful? Yes | No

    Post

    Hi, Charudatt

    Do not worry !!! This is certainly one of the least documented feature of PBP ...

    DEFINE INTHAND _INTER ...

    1) keeps prog mem locations 2 and 3 free ...

    2) places a GOTO _INTER at location 4 ... or a bit further if more than 1 program page ...and COULD need context saving.
    _INTER ( Note the Leading Underscore ) is the PBP "INTER:" Label readable by Assembler ...

    Consider it as a "classical" GOTO ... but you reach it when an "interrupt reason" occurs ... no latency then.

    INIT (Without Underscore !!! ) is the first ASSEMBLER line your Program really executes at power ON ...

    So, as is ... you can i.e. restart your PIC, ... without using MCLR - if not disposable !!!
    ... or goto the label you want !!!

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Allain,
    I was right. Clearing GIE does work as it does on the '690. It will wake and continue without needing an interrupt handler.

    Ron

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


    Did you find this post helpful? Yes | No

    Default

    <table><td>Vermont : 1
    France : 0</td><td></td></table>
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Ron Marcus View Post
    Allain,
    I was right. Clearing GIE does work as it does on the '690. It will wake and continue without needing an interrupt handler.

    Ron
    What about ENTERING sleep ??? 628A datasheet clearly says IF GIE = 0 , the SLEEP command is treated as a NOP ...

    I'm a bit confused here ... or I do not have the latest datasheet !!!

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    The little window says if GIE is 0 and both the flag bit and enable bit are set, it will treat the sleep command as a nop. If the flag bit is cleared, it will sleep. It IS confusingly written!

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


    Did you find this post helpful? Yes | No

    Default It does not work

    ALAIN,

    It still does not work,

    "DEFINE INTHAND INIT" , maybe puts it to sleep and never comes out.
    and "DEFINE INTHAND _BLINK" keeps the led blinking.

    regards

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


    Did you find this post helpful? Yes | No

    Wink The last ?

    Hi, RON

    Ok, Thanks for the explanation ...

    It really might be written instead of BUT ... : AND any interrupt ... !!!

    So, appears no real need to set the GIE bit here ...


    Back to Charudatt's program ...


    mighn't there be a PORTB reading ... ( to end the "mismatch condition" ) ???.

    Alain

    Charudatt :

    1) DEFINE ...INIT ... the result is quite normal !!! Pic wakes up to fall asleep ...

    2) if the led keeps blinking means ... the program always stay in the interrupt stubb !!! We've traced it now.

    in this case ... interrupt flags are not cleared ... : good reason, no ?
    Last edited by Acetronics2; - 13th May 2007 at 10:54.
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Talking Finally GOT it !!!

    Hi, Charudatt

    Straight from my test bench :


    @ __CONFIG _INTOSC_OSC_NOCLKOUT & _WDT_OFF & _LVP_OFF & _PWRTE_OFF & _CP_OFF & _BODEN_OFF

    DEFINE NO_CLRWDT 1
    DEFINE LCD_EBIT 1

    CMCON=7
    VRCON=%01101100 'VRCON bit7 is OFF for no current drain
    OPTION_REG.7 = 1 ' DISABLE INTERNAL PULLUPS
    Porta = 0
    PORTB = 0
    Trisa = %11111111
    Trisb = %01111111

    LED VAR PORTB.5
    SleepLed var PORTB.7
    Dummy var byte

    '
    ' PIC Low-Power Sleep Routine
    ' ---------------------------
    '
    ' Set Sleep Interrupts
    ' --------------------
    INTCON=%00010000 ' 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=0 - 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

    PAUSE 500
    LCDOUT $FE,1
    CYCLE:
    '
    ' Reset Interrupt Flags
    ' ---------------------
    INTCON.1=0 ' Reset RB0 Flag
    INTCON.0=0 ' Reset PORTB change Flag
    '
    ' Sleep
    ' -----
    LOW LED


    LCDOUT $FE,2 , "*** SLEEPING ***"
    High Sleepled

    @ SLEEP

    Dummy = PORTB
    LOW SleepLed
    @ nop
    @ nop
    @ nop

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

    LCDOUT $FE,1, " HURRY UP "

    PAUSE 5000
    LOW LED

    GOTO CYCLE

    END

    CONFIG Modified to suit MPLAB Requirements ...

    I used a LCD to show what happening and fixed LEDs for Wake (green) /Sleep ( Red ) states ...

    disabled CLRWDT PbP insertions ... ( a passing idea ??? )

    also disabled the WPU ... but that is not problematic.

    also changed LEDs PORTs ...

    As PORTB was used ... I did not try "Interrupt change on PortB" ... but works great with B.0 interrupt.

    Works fine ... as you intended to program it !!!

    Regards

    Alain
    Last edited by Acetronics2; - 13th May 2007 at 14:11.
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default Thanks

    I'll give it a shot tomorrow and post my feedback.

    regards

    p.s. Today after the failed experiments, i am planning the same thing on 16F73. Lets hope it works. I shall post my feedback on both tomorrow.
    Last edited by charudatt; - 13th May 2007 at 17:16.

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


    Did you find this post helpful? Yes | No

    Wink A Beer aside for me ...

    Hi, Charudatt



    @ __CONFIG _INTOSC_OSC_NOCLKOUT & _WDT_OFF & _LVP_OFF & _PWRTE_OFF & _CP_OFF & _BODEN_OFF

    DEFINE NO_CLRWDT 1

    CMCON=7
    VRCON=%01101100 'VRCON bit7 is OFF for no current drain
    OPTION_REG.7 = 0 ' ENABLE INTERNAL PULLUPS
    Porta = 0
    PORTB = %11110001
    Trisa = %11110011
    Trisb = %01111111

    LED VAR PORTA.2
    SleepLed var PORTA.3
    Dummy var byte

    '
    ' 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=0 ' 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

    High Sleepled

    @ SLEEP
    @ nop

    Dummy = PORTB
    LOW SleepLed
    @ nop
    @ nop
    @ nop

    Pause 100 ' Needed for system Wake-Up

    HIGH LED

    While ( PORTB >> 4 ) <> %00001111 ' Wait Key release
    Wend ' AND a PORTB Reading ...!!!

    PAUSE 200

    PAUSE 5000
    LOW LED

    GOTO CYCLE

    END


    Here it is with PORTB interrupts ... ( Note I modified all inputs to be active LOW ...)

    I think the origin of the problem is you forgot to read PORTB for the end of the mismatch condition ... wich Also locks the flag cancelling ( a RTFDatasheet for me ... )

    Heuuuuu, CHILLED, the beer, please !!!

    Alain

    PS : The interrupt way also works well ... if you're intersted in, I'll post it.
    Last edited by Acetronics2; - 13th May 2007 at 18:14.
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    The original program example I posted way back during another life is valid for the non-A version of the 16F62X. In the non-A version you get a wake from sleep regardless of the state of the GIE bit. However, the operation of the GIE bit differs in the A version in that respect and Alain is correct. It teaches us all a lesson here that some of the changes between PIC versions are seriously subtle! So it's read the Datasheet - thoroughly!

  26. #26
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    So it's read the Datasheet - thoroughly!
    Not another RTFD?!?!
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default Cheers for Beer.

    Alain

    PS : The interrupt way also works well ... if you're intersted in, I'll post it.[/QUOTE]

    Thank you very much, I am just dying to test it out.

    Yes Chilled beer for sure.

    Post the Interrupt way code, if you can, Thank you once again.

    regards

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


    Did you find this post helpful? Yes | No

    Default

    Hey Mel,
    I read the data sheet on the A version. It says on page 111 that the PIC will wake from sleep if both the flag and interrupt bits are set. Will it not wake from sleep if the flag bit is set after initiating sleep? I don't see where it discusses this.

    Ron

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


    Did you find this post helpful? Yes | No

    Default

    I'm talking about the GIE bit here. In the A version, if GIE is not set, the SLEEP (the Assembler instruction) is treated as a NOP and the PIC never enters SLEEP. This didn't work that way in the non-A version. I've a (fortunately) obsolete product that used that feature... otherwise I'd be scratching my head trying to figure why the product didn't work as expected!

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


    Did you find this post helpful? Yes | No

    Post The interrupt Way

    Hi, Charudatt

    Here it is :





    @ __CONFIG _INTOSC_OSC_NOCLKOUT & _WDT_OFF & _LVP_OFF & _PWRTE_OFF & _CP_OFF & _BODEN_OFF

    DEFINE NO_CLRWDT 1
    DEFINE INTHAND _Blink


    CMCON=7
    VRCON=%01101100 'VRCON bit7 is OFF for no current drain
    OPTION_REG.7 = 0 ' ENABLE INTERNAL PULLUPS
    Porta = 0
    PORTB = %11110001
    Trisa = %11110011
    Trisb = %11111111

    LED VAR PORTA.2
    SleepLed var PORTA.3
    Dummy var byte

    '
    ' PIC Low-Power Sleep Routine
    ' ---------------------------
    '
    ' Set Sleep Interrupts
    ' --------------------
    INTCON=%10011000 ' 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 = 0 ' 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
    INTCON.7 = 1
    '
    ' Sleep
    ' -----
    LOW LED

    High Sleepled

    @ SLEEP
    @ nop

    Blink:

    Dummy = PORTB
    Pause 100 ' Needed for system Wake-Up

    LOW SleepLed

    HIGH LED

    While ( PORTB >> 4 ) <> %00001111
    Wend

    PAUSE 200

    PAUSE 5000
    LOW LED

    GOTO CYCLE

    END



    As you see it's not so different from the "non interrupted" way ...

    But, IF I correctly understand Mel ( one more time, Mel : You're the one and Only ... !!! - no sexual meanings hidden ( LOL) ) , the interrupt way could fit both 628 and 628A ...

    I must say I used a 16F628-04 batch N° 0145H9F for tests ( I do not have any 628A ... but will run a try with a brand new 648A.

    ********************************************
    ********************************************
    A little "bug" in the "non interrupted" listing ... to correct:

    TRISB must be % 11111111 ... instead of % 01111111

    I was wondering why PortB.7 was inactive .... LOL !!!


    Have fun, and read you soon

    regards

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Talking Humour ...

    Those who really followed this thread have surely noticed there could have been other lines inserted between :

    @ SLEEP
    @ nop

    AND ...

    Blink:

    didn't you ??? ....

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

  32. #32
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Smile How about this

    Quote Originally Posted by Acetronics View Post
    Those who really followed this thread have surely noticed there could have been other lines inserted between :

    @ SLEEP
    @ nop

    AND ...

    Blink:

    didn't you ??? ....

    Alain
    Hello Alain,

    Do you mean:
    @ SLEEP
    @ nop
    snore
    Blink:
    turn-over
    @ SLEEP

    Then again, sometimes I "just don’t quite get it"...
    -Adam-
    Ohm it's not just a good idea... it's the LAW !

  33. #33
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Gotta get new glasses.

    @nap

    Did not work
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Wink

    <body onload="setInterval('blinkIt()',1000)">

    <script type="text/javascript">
    function blinkIt() {
    if (!document.all) return;
    else {
    for(i=0;i<document.all.tags('blink').length;i++){
    s=document.all.tags('blink')[i];
    s.style.visibility=(s.style.visibility=='visible') ?'hidden':'visible';
    }
    }
    }
    </script>

    <blink>@ NOP</blink>

    @nap will just define a label
    nap without the @, is a PBP function, and it's not the same as ASM
    <blink>@ NOP</blink>
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    A half hearted compile of your code (Alian) for the 16F873A gave an error with DEFINE INTHAND _Blink.

    I changed it to DEFINE INTHAND Blink and it did not come out of sleep (I presume) the same code compiles OK for the 16F628A.

    I am sorry , I was busy with some other job, but today I shall try your code for the intended chip and post results.

    Thank you for all your help,

    regards

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


    Did you find this post helpful? Yes | No

    Talking Rtfm !!!

    Hi, Charudatt

    See chapter 9.3 ...

    your device ( 16F873 ) has two mem. pages ... 16F628 only has ONE.

    What does PbP for ASM Interrupts ???

    What do you have to reserve as variables room ???


    TWO beers now !!!

    Cheers

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Talking

    Quote Originally Posted by Pic_User View Post
    Hello Alain,

    Do you mean:
    @ SLEEP
    @ nop
    snore
    Blink:
    turn-over
    @ SLEEP

    Then again, sometimes I "just don’t quite get it"...
    -Adam-
    Hi, Adam

    Snore never happens ... might be a LABEL to call before !!!

    Alain
    Last edited by Acetronics2; - 15th May 2007 at 09:55.
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    <body onload="setInterval('blinkIt()',1000)">

    <script type="text/javascript">
    function blinkIt() {
    if (!document.all) return;
    else {
    for(i=0;i<document.all.tags('blink').length;i++){
    s=document.all.tags('blink')[i];
    s.style.visibility=(s.style.visibility=='visible') ?'hidden':'visible';
    }
    }
    }
    </script>

    <blink>@ NOP</blink>

    @nap will just define a label
    nap without the @, is a PBP function, and it's not the same as ASM
    <blink>@ NOP</blink>
    C'mon Mister_e, you can do better than that! - show us all some of your "real" java skills, like scrolling some 3D text with user definable parameters.

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


    Did you find this post helpful? Yes | No

    Default

    euh... sorry i don't have any Java skills... i just copy/paste some script here and there.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Post

    I'm about to start a Java unit soon - maybe I'll teach you a thing or two Out of interest, I've just found some good code for VB that allows serial comms without MSCOMM.ocx !!! http://www.thescarms.com/VBasic/commio.aspx No probs in XP either.

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 : 1

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