Minimizing Power Consumption in Microcontrollers

Published  February 18, 2019   1
Implementing Low Power Consumption in Microcontrollers

Just as gas (petrol/diesel) is important for bikes, trucks and cars (yeah, excluding Teslas!) to move, so is electric power for most of the electronics applications and more so, for embedded system based applications which are usually battery (limited energy) powered, from the regular mobile phones to smart home devices amongst others.

 

The Limited nature of battery power implies the need to ensure the rate of power consumption of these devices should be reasonable to encourage their adoption and use. Especially with IoT based devices where a device could be expected to last for as long as 8 – 10 years on a single charge without battery replacement.

 

These trends has made the implementation of low power considerations in design of embedded systems and over the years, designers, engineers and manufacturers at several point have developed several intelligent ways of effectively managing the power consumed by products, to ensure that they last longer on a single charge.  A lot of these techniques focus on the microcontroller, which is the heart of most of the devices. In today’s article, we will be exploring some of these techniques and how they can be used to minimize power consumption in microcontrollers. Although a Microprocessor consumes less power but it can be used in placed on Microcontroller everywhere, follow the link to learn how Microprocessor is different from Microcontroller.

 

Power Saving Techniques for Microcontrollers

1. Sleep Modes

The sleep modes (generally referred to as low power modes) are arguably the most popular technique for reducing the power consumption in microcontrollers. They generally involve disabling of certain circuitry or clocks that drives certain peripherals of the microcontrollers.

 

Depending on the architecture and manufacturer, microcontrollers usually have different kind of sleep modes, with each mode possessing the ability to disable more internal circuitry or peripheral compared to the other. Sleep modes usually range from deep sleep or off, to idle and doze modes.

 

Some of the available modes are explained below. It should be noted that the characteristics as well as name of these modes may vary from manufacturer to manufacturer.

Sleep Mode

 

i. Idle/Sleep Mode

This is usually the simplest of the low power modes for designers to implement. This mode allows the microcontroller to return to full operation at a very fast rate. It is therefore not the best mode, if the power cycle of the device, requires it to leave the sleep mode very often, as a large amount of power is drawn, when the microcontroller exits the sleep mode. Return to active mode from standby mode is usually interrupt based. This mode is implemented on the microcontroller by turning off the clock tree that drives the CPU circuitry while the MCU primary high-frequency clock is kept running. With this, the CPU is able to resume operations immediately the wake-up trigger is activated. Clock gating has been employed extensively to cut off signals in low power modes for microcontrollers and this mode effectively gates clock signals across the CPU.

 

ii. Standby Mode

Standby Mode is another low power mode, easy for designers to implement. It is very similar to idle/sleep mode as it also involves the use of clock gating across the CPU, but one major difference is it allows change in the content of the ram which is not usually the case with the idle/sleep mode. In Standby mode, high-speed peripherals like the DMA (direct memory access), Serial Ports, ADC and AES peripherals are kept running to ensure they are available immediately after the CPU is awake. For certain MCUs, the RAM is also kept active and can be accessed by the DMA allowing data to be stored and received without CPU intervention. Power drawn in this mode can be as low as 50uA/MHZ for low power microcontrollers.

 

iii. Deep Sleep Mode

Deep sleep mode, generally involves the disabling of high frequency clocks and other circuitries within the microcontroller leaving only the clock circuitry used to drive critical elements like the watchdog timer, brown out detection and the power on reset circuitry. Other MCUs may add other elements to it to improve the overall efficiency.  Power consumption in this mode can be as low as 1uA depending on the particular MCU.

 

iv. Stop/ OFF Mode

Certain microcontrollers have different variations of this additional mode. In this mode, both the high and low oscillators are usually disabled leaving only some configuration registers and other critical elements on.

 

The features of all the sleep modes mentioned above differ from MCU to MCU but the general rule of thumb is; the deeper the sleep, the more the number of peripherals disabled during sleep, and the lower the amount of power consumed, although, this usually also means; the higher the amount of energy consumed to get the system back up. It is thus up to the designer to consider this variation and choose the right MCU for the task without making compromises that affects the specification of the system.

 

2. Dynamic Modification of Processor Frequency

This is another widely popular technique for efficiently reducing the amount of power consumed by a microcontroller. It is by far the oldest technique and a little more complicated than the sleep modes. It involves the firmware dynamically driving the processor clock, alternating between high and low frequency as the relationship between the frequency of the processor and the amount of power consumed is linear (as shown below).

 

