PDA

View Full Version : PIC Sleep Tutorial



Heckler
- 9th August 2011, 20:31
Hey group,

One of my favorite websites... www.hackaday.com (http://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

Heckler
- 10th August 2011, 18:18
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!

Heckler
- 10th August 2011, 18:50
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!!

mister_e
- 10th August 2011, 18:58
Amazing what you can find in those boring and useless datasheet huh? :D

Don't give up!

cncmachineguy
- 10th August 2011, 19:00
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

mister_e
- 10th August 2011, 19:10
try this single line


DEFINE READ_THE_DATASHEET WORTH_IT, FOR_ANY_PIC

Demon
- 13th August 2011, 00:28
I always read the datasheets, only problem is that none are in English. :D