Friday, March 11, 2022

How to put the MCU into sleep state and see how much power consumption can be saved?

The best way to explore low-power modes is to choose a microcontroller and actually run the processor in various low-power modes. For this article, I decided to dig out the dusty NXP Kinetis-L Freedom board that I have used not only for experiments, but also for many products, applications, and courses. Rightly or wrongly, I decided to measure not only the energy consumption of the microcontroller, but the energy consumption of the entire development board. The MCU is usually one of the biggest power consumers on the board, but measuring the current of the entire system often reminds me that it’s not the only power-hungry device on the board.Microcontroller optimization comes a long way, but it’s not the only

Low power mode experiment

The best way to explore low-power modes is to choose a microcontroller and actually run the processor in various low-power modes. For this article, I decided to dig out the dusty NXP Kinetis-L Freedom board that I have used not only for experiments, but also for many products, applications, and courses. Rightly or wrongly, I decided to measure not only the energy consumption of the microcontroller, but the energy consumption of the entire development board. The MCU is usually one of the biggest power consumers on the board, but measuring the current of the entire system often reminds me that it’s not the only power-hungry device on the board. Microcontroller optimization is a long way off, but it’s not the only device that needs to be optimized for power consumption.

Start with baseline measurements

Whenever I work to optimize a product’s energy consumption, I start with a baseline energy measurement. Usually I figure out where to start by analyzing the current draw of the device over a few seconds or minutes. In my dev board experiments, I put the Kinetis-L in run mode, no sleep mode, all peripherals running and the board was set to toggle the LEDs periodically. Using the I-Jet debugger from the IAR Embedded Workbench along with the I-Scope, I was able to configure a simple baseline for this board, which is about 16.9mA when the LEDs are off and 18.0mA when the LEDs are on, as shown in the figure 1 shown. Obviously, it is important where to start the measurement, otherwise the analysis results may deviate significantly.

How to put the MCU into sleep state and see how much power consumption can be saved?
Figure 1: Current measurement of the development board, the LED toggles every second. (Source: Author)

Optimize energy consumption with standby mode and deep sleep mode

The fastest way to save energy is to perform a standby or deep sleep mode. Studying the datasheet for the Kinetis-L processor shows that the power consumption in standby mode is between 3.7 and 5.0mA at 3V. In this mode, the CPU and peripheral clocks are disabled, and the flash memory is in sleep mode, allowing the processor to still wake up within the interrupt time frame (12-15 clock cycles). Wait mode is easy to implement, and the code to set up to enter wait mode is as follows:

void Sleep_Wait(void)
{
SCB_SCR &=~ SCB_SCR_SLEEPDEEP_MASK;
asm(“WFI”);
}

With just these two lines of code, the board’s current consumption dropped from 18.0mA to 15.9mA. Current consumption is reduced by 11.6%! If the board were powered by a 680mA battery, the battery life of the device would go from 37.8 hours to 42.8 hours! Two lines of code can extend battery life by five hours!

The benefit of these advanced power modes is that we can easily go one step further. We can put the processor into deep sleep wait mode instead of just wait mode using the following code:

void Sleep_Deep(void)
{
SCB_SCR |= SCB_SCR_SLEEPDEEP_MASK;
asm(“WFI”);
}

All we have done is to adjust a bit in the SCB_SCR register and we have reduced the initial 18mA current consumption to 14.8mA. Current consumption is reduced by 17.8%! Again, battery life has now grown from 37.8 hours to 46 hours, assuming the board is powered by a 680mA battery! You can save a lot of energy with just a few lines of code, and that’s just the tip of the iceberg!

Microamp-level current consumption with Stop and VLLS modes

Using stop mode disables the core and system clocks, potentially reducing MCU current consumption by a further two mA. You will find that the lower the power mode, the more code is required to implement it, and the more complex the code to wake the system back to work. The code to put the Kinetis-L into stop mode looks like this:

void Sleep_Stop(void)
{
volatile unsigned int dummyread = 0;
SMC_PMCTRL &=~ SMC_PMCTRL_STOPM_MASK;
SMC_PMCTRL |= SMC_PMCTRL_STOPM(0);
dummyread = SMC_PMCTRL;
Sleep_Deep();
}

Note that the stop mode is controlled by the power management control register, once the state is set, the Sleep_Deep function is called to complete the power mode setting and perform WFI.

So far, we’ve been talking about MCU power consumption of 1~2mA. Modern microcontrollers will offer power modes that consume only microamps or even nanoamps! The Kinetis-L processor, which debuted around 2013, uses only 135 to 496 microamps in its Ultra Low Leakage Stop (VLLS) mode! The code to initialize this power mode looks like this:

void Sleep_VLLS1(void)
{
volatile unsigned int dummyread = 0;
SMC_PMCTRL &=~ SMC_PMCTRL_STOPM_MASK;
SMC_PMCTRL |= SMC_PMCTRL_STOPM(0x4);
SMC_VLLSTRL = SMC_VLLSCTRL_LLSM(1);
dummyread = VLLS_CTRL;
Sleep_Deep();
}

At this point, you will find that the microcontroller consumes almost no power!

Effects of low power modes on wake-up latency

As we’ve seen so far, putting the processor into lower and lower power modes is a great way to save energy, but it comes at a cost. The lower the energy state of the processor, the longer it takes to wake the processor back to work. For example, if I use the standard stop mode, it takes 2µs plus the interrupt latency for the processor to wake up and start executing code again, which is acceptable. However, if one of the VLLS modes is set on the Kinetis-L, it will require a wake-up delay to start the processor plus an additional 53 to 115 microseconds! Some apps may not accept this condition. Figure 2 shows the various transitions of the Kinetis-L from low-power modes to run states.

How to put the MCU into sleep state and see how much power consumption can be saved?
Figure 2: Kinetis-L transition time from low power mode to various modes. (Source: Kinetis-L data sheet)

in conclusion

Arm microcontrollers all have standard low-power modes, but each chip maker customizes more low-power modes available to developers. As we’ve seen, chip vendors typically offer several easy-to-implement modes with minimal impact on wake-up latency. They also offer several ultra-low power modes that virtually shut down the processor and consume only a few hundred microamps or less! Developers often need to make a trade-off between power consumption and how long it takes the system to wake up and how quickly it can respond to events. And the trade-offs must be application-based, so don’t expect to be able to implement the lowest power modes on every product and application.

The Links:   LA084X01-SX01 2MBI400TC-060-01 IGBTMODULE

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.