10 January 2011

Optimising the power consumption of embedded systems

  • Embedded Software Development
  • Embedded Software Development
  • Embedded Software Development
  • Embedded Software Development

How software developers can help to optimise the power consumption of an embedded system. By Lotta Frimanson and Anders Lundgren.

Power consumption has traditionally been something influenced only by hardware developers. But power consumption depends not only on the hardware, but also on how it is used and how it is controlled by the system software. Through power debugging – coupling source code to power consumption – it becomes possible to test and tune for power optimisation.

The approach is based on the ability to sample power consumption and to correlate each sample with the program's instruction sequence and, hence, with the source code. One difficulty is achieving high sampling precision. Ideally, power consumption should be sampled at the system clock's frequency, but power system capacitances reduce the reliability of such measurements. From the software developer's perspective, it is more interesting to correlate power consumption with source code and various events in the program execution than with individual instructions, so the resolution needed is much lower.
Power is measured by the debug probe – IAR's J-Link Ultra, for example (see fig 1).



This measures the voltage drop across a small resistor in series with the supply power to the device. The voltage drop is measured by a differential amplifier and sampled by an a/d converter.
The key to accurate power debugging is a good correlation between the instruction trace and the power samples. The best correlation is with a complete instruction trace, but this is not available in all devices and, even if it is, a special debug probe is often required.
Less accurate, but still giving good correlation, is to use the PC (program counter) sampling facility found in some on chip debug architectures, see fig



2. The PC is sampled periodically and each sample given a time stamp. The debug probe samples device power consumption using an a/d converter and, by time stamping the sampled power values and the PC samples, it is possible for the debugger to present power data on the same time axis as graphs like interrupt log and variable plots, and to correlate power data to source code.

In general, optimising for power is similar to optimising for speed. The faster a task is executed, the more time can be spent in a low power mode. So by maximising idle time, power consumption is reduced.

* Waiting for device status
There can be difficulty in identifying how a system consumes energy and where power demands can be optimised. Typically, explicit flaws in the source code are not exposed, rather opportunities to tune how the hardware is used.

One common mistake that can cause power to be consumed unnecessarily is using a poll loop to wait for a peripheral to change status. Another related code construction is implementing a software delay as a 'for' or 'while' loop. This keeps the cpu busy executing an instruction that does nothing but count time.

In both of these examples, the code could be changed to minimise power consumption. Time delays are better implemented by using a hardware timer. The timer interrupt is set up, after which the cpu goes into a low power mode until it is awakened by the interrupt. Meanwhile, polling device status change should be solved using interrupts or by using a timer interrupt so the cpu can sleep between polls.

* DMA versus polled I/O
Direct memory access (DMA) has traditionally been used to increase transfer speed. In some architectures, the cpu can even be put into sleep mode during the DMA transfer. Power debugging allows the developer to experiment and, via the debugger, see what effects DMA techniques will have compared to a cpu driven polled approach.

* Low power mode diagnostics
Embedded applications spend most of their time waiting for something to happen. If the processor is running at full speed when idle, battery life is reduced while little is being accomplished. In many applications, the microprocessor is only active for a small amount of the total time, so by placing it in a low power mode during idle time, battery life can be extended significantly.

A good approach is to use task oriented design and an rtos. In task oriented design, a task defined with the lowest priority will only run when no other task needs to run. This idle task is the perfect place to implement power management. In practice, every time the idle task is activated, it puts the processor, or parts of it, into one of a number of low power modes.

* cpu frequency
Power debugging allows the developer to verify power consumption as a factor of the clock frequency. A system that spends little time in sleep mode at 50MHz is expected to spend 50% of the time in sleep mode when running at 100MHz. The power data in the debugger will allow the developer to verify expected behaviour and, if there is a non linear dependency, to choose the operating frequency that gives the lowest power consumption.

* Interrupt handling
Figure 3 shows a schematic diagram of the power consumption of an event driven system where the system at t0 is in an inactive mode and the current is I0.