The implementation of this technique usually follows this pattern; when the system is in an idle state, the firmware sets the clock frequency to a low speed allowing the device to save some power and when the system needs to do heavy computations, the clock speed is brought back up.

 

There are counterproductive scenarios to modifying processor frequency which is usually as a result of badly developed firmware. Such scenarios arise when the clock frequency is kept at a low while the system is performing heavy computations. A low frequency in this scenario means the system will take more time than necessary to perform the set task and will thus accumulatively consume the same amount of power the designers were trying to save. Thus, extra care must be taken when implementing this technique in time critical applications.

Dynamic Modification of Processor Frequency

 

3. Interrupt Handler Firmware Structure

This is one of the most extreme techniques of power management in microcontrollers. It is made possible by few microcontrollers like, the ARM cortex-M cores which have a sleep-on-exit bit in the SCR register. This bit provides the microcontroller with the ability to sleep after running an interrupt routine. While there is a limit to the number of applications that will run smoothly in this manner, this could be a very useful technique for field sensors and other, long-term, data gathering based applications.

 

Most of the other techniques in my own opinion are variations of the ones already mentioned above. For example the selective peripheral clocking technique is essentially a variation of the sleep modes in which the designer selects the peripherals to turn on or off. This technique requires a deep knowledge of the target microcontroller and may not be very beginner friendly.

 

4. Power Optimized Firmware

One of the best ways of reducing the amount of power consumed by a microcontroller is by writing efficient and well optimized firmware. This directly affects the amount of work done by the CPU per time and this, by extension contributes to the amount of power consumed by the microcontroller.  Efforts should be made while writing the firmware to ensure reduced code size and cycles as every unnecessary instruction executed, is a portion of the energy stored in the battery being wasted. Below are some common C based tips for optimized firmware development;

  1. Use the “Static Const” Class as much as possible to prevent runtime copying of arrays, structures etc. that consumes power.
  2. Use Pointers. They are probably the most difficult part of the C language to understand for beginners but they are the best for accessing structures and unions efficiently.
  3. Avoid Modulo!
  4. Local variables over global variables where possible. Local variables are contained in the CPU while global variables are stored in the RAM, the CPU accesses local variables faster.
  5. Unsigned data types are your best friend where possible.
  6. Adopt “countdown” for loops where possible.
  7. Instead of bit fields for unsigned integers, use bit masks.

 

Approaches for reducing the amount of power consumed by a microcontroller are not limited to the software based approaches mentioned above, hardware based approaches like the core voltage control technique, exist, but to keep the length of this post within a reasonable range, we will save them for another day.

 

Conclusion

Implementing low power product starts from the choice of microcontroller and it can be quite confusing when you try to go over the diverse options available in the market. While scanning through, the datasheet may work well for obtaining the general performance of MCUs, but for power critical applications, it can be a very costly approach. To understand the true power characteristics of a microcontroller, developers must take into account the electrical specifications and the low power functionalities available to the microcontroller. Designers should not only be concerned about current consumption by each of the power modes advertised by the MCU’s datasheet, they should look into the wake-up time, wake-up sources, and peripherals that are available for use during the low power modes. 

 

It is important to check the features of the microcontroller you plan to use to ascertain the options you have for low power implementation. Microcontrollers have been one of the largest beneficiaries of technology advancement and there are now several ultra-low-power microcontrollers which ensure you have resources to help you stay within your power budget. A number of them also provide several power analysis software tools which you can take advantage of, for effective design. A personal favourite is the MSP430 line of microcontrollers from Texas Instrument.

Have any question realated to this Article?

Ask Our Community Members

Not just the MCU but the whole circuit needs to be designed for low power consumption.

Various things that need to be considered are:

1. Operating voltage of the circuitry

2. Operating voltage of power-hungry devices

3. Selection of components/chips ( ADC, DAC, Relays, etc.)

4. Other Interface Modules

5. Power gating the peripherals (ON/OFF control)

6. Power Supply

7. LED

8. Display

9. Pull-ups

10. Microcontroller (Software Control)

In order to optimize power consumption, a measuring tool is very critical. You need to have a Joulescope kind of tool if you are seriously building a very low-power embedded product.

You can read the above points in more detail in my article: https://pallavaggarwal.in/10-tips-for-low-power-embedded-system-design/. Hope you will find it useful.

 

If you need any help in embedded system design optimization for power, cost, size, reliability, do contact me at [pallav.aggarwal at Gmail dot com]

Thank you

Pallav Aggarwal