Power efficiency is more important now than in the past, as portable, battery-powered devices compete for market share on features and battery life. Battery technology has not improved radically in the recent past, and attempts at innovation can wreak havoc with overheated batteries that sometimes burst into flames. Therefore, using less energy to do more tasks is a safe but tedious route to better power efficiency.
Use Efficient Code
There are several ways to reduce power consumption. One is to write very efficient code. One can do more with fewer instructions, careful planning, and by optimizing the compiler. A compiler optimized for maximum speed produces different results than the same compiler set for minimum code size for lower power consumption. Where possible, remove unnecessary instructions and code for fewer clock cycles to achieve the same objective. One unnecessary step that executes several times a minute adds up. There are code analysis tools built specifically for low power development, such as the ultra low power ULP Advisor, a free tool for MSP43x MCUs from Texas Instruments. The ULP Advisor compares code against a ULP checklist and comes as part of Code Composer Studio (v 5.0 and higher). The ULP Advisor is also integrated into the IAR Embedded Workbench. Those not using MSP430s can take advantage of the ULP Advisor Rule Table, which lists common sense rules such as terminating unused GPIOs, using local instead of global variables when possible, and avoiding processor-intensive operations such as divide or floating point operations.
Use Low Power Modes
Assuming that you are using an ultra-low-power MCU, another way to lower total power consumption is to take full advantage of the flexibility offered by the many sleep states that ultra-low power MCUs now offer. Some MCUs have 6 or more different states of operation, which helps if the time it takes for your MCU to wake up matters, even if it’s only microseconds.
Microchip PIC controllers have a “doze” mode where the core and FLASH operate at a slower clock rate than normal and peripherals, the voltage regulator, and RAM are all kept in an active state. In idle mode, the core and FLASH are turned off. Sleep mode goes a bit further, and core, FLASH, and any peripherals that depend on the system clock are turned off at the cost of tens of microseconds to wake-up. A longer term type of sleep mode is for when longer latencies are acceptable, and is called “low voltage sleep” by Microchip Technology. Low voltage sleep takes it a step further by reducing the current output of the regulator. By maintaining a low-current, low-voltage sleep mode, it maintains RAM readiness and an optional real-time clock, watchdog, or another timer. Deep Sleep mode does not preserve RAM readiness, where the device takes time (and consumes power) to wake by going through a restart sequence upon wake-up. Deep sleep mode has most of the MCU turned off except for interrupt handling, an RTC, or a timer. A free Battery Life Estimator Tool is available from Microchip Technology that helps with designing an application with a limited power budget, be it peak power or total battery life limitations.
Common sense prevails. Don’t poll for event flags if your MCU has an integrated peripheral that can be used to wake up the CPU instead. Take advantage of Idle mode when waiting for an interrupt. Check to see if on-chip peripherals have power-saving features. The more you know about your power budget and the details of how your design or application operates, the more you will be able to take advantage of all that modern chips and tools have to offer.
Leave a Reply