ABC of Electronics cosycom.com
PIC BASICS · LESSON 19

Sleep Modes & Power Management

A microcontroller that never sleeps wastes power it often doesn't need to spend. Sleep modes let it pause almost everything until something worth waking up for happens.

Many PIC projects run on batteries, where every microamp of current matters. Running the CPU at full speed constantly, even while waiting for a button press that might come once an hour, wastes power for no benefit. PIC chips address this with one or more sleep modes — low-power states that shut down most of the chip's activity until a specific event wakes it back up.

In full sleep mode, the CPU stops executing instructions entirely and the main oscillator is halted, cutting power consumption dramatically — often to a small fraction of the chip's normal running current. The chip remains in this state indefinitely until a wake-up source occurs: commonly, a change on an external interrupt pin, a watchdog timer timeout, or (on some chips) a scheduled timer event from a separate, always-on low-power oscillator.

Typical wake-up sources from sleep
SourceTypical use case
External interrupt pinWake instantly when a button is pressed
Watchdog timer timeoutWake periodically to take a reading, then sleep again
UART receiveWake when data starts arriving from another device

A common battery-powered pattern is to spend nearly all of the chip's life asleep, waking briefly on a timer to take one sensor reading, act on it if necessary, and immediately return to sleep — repeating that cycle indefinitely. Done well, this can stretch a small battery's life from days to months or longer, because the "awake" portion of each cycle might last only a few milliseconds out of every several seconds.

main.c — sleep, wake on a timer, take a reading, repeat
void main(void) {
    // (watchdog timer configured elsewhere to wake the chip periodically)
    while(1) {
        unsigned int value = read_adc();
        if (value > THRESHOLD) {
            LATB0 = 1;          // e.g. sound an alarm
        }
        SLEEP();                // go back to sleep until next wake-up
    }
}
KEY TAKEAWAY
Sleep modes turn "always on" into "on only when it matters" — the single biggest lever for extending battery life in a microcontroller project.