17.01.2015 Views

Microcontroller Solutions TechZone Magazine, April 2011 - Digikey

Microcontroller Solutions TechZone Magazine, April 2011 - Digikey

Microcontroller Solutions TechZone Magazine, April 2011 - Digikey

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Power Debugging ARM Cortex-M3<br />

and Cortex-M4 Applications<br />

by Lotta Frimanson and Anders Lundgren, IAR Systems<br />

Your application is now working properly,<br />

but you’re still over your power budget.<br />

This article shows you how to debug that<br />

problem, too.<br />

Power debugging is a recent innovation that provides software<br />

developers with information about how the software implementation<br />

in an embedded system affects system-level power consumption. By<br />

coupling source code to power consumption, testing and tuning for<br />

power optimization is enabled.<br />

Long battery lifetime is a very important factor for many embedded<br />

systems in almost any market segment--medical, consumer<br />

electronics, home automation, and many more. Power consumption<br />

has traditionally been a design goal that only the hardware developers<br />

have been able to infl uence. But in an active system, power<br />

consumption depends not only on the design of the hardware but also<br />

how it is used, which in turn is controlled by the system software.<br />

The technology for power debugging is based on the ability to<br />

sample power consumption and correlate each sample with the<br />

program’s instruction sequence and hence with the source code.<br />

One diffi culty is achieving high precision sampling. It would be ideal<br />

to be able to sample power consumption with the same frequency<br />

the system clock uses, but power system capacitances reduce the<br />

reliability of such measurements. Usually this is not a problem since<br />

from the software developer’s perspective, it is more interesting<br />

to correlate the power consumption with the source code and<br />

various events in the program execution rather than with individual<br />

instructions, so the resolution needed is much lower than one<br />

sample per instruction.<br />

Typically within the debug probe, a resistor is connected in series with<br />

the supply to the development board. The voltage drop across this<br />

resistor is measured, fed to a differential amplifi er and then sampled<br />

by an A/D converter.<br />

The key to accurate power debugging is a good correlation between<br />

the instruction trace and the power samples. The best correlation can<br />

be achieved if a complete instruction trace is available, as is the case<br />

for ARM MCUs with ETM (Embedded Trace Macrocell) support. The<br />

drawback with using ETM is that it requires a special debug probe<br />

and ETM support in the device itself.<br />

Figure 1: The debug module on Cortex-M3/M4.<br />

Less accurate but still giving good correlation is to use the PC (Program<br />

Counter) sampling facility available in the ARM Cortex-M3/M4 cores<br />

(Figure 1). The DWT (Discrete Wavelet Transform) module implements<br />

the PC sampler; it samples the PC periodically around 10,000 times per<br />

second and triggers an ITM (Instrumentation Trace Macrocell) packet for<br />

each sample taken. The ITM is the formatter for events originating from<br />

the DWT. It packetizes the events and timestamps them. The debug<br />

probe (J-Link Ultra) samples the power consumption of the device using<br />

an A/D converter. By time stamping the sampled power values and the<br />

PC samples, the debugger is able to present power data on the same<br />

time axis as graphs like the interrupt log and variable plots as well as to<br />

correlate power data with the source code.<br />

As stated before, power debugging is based on the ability to sample<br />

the power consumption and correlate each sample with the source<br />

code. For example, in IAR Embedded Workbench the power samples<br />

can be displayed in different formats. The Power Log window (Figure<br />

2) is a log of all collected power samples. This window can be useful<br />

to fi nd peaks in the power sampling, and since the power samples are<br />

correlated with the executed code it is possible to double-click on a<br />

value in the Power Log window and get to the corresponding code.<br />

Figure 2: Power Log window.<br />

58

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!