+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    288

    Default PIC Sleep Tutorial

    Hey group,

    One of my favorite websites... www.hackaday.com has a link to an article about PIC Sleep modes and how to use.

    Here is a link to the article... http://embedded-lab.com/blog/?p=3237

    His program is in C, but there is plenty of info.

    Take a look if you want another view on PIC Sleep.

    dwight


    Hi, we are pleased to see that you are using our forum.

    We'd like you to become a member of our community. Membership is FREE, please REGISTER and view our forums without these annoying reminders!

    Once registered you may post on the forums, download from the file areas and use the WIKI without interruption.




    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  2. #2
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    288

    Default Re: PIC Sleep Tutorial

    The following two statements helped me, finally, to understand how to use the WDT to wake my PIC from SLEEP and to make the SLEEP period as long as I need.

    Several events can make the device wake up from the sleep mode:
    1. Any device reset.
    2. Watchdog Timer Wake-up (if WDT was enabled).


    3. Any peripheral module which can set its interrupt flag while in sleep, such as:
    • External INT pin
    • Change on port pin
    • Comparators
    • A/D conversion
    • Timer1
    • LCD
    • SSP
    • Capture, etc.
    The first event (device reset) will reset the device upon wake-up. However the latter two events will wake the device and then resume program execution. When the SLEEP instruction is being executed, the next instruction (PC + 1) is pre-fetched, so that on wake-up the processor could execute the next instruction after the SLEEP command. For the device to wake-up through an interrupt event, the corresponding interrupt enable bit must be set (enabled). Wake-up is regardless of the state of the GIE bit. If the GIE bit is clear (disabled), the device will just wake up from sleep and continues executing the program from the instruction right after the SLEEP command. If the GIE bit is set (enabled), the processor will execute the instruction after the SLEEP instruction and then branches to the interrupt address (0004h). Therefore, if an interrupt is to be used just to wake up the PIC microcontroller, the GIE bit must be cleared before the sleep instruction.

    In PIC16F628A microcontroller, the use of Sleep mode with WDT wake-up provides a maximum sleep duration of 2.3 sec. But if your data logger design requires a longer sampling interval between two successive data samples and you want to put the microcontroller into Sleep mode during most of this interval, you can use multiple SLEEP instructions in sequence. When the microcontroller wakes up from the first sleep by WDT time-out, it resumes normal operation and executes the next instruction. If it finds another SLEEP instruction, it will reset the WDT and go back to Sleep mode again, thus prolonging the sleep duration.
    I've been working with these PIC's for a couple of years now... and I guess mabie I need to change my signature to say...

    "These PIC's are like Elephants... you can't eat the whole beast in one sitting, but rather ONE bite (byte?) at a time, over many sittings."

    I now have my little project waking up every 60 seconds, checking the temperature, and then going happly back to sleep.

    Sweeeeeet!
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  3. #3
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    288

    Default Re: PIC Sleep Tutorial

    I also found, by reading the data sheet (no there's a concept), that for the PIC's I am using, 16F690 and 16F1828, that there is a WDT prescaler that would allow me to adjust the WDT timeout period from 1ms to over 4 minutes!!
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,896

    Default Re: PIC Sleep Tutorial

    Amazing what you can find in those boring and useless datasheet huh?

    Don't give up!
    Steve

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

  5. #5
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    875

    Default Re: PIC Sleep Tutorial

    Dwight, Thats GREAT. Its always fun to here someone has made a breakthrough (for them at least). Understanding how the WDT interacts with the rest of the PIC is a challange. But once the light bulb turns on- everything is just a little clearer.

    But just 1 question, What on earth would comple you to
    reading the data sheet
    hahahahahahahaha
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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

    Default Re: PIC Sleep Tutorial

    try this single line
    Code:
    DEFINE READ_THE_DATASHEET WORTH_IT, FOR_ANY_PIC
    Steve

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

  7. #7
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    1,780

    Default Re: PIC Sleep Tutorial

    I always read the datasheets, only problem is that none are in English.
    Robert
    Not as dumb as yesterday, but stupider than tomorrow!

Members who have read this thread : 7

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