Depths of sleep

Many microcontrollers offer several low-power states of different depth. A light sleep stops only the CPU clock while the peripherals keep running, so execution can resume immediately. Deeper states also stop the high-speed oscillators and the PLL and put the regulator into a low-power mode, keeping only the contents of RAM and registers. The deepest states switch off most of the power, and on waking the program starts from the beginning as it does after a reset. Names vary between manufacturers; the deeper the state, the lower the current and the longer the wake-up time.

Entering and leaving sleep

On Arm Cortex-M processors, sleep is entered with the WFI or WFE instruction, and the SLEEPDEEP bit in the System Control Register selects deep sleep. Wake-up sources are interrupts from a low-power timer or an RTC alarm, a pin change, received communication and so on. Waking from a deep state takes extra time while the oscillator stabilizes. After waking from the deepest state, the firmware checks the reset-cause flags to tell it apart from a power-on.

Keeping the current low

Battery life depends on the average of the current while running and while sleeping, so the basic rule is to finish the work quickly after waking and go straight back to sleep. Even during sleep, extra current flows if the clocks of unused peripherals are left running or if unconnected input pins are left floating. Pin settings are therefore reviewed and unneeded circuits stopped before sleeping. Some microcontrollers cannot enter deep sleep while a debugger is attached.

Try it: questions about Sleep mode

What is the main purpose of using a microcontroller's sleep mode in a battery-powered embedded device?

  1. ATo increase processing speed
  2. BTo stop the CPU and clocks when idle to cut power, waking only when needed, for example on an interrupt
  3. CTo erase the program
Show answer and explanation

Answer: B. To stop the CPU and clocks when idle to cut power, waking only when needed, for example on an interrupt

A device that reads a sensor once every few seconds has nothing to do most of the time. Sleep mode stops the clocks or power to the CPU and unused peripherals, cutting the current; in deep sleep, some microcontrollers draw only microamperes or less. A timer or pin-change interrupt wakes it, and it goes back to sleep as soon as the work is done. Deeper sleep draws less current but takes longer to wake and loses more state.

Books on Embedded Systems & Firmware Ad

Learn hands-on: parts and kits

Building real circuits is a good way to check what you learned in the questions.

As an Amazon Associate I earn from qualifying purchases.

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary