Sleep and how to use it


+ Reply to Thread
Results 1 to 8 of 8

Thread: Sleep and how to use it59 days old

  1. #1
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,754
    Thumbs Up
    Received: 51
    Given: 96
    Total Downloaded
    1.33 GB

    0 Not allowed!

    Default Sleep and how to use it

    Hi,

    I need to save power in a device (16f1823) so thought, sleep a lot.

    But I never really used the command before. Reading the data sheet I cannot use an interrupt to wake me, eg a rolling over tmr. There is the Snooze command and would use that. However it never seems to wake. So have been checking settings.

    Config1 FOSC_INTOSC, WDTE_ON, PWRTE_OFF, MCLRE_ON, CP_OFF, CPD_OFF, BOREN_ON, CLKOUTEN_OFF, IESO_ON, FCMEN_ON
    Config2 WRT_OFF, PLLEN_OFF, STVREN_ON, BORV_19, LVP_ON



    Changing the settings to WDT_ON in config makes the device reset during the sleep.

    So I obviously have something wrong and do not understand how to set it up and run it.

    Any pointers?

    Thanks Tim
    Tim

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Senior Member SimonJA's Avatar
    Join Date
    Mar 2006
    Posts
    842
    Thumbs Up
    Received: 14
    Given: 16
    Total Downloaded
    1.03 GB

    0 Not allowed!

    Default Re: Sleep and how to use it

    First set the watchdog timer so that it is controlled by software (config 1 WDTE) and set the timer period.

    Before you want to sleep enable the watchdog timer (SWDTEN).

    Then issue a SLEEP command.

    Disable the watchdog timer when you wake.

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,354
    Thumbs Up
    Received: 83
    Given: 183
    Total Downloaded
    5.30 GB

    0 Not allowed!

    Default Re: Sleep and how to use it

    Another example might be where a battery power key fob used sleep to save power and a irq from a bunch of key depression ioc's

    IOCA = %00110101 ' A5, A4, A2 and A0
    IOCB = %10100000 ' B7 and B5
    SBOREN = 0
    RBIF = 0 ' jic
    RABIE = 1 ' enable ioc interupt
    Sleep
    '
    ' we will stick here till a switch is pressed
    '
    RABIE = 0 ' disable ioc interupt
    SBOREN = 1
    RBIF = 0 ' jic
    IOCA = %00000000 ' A5, A4, A2 And A0
    IOCB = %00000000 ' B7 and B5
    George.

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,754
    Thumbs Up
    Received: 51
    Given: 96
    Total Downloaded
    1.33 GB

    0 Not allowed!

    Default Re: Sleep and how to use it

    Hi, Thanks SimonJA

    I understand now. I made the changes and it still failed however this I just found is due to a bug in my very old version the VSM I'm using that was fixed post my version.

    I'm presuming it will be fine in the silicone when I get the board made.

    Tim
    Tim

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Member kuhrig's Avatar
    Join Date
    Aug 2005
    Posts
    108
    Thumbs Up
    Received: 4
    Given: 0
    Total Downloaded
    4.71 GB

    0 Not allowed!

    Default Re: Sleep and how to use it

    Tim,
    I am using a 16F1939 and use sleep and wake it up from sleep by an interrupt of change (pressing a button) and the watchdog timer.
    There are no problems and it wakes up immediately. Here are the relevant parts of the code.

    Code:
    __Config _Config1, 0x0F1C ;FOSC_INTOSC & WDTE_ON & PWRTE_ON & MCLRE_OFF & CP_ON & CPD_OFF & BOREN_ON & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF
    __Config _Config2, 0x1AEC ;WRT_ALL & VCAPEN_RA6 & PLLEN_OFF & STVREN_ON & BORV_HI & LVP_OFF
    
    '-----------------------------------------------------------------
    ' INTERRUPT ON CHANGE CONFIGURATION
        Set IOCBN.4         ' INTERRUPT ON CHANGE TO NEGATIVE ENABLED
        Set IOCBN.5         ' INTERRUPT ON CHANGE TO NEGATIVE ENABLED
        Clear IOCBF         ' CLEAR FLAGS
    
    Set INTCON.7 ' SET GIE
    Set INTCON.6 ' SET PEIE
    Set INTCON.3        ' SET IOCIE bit   Interrupt enable
    
    Clear IOCBF
    
    While 1 = 1
           WDTCON = 100001 ; 64 sec - wdt always on          
            Sleep
            WDTCON = 010111 ; 2 sec - wdt always on  
            If IOCBF > 0  Then Break
            High LED
            Delayms 50
            Low LED
    Wend
    I'm using the watchdog timer to wake it up after 1 min. to flash an LED. It wakes up immediately when port B.4 or B.5 (pulled up by weak pull-up) changes to negative.
    Hope it helps.
    Last edited by kuhrig; 5th April 2020 at 11:48.

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,754
    Thumbs Up
    Received: 51
    Given: 96
    Total Downloaded
    1.33 GB

    0 Not allowed!

    Default Re: Sleep and how to use it

    Hi,

    Thanks. The snippets are always welcome, I often do a search and find them enabling me to get my coding done quicker.

    Tim
    Tim

  12. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  13. #7
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,354
    Thumbs Up
    Received: 83
    Given: 183
    Total Downloaded
    5.30 GB

    0 Not allowed!

    Default Re: Sleep and how to use it

    @Kuhrig. To confirm I understand your code correctly, PIC will come out of sleep if a button is pressed or 1 minute timeout?

    Please could you repost your code (binary values) and don't subsequently edit it
    George.

  14. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  15. #8
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,596
    Thumbs Up
    Received: 339
    Given: 162
    Total Downloaded
    1.99 GB

    0 Not allowed!

    Default Re: Sleep and how to use it

    If using an external peripheral that cannot be put to sleep, use a small MOSFET to disable its VDD before going to sleep and if using any internal peripherals, disable them before going to sleep and disable any internal pull-up resistors that are enabled, apart from any that are required to wake the device from sleep. I recently did a project that placed the whole board to sleep and it drew 3uA.
    Last edited by top204; 6th April 2020 at 12:19.

  16. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. sleep
    By n.mirzai in forum Projects discussion
    Replies: 11
    Last Post: 24th November 2015, 13:59
  2. Sleep and Sleep X[s] not working on 10F200
    By SebaG in forum Proton Plus Compiler v3
    Replies: 19
    Last Post: 29th October 2015, 08:19
  3. Sleep again
    By dmTulsa in forum Proton Plus Compiler v3
    Replies: 14
    Last Post: 26th September 2010, 16:12
  4. Sleep and Sleep (time) on 16F877A
    By fgcity in forum Proton Plus Compiler v3
    Replies: 1
    Last Post: 17th September 2008, 20:26
  5. [SOLVED !] Sleep
    By RichardN in forum Proton Plus Compiler v3
    Replies: 8
    Last Post: 8th February 2007, 15:39

Posting Permissions

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