At t1 the system is activated and current rises to I1 which is the system's power consumption in active mode with one used peripheral device. At t2, execution is suspended by an interrupt handled with higher priority. Active peripherals are not turned off, although the thread with higher priority is not using them. Instead, more peripherals are activated by the new thread and the current rises to I2 between t2 and t3, when control is handed back to the thread with lower priority.

While system functionality could be excellent and maybe further optimised in terms of execution speed and code size, more optimisations can be done in the power domain. The red area represents the energy that could be saved if the peripherals that are not used between t2 and t3 are turned off, or if the priorities of the two threads can be changed.

Power debugging makes it easier to discover the increase in power consumption when the interrupt hits and to identify it as abnormal.

* Conflicting hardware
It is common practice to avoid floating inputs by tying unused mcu I/O pins to ground. If, by mistake, the software configures a grounded I/O pin as a logical '1' output, a current as high as 25mA may be drained on that pin. This is easily observed by reading the current value from the power sampling display; it is also possible to find the corresponding erratic initialisation code by looking at this display during application startup.

Conclusion
Power debugging provides embedded developers with the ability to see inside their application and to determine how program code and flow influences power consumption. With this knowledge, source code can be tuned and optimised to minimise the power required, making designs as energy conservative as possible without impacting performance.

Author profiles:
Lotta Frimanson and Anders Lundgren are with IAR Systems.

Author
Lotta Frimanson and Anders Lundgren

Supporting Information

Downloads
30528\P35-36.pdf

Websites
http://www.iar.com/

Companies
IAR Systems Ltd

This material is protected by Findlay Media copyright
See Terms and Conditions.
One-off usage is permitted but bulk copying is not.
For multiple copies contact the sales team.

Do you have any comments about this article?

Very informative writing. Thank you to the authors.

- Deeppak, 03/04/2012

Add your comments

Name
 
Email
 
Comments
 

Your comments/feedback may be edited prior to publishing. Not all entries will be published.
Please view our Terms and Conditions before leaving a comment.

 

Related Articles

Feabhas gets OK from ARM

Embedded training specialist Feabhas has been appointed an ARM Approved ...

MIT unveils simulation system

MIT researchers have developed a software simulation system designed to ...

Mathworks enhances range

In a move described as a 'significant enhancement' to its product range, ...

Putting a trace on bugs

When developers start a new microprocessor based project, they are faced with a ...

Ecosystem extends abilities

Operating systems can be a major source of stress for embedded design ...

Unlocking the code

Releasing a product with bugs is potentially very expensive, especially when ...

High speed board design

Istvan Nagy, electronics design engineer at Blue Chip Technology, a leading UK ...

Software development paper

The white paper illustrates, by way of a practical example, how a modular ...

Finding concurrency errors

This whitepaper describes common concurrency pitfalls and explains how static ...

Add in extensions

Agilent Technologies has announced a product enhancement designed to help ...

Cobham design software

Cobham Technical Services claims that the development of new generations of ...

Starter kit STM32F407ZG mcu

IAR Systems has announced a new 32bit kit for STMicroelectronics' first ARM ...

MCU Solutions Summit 2012

18 September, Southern UK (tbc) 20 September, Manchester

Altium design secret one

If you've ever reviewed a hard copy of a design, schematic or pcb, you've ...

Booster pack for MSP430

The Audio Capacitive Touch BoosterPack (430BOOST-C55AUDIO1) is a plug in board ...

C5000 software overview

The Audio Capacitive Touch BoosterPack (430BOOST-C55AUDIO1) is a plug in board ...

The eco cloudy system thing...

One of the bothersome aspects of coming to grips with new, popular shifts in ...

Software developers' lives

A friend once asked me what software developers do when they're not creating ...

Design reuse

It's become a cliché in news or science reports. A water treatment plant ...

Cyrille Comar, AdaCore Europe

Cyrille Comar, co founder and managing director of AdaCore Europe, speaks to ...

Martin Harris, Altium

Chris Shaw asks Martin Harris about the latest developments at Altium

Herbert Truppe interview

Herbert Truppe, director, Product Management & Application, ...