Using Power saving mode of microcontroller efficiently


Whether they’re used in washing machine, refrigerator, smart meters or mobile health monitoring products, microcontrollers are at the heart of almost every real-time product. In many of these product the microcontrollers relies on sophisticated sleep mode techniques that suspend most or all of its operations to minimize energy consumption, allowing it to run for years or even decades on limited energy sources.

These real-time low-energy environments pose special challenges for the designer and programmer because the same sleep states that reduce an MCU’s energy consumption often also reduce its ability to quickly respond to an event.

So this article is specially targeted to low power consumption modes. Low-power modes typically range from a light sleep or standby mode, through deep-sleep, to off. Each of these mode is working separately according to designed by that particular silicon vendor. But most of them are common to some kind of level in which CPU, I/O or some peripheral are switched according to need.

Well this mode basically includes saving energy during idle time of processor and during power down time of processor. These are almost importance in making power saving devices.

Different Low Power Modes

  • Idle mode or sleep mode is when CPU is stop while all on chip peripherals are ON Such as internal SRAM, timers, serial port and interrupts. In this mode oscillator continues providing clock to serial port, timer, interrupt, but no clock is provided to the CPU. Notice that during this mode all the register and RAM contents remain unchanged.
  • A Power-Save mode allows the asynchronous real-time counter to run so that the application can maintain a timer base while the rest of the chip is sleeping.
  • In Power down mode, the on chip oscillator is stop which cuts of frequency to the CPU and the Peripheral functions such as timer, serial ports and interrupts. This mode brings power consumption down to an absolute minimum and the contents of SRAM and registers are saved and remain unchanged.
  • In Standby mode, the crystal oscillator run its operation while the rest of the chip is sleeping. By allowing the oscillator to run, the chip achieves a very fast startup.

Here is simple 8051 based example how to run multiple task with power saving mode. Some developer finds little bit complex to use different low power mode.

Program Explanation

  • As you can see, first we have to write code for generating 1 millisecond(you can choose according to your choice, as small as ISR time as fast as our program execution be) timer interrupt in auto-reload mode which means timer will generate interrupt at every 1 millisecond.
  • Now we have to divide our tasks and perform it within 1 millisecond in interrupt service routine of timer as you can see.
  • We can not use any loops like for, while, do-while which takes more time and our over all time of all tasks not been more than 1 millisecond otherwise our code can stuck due to recursive call of interrupt and at the end stack will overflow.
  • So we can control GPIO with conditional statement like switch, if, if-else, etc within timer ISR and program special peripherals like UART, ADC, SPI, etc by their interrupt routines.

                       So this is simple example of power saving mode, there are many techniques to use these different modes according to your customization and code complexity.


If you like this Article, then don’t forget to Click on Social likes buttons.