a state-based method to model and analyze the power...

54
UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based method to model and analyze the power consumption of embedded systems Lars Haulin

Upload: others

Post on 22-Mar-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

UPTEC F 18050

Examensarbete 30 hpSeptember 2018

A state-based method to model and analyze the power consumption of embedded systems

Lars Haulin

Page 2: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

Teknisk- naturvetenskaplig fakultet UTH-enheten Besöksadress: Ångströmlaboratoriet Lägerhyddsvägen 1 Hus 4, Plan 0 Postadress: Box 536 751 21 Uppsala Telefon: 018 – 471 30 03 Telefax: 018 – 471 30 00 Hemsida: http://www.teknat.uu.se/student

Abstract

A state-based method to model and analyze thepower consumption of embedded systems

Lars Haulin

In this work I have evaluated a method to model, measure and analyze the powerconsumption of embedded systems.

The method combines current measurement with debug trace data telling which partsof the systems that are enabled. This makes it possible to compute the individualcurrent consumption of the parts in the system from a single measurement point.

The method allows an embedded systems engineer to determine the powerconsumption of individual parts in a system to either get an overview or to compareseveral revisions of hardware and/or software with each other.

The method also captures the system dynamics of the power delivery route. Thismakes the model consumption behave more like the actual system around statetransitions.

The case study is focused on the Arm-based microcontroller CC2650 from TexasInstruments and uses the I-scope/I-jet probe from IAR Systems to measure currentconsumption and collect trace data.

ISSN: 1401-5757, UPTEC F 18050Examinator: Tomas NybergÄmnesgranskare: Christian RohnerHandledare: Jaan Reio, IAR Systems

Page 3: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

Populärvetenskaplig

sammanfattning

Den kanske största förändringen i vårt dagliga liv de senaste fyrtio åren är intevilka apparater vi har, utan hur de är uppbyggda. Det fanns bilar, telefoner ochmusikspelare även då, men dagens system är till mycket hög grad datorstyrda.Dessa små datorer som sitter inuti andra apparater med syfte att styra demkallas inbyggda system. Många av de inbyggda systemen är batteridrivna ochdet är viktigt att hålla deras strömförbrukning så låg som möjligt.

Strömförbrukningen hos ett system varierar beroende på vad dess styrprogramgör. När till exempel en lampa tänds eller en motor startar så ökar ström-förbrukningen. Det krävs bra styrning och kontroll för att inte slösa energi ionödan.

För att bygga ett effektivt system krävs noggrannt utvecklingsarbete. Varjeändring som görs kan påverka strömförbrukningen. Många delar samverkar ochdet är inte alltid uppenbart hur mycket ström varje enskild del av systemet drar.Det måste i så fall mätas, och om det arbetet kan underlättas sparar det tid.

I detta arbete har jag utvärderat en metod för att mäta strömförbrukningeni inbyggda system. Jag har kombinerat strömmätningar med information frånsystemet om vilka delar som är igång. Utifrån det har jag skapat en modellför systemets strömförbrukning. Den stora styrkan med denna metod är attströmförbrukningen hos enskilda delar kan mätas utifrån en enda mätpunkt.

En förändring i strömförbrukning sker inte direkt. Det är samma princip somatt det tar tid för en bil att komma upp i hastighet efter ett gaspådrag ochatt ett kallt rum inte blir varmt direkt när man sätter igång ett värmeelement.Denna tröghet till förändring kallas formellt för systemdynamik.

Mätmetoden i detta arbete fångar även systemdynamiken i strömförbrukningen.Det gör att man kan förutspå vilken strömförbrukning systemet borde ha, ochjämföra hur väl denna stämmer med den strömförbrukning som faktiskt mättsupp.

Arbetet har utförts på IAR Systems, ett företag som skapar verktyg för utveck-ling av inbyggda system.

3

Page 4: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

Acknowledgments

I am very thankful for all the help, input and support that I have receivedduring my work. There are many people that have helped me both directly andindirectly.

I would like to thank my supervisor Jaan Reio for answering any obscure anddetailed question I have had about debug probes and for generally supportingme through the project.

Many thanks to my evaluator Professor Christian Rohner for advice on prioritiesand how to set my project goals.

Finally, thanks to all the people at IAR Systems for making this thesis possibleby providing hardware and software tools to work with. I have really enjoyedthe welcoming atmosphere, interesting discussions and narrow but entertainingcompiler-development-team-humor.

4

Page 5: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

Contents

1 Introduction 7

1.1 IAR Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81.2 Problem description . . . . . . . . . . . . . . . . . . . . . . . . . 81.3 Goal and purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . 81.4 Limitation of the study . . . . . . . . . . . . . . . . . . . . . . . 9

2 Background 10

2.1 Energy, power and current consumption . . . . . . . . . . . . . . 102.1.1 Causes of power consumption . . . . . . . . . . . . . . . . 112.1.2 Measuring power consumption . . . . . . . . . . . . . . . 112.1.3 Reducing power consumption . . . . . . . . . . . . . . . . 11

2.2 Microcontrollers . . . . . . . . . . . . . . . . . . . . . . . . . . . 122.2.1 Peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . 132.2.2 Debugging and programming . . . . . . . . . . . . . . . . 132.2.3 Tracing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

2.3 Arm Cortex-M microcontrollers . . . . . . . . . . . . . . . . . . . 142.3.1 CMSIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142.3.2 The Coresight debug interface . . . . . . . . . . . . . . . . 142.3.3 ITM messages . . . . . . . . . . . . . . . . . . . . . . . . 14

2.4 Debug probes with power measuring . . . . . . . . . . . . . . . . 152.5 How to measure power consumption with the I-scope probe . . . 16

3 Method 18

3.1 Comparing power consumption . . . . . . . . . . . . . . . . . . . 183.2 Measuring several power consumers from a single measurement

point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183.3 Measurement residual . . . . . . . . . . . . . . . . . . . . . . . . 193.4 A current model with automatic calibration . . . . . . . . . . . . 203.5 Computing a system impulse response . . . . . . . . . . . . . . . 213.6 Hardware platforms . . . . . . . . . . . . . . . . . . . . . . . . . 22

3.6.1 SimpleLink SensorTag . . . . . . . . . . . . . . . . . . . . 223.6.2 CC2650 LaunchPad . . . . . . . . . . . . . . . . . . . . . 23

3.7 Application software for CC2650 . . . . . . . . . . . . . . . . . . 233.8 Adding instrumentation to the application . . . . . . . . . . . . . 243.9 Acquiring and exporting measurement data . . . . . . . . . . . . 253.10 Data processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

5

Page 6: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

4 Results and analysis 27

4.1 Prestudy with manual analysis . . . . . . . . . . . . . . . . . . . 274.2 Automated analysis . . . . . . . . . . . . . . . . . . . . . . . . . 294.3 Parameter visualization . . . . . . . . . . . . . . . . . . . . . . . 29

4.3.1 Pie chart . . . . . . . . . . . . . . . . . . . . . . . . . . . 294.3.2 Log-log diagram . . . . . . . . . . . . . . . . . . . . . . . 314.3.3 Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . 31

4.4 Time-based visualization . . . . . . . . . . . . . . . . . . . . . . . 314.4.1 The raw model . . . . . . . . . . . . . . . . . . . . . . . . 324.4.2 Model extended with system dynamics . . . . . . . . . . . 33

4.5 Residual analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . 364.5.1 Current consumption depends on counter value . . . . . . 364.5.2 Periodic peaks . . . . . . . . . . . . . . . . . . . . . . . . 37

4.6 Failures and dead ends . . . . . . . . . . . . . . . . . . . . . . . . 404.6.1 State modeling . . . . . . . . . . . . . . . . . . . . . . . . 404.6.2 Dynamics modeling . . . . . . . . . . . . . . . . . . . . . 404.6.3 Other hardware platforms . . . . . . . . . . . . . . . . . . 40

5 Discussion 41

6 Conclusions 43

7 Future work 44

7.1 Automatic placement of instrumentation . . . . . . . . . . . . . . 447.2 Extending the model with transient events . . . . . . . . . . . . . 447.3 Extending the model with variance . . . . . . . . . . . . . . . . . 457.4 Other architectures . . . . . . . . . . . . . . . . . . . . . . . . . . 457.5 Driving the model to new states from power measurements only . 45

Appendix 46

A Abbreviations 46

B Bibliography 47

C Computation example 49

C.1 Acquiring data from a simulated circuit . . . . . . . . . . . . . . 49C.2 Implementation of parameter computation . . . . . . . . . . . . . 50C.3 Simulation data from LTspice model . . . . . . . . . . . . . . . . 53

6

Page 7: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

1 Introduction

The perhaps biggest change in everyday life over the last forty years is not whatthings we have, but how they are built. There were cars, telephones and musicplayers in the seventies, but they are no longer based on mechanical carburetors,relays and vinyl records. They are instead embedded systems.

The definition of an embedded system can be worded in many ways, but I likethis short and elegant description:

An embedded system is a small computer with a specific purpose.[1]

Embedded systems are everywhere, they occur in industrial applications suchas automatic control, measurement and communication systems, but also aspreviously mentioned in in modern cars, media systems and house appliances.

All these systems run on electricity and the total energy consumption of thesesystems add up to a considerable amount. Energy consumption is most often re-lated to operating cost, but for battery driven systems a low power consumptionmight be a functional requirement.

The power consumption of a system varies depending on what the system pro-gram does. When a lamp or motor is turned on, the power consumption willincrease. Keeping a part of a system on when not needed wastes energy. Goodcontrol is needed to avoid this.

It takes careful development to build an effective system. This can be a tediouswork, as a system can consist of many parts and it is not always obvious howmuch every part of the system contributes to the total power consumption. Ifthis work can be eased, it will save development time.

In this work I have evaluated a method to measure the power consumptionof the different parts of an embedded system. The method can measure theconsumption of several different parts using only a single measurement point.This is achieved by combining the measurement with debug information fromthe system about which parts of the system that are currently enabled.

I hope this method will help embedded system developers to get a picture ofwhere the most power is consumed in their systems and make it easier to com-pare two different revisions of a system with each other from a power consump-tion perspective.

7

Page 8: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

1.1 IAR Systems

This work has been done at IAR Systems, a company that supplies tools for em-bedded software development. Their main product IAR Embedded Workbenchis an integrated development environment. It features a source code editor,compiler and debugger.

Another product from IAR Systems is the I-jet/I-scope debug probe. It canbe used to program and debug an embedded system and can also measure thepower consumption of the system.

1.2 Problem description

Embedded system development is often an iterative work done in several smallsteps, whether the goal is to reduce the power consumption or improve anyother system characteristic such as code size or execution time. It is not alwaysobvious if a program change has had the desired impact, or even if the change hashad any effect at all. The developers rely on code metrics to evaluate changes.

Some code metrics are simple to set up, measure and interpret. Some examplesare code size, code coverage and passing tests.

One metric that is hard to automatize is power consumption. Measurement,modeling and parameter extraction are not straightforward to automatize, andtypically requires manual testing or a custom built test bench.

IAR Embedded Workbench already contains some power profiling tools thatcan measure how much time the program spends in different functions andhow much power the system consumes. However, the profiling does not takeperipheral devices into account. The same part of a program can consumedifferent amounts of power depending on the state of the peripherals.

1.3 Goal and purpose

This thesis investigates the power consumption of embedded systems, and howthe existing development tools can be improved to measure the power consump-tion of a system with multiple states.

I have investigated a method that makes it possible to compute the individualconsumption of several internal system parts from a single current measurementpoint by combining the current consumption measurements with debug dataadded to the device drivers of the system software.

The questions I try to answer in this work are:

• How well does this method work?

• How precise can the energy consumption be modeled?

• How much work is required from the system developer to use the method?

8

Page 9: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

1.4 Limitation of the study

This study has focused on technology available for microcontrollers based on theArm Cortex-M architecture. I have only performed measurements on systemsbased on the CC2650 chip and only used the I-jet/I-scope debug probe for themeasurements in my case study.

The study has been held from a software perspective. Full system energy reduc-tion is a multi-dimensional optimization problem where not only software butalso hardware must be considered. The software-only perspective is relevant forexisting products where the hardware is fix.

9

Page 10: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

2 Background

This chapter presents the theoretical background for this thesis, the fundamentalconcepts of energy consumption, the available technology and equipment, andprevious research in the area of power reduction.

2.1 Energy, power and current consumption

It is important to know the distinction between the consumption of energy,power and current. They can sometimes be used interchangeably, but onlywhen certain conditions hold.

The power consumption of a device is the amount of energy that it consumes ina given moment. The energy consumption of a device is the sum of the powerconsumption over time.

For example, a camera flash has a very high power consumption when it is on,but as that time is very short the total energy consumption is moderate.

In electrical devices the power consumption P depends on the current con-sumption I and the voltage U through Joule’s law P = U ·I. For systems withconstant supply voltage the power depends only on the current, and minimizingthe power consumption is equivalent to minimizing the current consumption.

Mathematically, the total energy consumption of an electric circuit can be ex-pressed as

E =∫ T

0

P (t)dt =∫ T

0

U(t)I(t)dt

so lowering the energy consumption E can be done by lowering either:

• the voltage U the system is using,

• the current I the system consumes, or

• the time T that the system is running.

An embedded system application is often running endlessly, so both energy andtime would increase without limit. Because of this, it is more practical to usemean power Pmean = E

Tthan total energy, as this is a limited quantity.

10

Page 11: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

2.1.1 Causes of power consumption

Some causes of power consumption can not be avoided, as some energy must beused to fulfill the functional requirements of the system. A radio transmittermust have enough power to broadcast, and a LED might appear dim if does notget enough power.

There are two types of loads that can consume power: resistive and reactive.

A resistive load behaves according to Ohms law. The current depends only onthe voltage that is applied to the load and the resistance of the load. Resistiveloads are simple to compute with, as they can be turned on and off without anythought of consumption impact.

Reactive loads are frequency dependent. A reactive load might consume a littemore power when it starts, but less power once on. If such a load is switchedon and off more frequently, it will consume more power. An example of thisis CMOS-circuitry. Every change in polarity on the gate of a transistor willconsume an amount of charge. There are also other reactive loads that consumemore power after being on for a while, then higher frequencies consume lesspower.

2.1.2 Measuring power consumption

The actual measurement of power consumption can be done in several differentways. The paper [2] summarizes some different methods that apply to embeddedsystems.

The most common way to measure the power consumption of a device is to usea shunt resistor. The shunt resistor is connected in series with the device toconvert the current into a voltage. There are also other ways, but using a shuntresistor is a proven method that most engineers are familiar with and does notrequire advanced circuitry.

It is important to measure close to the current sink to catch rapid variations inthe consumption. The capacitance on the power delivery route will dampen thehigh frequency content of the measured signal.

2.1.3 Reducing power consumption

Over the last 20 years, there has been a lot of research about how to reducethe energy consumption of embedded systems. The works are well summarizedin the two surveys [3] and [4]. This section lists some of the most importantresults from those surveys.

The perhaps easiest way to reduce the power consumption of a system is to turnit off. This is often not a useful solution as it disables the system, but it makesa point: Without functional requirements, it is impossible to know if a systemchange is acceptable or not.

11

Page 12: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

Power reduction efforts are most effective when they are introduced early inthe design process. Before the design is fully determined, there is freedom tochoose a system architecture based on power efficient communication protocolsand freedom to pick the most power efficient circuits for the hardware.

Thorough power reduction requires efforts on every level of the system, andaffects both hardware, software and system architecture. This is not alwayspossible, for example when trying to make existing hardware perform better.

There are three general ways to reduce energy consumption:

• reduce the voltage and/or frequency of the system - DV(F)S, DynamicVoltage (and Frequency) Scaling,

• turn off parts of the systems that consume power - DPM, Dynamic PowerManagement, or

• change the system (write more efficient code, make algorithm approxima-tions, change components).

The advantages of DV(F)S and DPM are that they can be performed at runtimeif the system supports it, but system changes require hardware or softwareupdates.

In an embedded system, it is not always possible to change the system voltageat runtime. But, it can be done in the hardware design phase. A lower supplyvoltage will decrease the power consumption of resistive parts.

The system frequency can also affect the power consumption. Lowering the clockfrequency will decrease the power consumption of the CMOS-circuits. However,this might mean that the processor does not meet performance requirementsin a real-time computation, or that it stays awake doing computations when itcould have been put to sleep.

2.2 Microcontrollers

Microcontrollers are small computers contained in a single IC-chip. Like ordi-nary personal computers, they run programs and perform computations. Butopposed to a personal computer, there is often no direct user interaction.

Microcontrollers are often used in systems that are manufactured in large series,and it is therefore important to match their specification with the requirementsto keep the cost down. Microcontrollers can have internal memory ranging fromless than a kilobyte to several hundred megabytes.

There are many different types of microcontrollers, because they are very spe-cialized to their application. The requirements on the microcontroller in a TVremote control are very different from the microcontrollers in a cellphone.

12

Page 13: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

2.2.1 Peripherals

The main difference between a regular computer and microcontroller, besidesperformance, is how they interact with their surroundings. A microcontrollerinteracts with its surroundings using electrical signals, which the microcontrollercan send and listen for on its pins. The pins are then connected to othercomponents in the system.

The pins on a microcontroller can have slightly different capabilities, some canmeasure voltage levels while others have hardware support to act as serial com-munication interfaces. The availability of these peripheral units is also some-thing that distinguishes different microcontrollers from each other and affectstheir price. Most pins on a microcontroller have the capability to detect or senda high or low signal, this is called general purpose input and output, GPIO.

2.2.2 Debugging and programming

A personal computer interacts directly with the user through screen, keyboardand mouse, and the programs on a computer are created on the computer itself.

A microcontroller is not programmed directly. The programs for it are writtenand compiled into binaries on an ordinary personal computer. The binaries arethen written to the microcontroller with special debug probes that connect toboth the computer and the microcontroller. This programming procedure isoften called flashing, as the program is written to flash memory.

The debug probes are also used to test and debug the microcontroller programusing debug software running on the computer. This makes it possible to pause,resume and set breakpoints in the program. It is also possible to look at and/orchange program data much like in a debugger for ordinary computer programs.

2.2.3 Tracing

Microcontroller programs often have real-time requirements, and this meansthat they can not be halted without restrictions. The control system for aquadcopter can not be halted when it is flying without causing damage to thesystem. In such situations it is not possible to extract data about the programexecution by halting the processor and examining its internal memory.

Tracing is a way to extract runtime data without halting the program. It pro-vides an interface that can export information about the state of the programto the debug probe.

Tracing requires special hardware support, both inside the microcontroller andin the debug probe. Debug probes with tracing support typically have a lot ofinternal memory that can buffer data before sending it to the computer. Thismakes probes with tracing capabilities more expensive. Even if the microcon-troller does not support direct tracing, instrumentation can be implemented insoftware. [5]

13

Page 14: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

2.3 Arm Cortex-M microcontrollers

The Cortex-M is a processor core from Arm. It is not manufactured by Armthemselves, but instead licensed to other manufacturers. This is attractive forsilicon vendors, as they can use a proven design for new chips, and benefit fromalready existing compilers and that customers are familiar with the architecture.

2.3.1 CMSIS

The Arm Cortex Microcontroller Software Interface Standard (CMSIS) is avendor-independent hardware abstraction layer for Cortex-M microcontrollers.This standard enables a consistent software interface to the processor and theperipheral devices. This means that device drivers written using this interfacecan be used on any chip with peripherals that adhere to the standard. [6]

2.3.2 The Coresight debug interface

The CMSIS also specifies a debug and trace interface, called Coresight. It is usedin Cortex-M and some of the other processors from Arm. This interface pro-vides both normal debugging with start/stop/step/breakpoints and non-invasivetracing. [7]

2.3.3 ITM messages

The Instrumentation and Trace Macrocell (ITM) is a Coresight component thatallows the microcontroller application to send arbitrary data to the debuggerin real time. Data is sent in chunks of 8, 16 or 32 bits over 32 channels. Thedivision of data into channels allows the debugger to filter out the data that isrelevant.

An ITM message is sent by writing data to a stimulus register. A write to thisregister will put the data in a queue to be sent. The application must checkthat there is room in the queue before writing to the register by reading from it.The value is 1 if there is room and 0 if the queue is full. An example written inC using the CMSIS standard headers is shown in listing 1. The CMSIS-COREstandard reserves stimulus channels 0 and 31. Channel 0 is used as a UARTand channel 31 is reserved for kernel use. [6, 8]

Listing 1: Example code to send an ITM-message.

1 void sendMessage ( uint8_t portNumber , uint8_t value ) {2 while (ITM−>PORT[ portNumber ] . u32 == 0)3 ; /∗ sp in wai t ∗/4 ITM−>PORT[ portNumber ] . u8 = value ;5 }

14

Page 15: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

Table 1: Side-by side comparison of a few different debug probes with powermeasurement capabilities.

Manufacturer Name Resolution Range Channels Rate

Atmel [9] Power Debugger ±3 µA 0.5-100 mA A 62.5 kHz±30 nA 1 mA-1 µA A

±500 µA 1 mA-1 µA BIAR [10] I-jet + I-scope 12 bits (shunt) up to 4 200 kHzKeil + Hitex Ulink + PowerScale <3% 1 A-1 mA up to 4 100 kHz[11] (with ACM probe) <2.5% 0.5 A-0.2 µALauterbach TRACE32 [12] 12 bits (shunt) up to 7 625 kHzSegger [13] J-link Ultra+ ± 1 mA 0-300 mA 1 50 kHzSiLabs [14] Built-in AEM 500 µA 0.25-50 mA 1 6250 Hz

probes 1 µA 0.1-250 µATI [15] XDS110 ±0.5 µA/2% 1 µA-25 mA 1 2 kHz

±0.5 µA/5% 25-100 mA

2.4 Debug probes with power measuring

There are many tools to measure the energy consumption with, such as am-meters or oscilloscopes. For microcontrollers, there are debug probes that canmeasure power and synchronize this with trace data from the program. Thelatter is an important feature, as this makes it possible to correlate programbehaviour with power consumption. With this info, a developer can identifythe parts of the program that could be reworked for energy efficiency.

A few probes are listed in table 1. All these probes can measure energy overtime and not just the average consumption. The probes measure current indifferent ways.

The J-Link Ultra+ and XDS110 probes measure current when they providepower to the device. The I-jet also has this feature when used without theI-scope.

The Power Debugger and PowerScale probes have internal shunt resistances thatthe supply current is routed through. The ACM probe for the PowerScale hasa measurement range of six orders of magnitude. It achieves this with severalshunt resistances that it switches between automatically. [11]

The XDS110 probe from Texas Instruments does not use a shunt resistance. Itinstead uses a patented technique called EnergyTrace that computes the powerconsumption from the frequency of a DC-DC converter. [16] This is an appli-cation of the charge transfer method described in [2]. The circuit integrates thepower consumption to energy consumption without any numerical errors, as thepulse count is an integer. This is good for very low currents. The drawbackis that the update interval is not fixed and it is not possible to sample powerconsumption at a higher rate than the DC-DC converter frequency.

15

Page 16: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

Usupply

-

+

Rshunt

Ushunt

I

Device

I-scopeI-scope I-jetI-jet

Deb

ug

Debug and measurements

USB

I+ I-/V1

Figure 1: Schematic for current measurement with the I-scope.

2.5 How to measure power consumption with

the I-scope probe

The I-scope probe can measure four simultaneous voltages: V1, V2, V3 and I+.The voltage I+ is measured relative to V1, the others are measured relative toground. This configuration allows the I-scope probe to measure both the currentconsumption and the supply voltage for the device at the same time.

Figure 1 shows how the I-scope is typically connected to a device when measur-ing current and voltage. The probe needs an external shunt resistor to measurecurrent. The current is computed from the voltage I+ and the shunt resistanceusing Ohm’s law. The I-scope can measure voltage drops in the range 0-110 mVover the shunt resistance. Figure 2 shows a photo of the I-scope connected to aCC2650 SensorTag.

The quality of the measurement will depend on the value of the shunt resistance.The resistance should be large enough to give an acceptable resolution for themeasurements, but at the same time small enough to keep the shunt voltage inthe measurable range.

The measurements of current and voltage are not done exactly at the same time,they are interleaved. As I need simultaneous current and voltage to computepower consumption, I assigned the previous measured voltage to every currentmeasurement. This is zero order hold interpolation.

16

Page 17: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

Figure 2: A current measurement setup with an I-jet and I-scope connected toa CC2650 SensorTag. Test clips hold the shunt resistor and connect the powercables to the device. A voltmeter is connected in parallel with the power supplyto show the voltage.

17

Page 18: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

3 Method

This chapter describes the algorithms I used in my work and how I performedmy measurements.

3.1 Comparing power consumption

IAR Embedded Workbench already has the time line interface that allows forvisual analysis of the power consumption. This is good for analysis of a singlerun of measurement data.

A developer might sometimes want to compare measurements with each other.Either to prove consistency by comparing two measurements from the samesystem, or to see what effect system changes have on the power consumption bycomparing measurements from different revisions of software/hardware.

A time-based approach might not be the best when comparing two measure-ments. The program flow of an embedded system often depends on externalstimuli, and a small change in the stimuli can cause the program to behave verydifferent. Two measurements might be impossible to compare due to synchro-nization problems.

A time based approach does not summarize the consumption, as the informationabout consumption is spread out in time. Summaries are good both whencomparing measurements and when communicating results through reports orpresentations. It is desirable to have a measurement method that summarizesthe results.

3.2 Measuring several power consumers from a

single measurement point

Traditionally, several measurement points are needed to measure several powerconsumers. This is straightforward and needs no extra computations, but themethod does not scale well. There must be hardware added for every part ofthe system that needs to be measured.

18

Page 19: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

Probe

AnalysisVerification

Output

Device under testCurrent

measurement

Trace captureModel parameter

computation

Σ+

Consumptionmodel

Modelparameters

Measurementresidual

Figure 3: The data flow when computing the model parameters and the mea-surement residual.

The method in this work combines measurement data with debug informationfrom the system to determine the individual contribution to the power consump-tion from every part in the system. This makes it sufficient to only measure thecurrent in a single point.

The approach is to create a model for the power consumption and then computethe consumption parameters that fit the model to the measured data.

The trade-off when reducing the number of measurement points is that the resultdoes not come out directly. The data must be analyzed, and the parameterscomputed. But this process can be automated.

3.3 Measurement residual

When doing a power analysis on an embedded system, some information isalready known to the developer. Turning a LED on will increase the powerconsumption, that information is not new. This knowledge can be made explicitby creating a model. The model is driven by the state changes in the system.The model parameters need to be calibrated with measurement data.

By removing the part of the measurement that the model predicted, only thepart that contains new information remains. This is known as the measurementresidual or innovation, and is often used in statistics and control theory. Theresidual is defined as the measurement minus the prediction. The data flowof the computation process is shown in figure 3. The residual can be bothpositive and negative, depending on what kind of information the predictormodel missed. With perfect model and prediction, the residual is zero. Thismeans that the measurements do not contain any information about the systemthat is not already covered by the model.

Note that the measured power consumption can be a vector if several currentsor voltages are measured. With enough (and wisely chosen) measurements, itmight be possible to determine what state the system is in. This is an analogyto the observability concept from control theory on dynamic systems. [17]

19

Page 20: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

3.4 A current model with automatic calibration

A method for automatically calibrating model parameters using least squaresregression was first presented in [18], but is expanded and better describedin [19]. The model presented there describes the total power consumption ofintegrated circuits as the sum of the consumption from every part. Each part hasan estimated power consumption that depends linearly on the system frequency.

I have adapted this model to describe current instead of power and applied itto embedded systems. From my preliminary current measurements I found outthat I had to take the voltage in account. Current is directly proportional tovoltage (Ohms law) and power is proportional to voltage squared (Joules law).

The model makes a few assumptions. In this model, every part i of the system iseither on or off at any given time. This is modeled using indicator variables si,when the part i is on then si = 1, otherwise it is zero. The model also assumesthat the estimated current Ii that part i contributes to the total estimatedcurrent consumption has a constant part ai and a voltage dependent part withcoefficient bi. It also assumes that the total current is the sum of all the parts,without any non-linearities.

The model estimate of the total current consumption I(t) at time t for a systemwith N parts is

I(t) =N

i=0

si(t)Ii(t) =N

i=0

si(t) (ai + U(t)bi) (3.1)

where the special state 0 models the constant current consumption, combiningleak currents, non-modeled parts and the consumption that all system partshave when they are off. The indicator variable s0 is always set to one.

Equation (3.1) can be rewritten with a scalar product (s0 is eliminated) as

I(t) =(

1 s1(t) . . . sN (t) U(t) s1(t)U(t) . . . sN (t)U(t))

(

~a~b

)

and the full system of equations for all measurements can be written on matrixform. The current measurements become a vector I and the state informationwith voltage measurements becomes a matrix S. The resulting equation system

is I = S

(

~a~b

)

which has the model parameters as its solution.

The measured current I will have some level of measurement noise and modelerror ǫ. This can be written as I = I + ǫ. The model parameters ~a and ~b canbe computed using linear least mean squares so that ǫ is minimized.

For an overdetermined linear equation system Ax = y, the least squares solutionis given by AT Ax = AT y, or x =

(

AT A)−1

AT y.

A more verbose example of how to construct S and how to compute the modelparameters is presented in appendix C.

20

Page 21: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

3.5 Computing a system impulse response

The dynamics of a system can be computed from measurement data with aWiener filter. The Wiener filter is a filter that minimizes the mean square sumof the difference between two signals.

System dynamics in a power measurement comes from capacitance and induc-tance on the power delivery route - the circuitry between the power sink andthe point where the consumption is measured.

The problem of finding the system dynamics can be formulated as finding afilter f that minimizes the difference between the filtered estimated currentf ∗ I and measured current I. There are several ways to define “difference”, butthe L2-norm is used to compute the Wiener filter.

The residual V (f) to be minimized is

V (f) = ||I − f ∗ I||2

where ∗ denotes convolution. The residual depends only on f , as I and I aregiven. In discrete time, both I and I are vectors with values In and In at samplen. Let fj be the j:th tap in a causal FIR filter, then V (f) can be written as

V (f) =∑

n

In −∑

j

fj In−j

2

=∑

n

I2

n − 2In

j

fj In−j +

j

fj In−j

2

.

The minimum of V (f) is found by taking the derivative for each FIR-tap fk

dV (f)dfk

=∑

n

−2InIn−k + 2In−k

j

fj In−j

and solving the equation for when the derivative is equal to zero. With thenotation Rab[i] =

n anbn−i for correlation, the equation from the filter tap fk

derivative is∑

j

fjRI I

[j − k] = RII

[k] .

The equations from all filter tap derivatives are together called the Wiener-Hopfequations (in discrete time). They can be written on matrix form as

RI I

[0] RI I

[−1] . . .

RI I

[1] RI I

[0] . . .

. . . . . . . . .

f0

f1

. . .

=

RII

[0]R

II[1]

. . .

(3.2)

thus the FIR Wiener filter f is the solution to a linear equation system definedby the correlation between the measured current I and the estimate I. [20]

The number of taps in f can be chosen arbitrarily. The solution will be differentdepending on the number of taps used.

21

Page 22: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

3.6 Hardware platforms

I had to choose hardware platforms for my case study. The various platformsand chipsets all have different characteristics and give different possibilities, sothe choice was non-trivial.

My requirements were to have a readily available development platform with anArm Cortex-M microcontroller. The board should have a power efficient design,as a metric for this I looked at battery driven boards. It would also be good ifthe board existed in several different variants, so that the same software couldbe compared on several boards.

3.6.1 SimpleLink SensorTag

The SimpleLink SensorTag from Texas Instruments is a small battery drivensensor platform, pictured in figure 4. It is based on the Arm chip CC2650 whichhas a built in radio module. It has been used in several student projects atUppsala university.[21, 22, 23] The SensorTag has sensors for humidity, pressure,light, motion and temperature. For user interaction it also has buttons, LEDsand a speaker.

Figure 4: The SensorTag, with and without its protective case.

22

Page 23: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

Figure 5: The CC2650 LaunchPad development board.

3.6.2 CC2650 LaunchPad

The CC2650 LaunchPad is a development kit from Texas Instruments. It is alsobased on the CC2650 chip. This board is shown in figure 5. It has no sensorson its own, but breaks out most of the pins to headers. The board has a builtin antenna and debugger, but it is also possible to use an external debugger. Italso has two LEDs and buttons.

The built in XDS110 debugger does not support EnergyTrace, at least notin board revision 1.2. The debugger in the CC2650 LaunchPad uses a linearregulator instead of a DC-DC converter. Other versions of the XDS110 debuggersupport EnergyTrace.

3.7 Application software for CC2650

I wrote a small test program for my measurements. The only thing it did was toblink two LEDs so that there were four distinctive states of power consumption.The blinking was shifted in phase so that two diodes never changed state at thesame time.

23

Page 24: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

Figure 6: The timeline in IAR Embedded Workbench, showing an instrumentedpower log. The current consumption and ITM messages are shown over time.

01234567

EventID State

Figure 7: The event message structure. An event consists of the event ID andthe new state it enters.

3.8 Adding instrumentation to the application

I added instrumentation code to the CC2650 program and recorded instru-mented power logs with IAR Embedded Workbench. The SWO instrumentationallowed the microcontroller to send integers to the debugger. Figure 6 shows ascreenshot of the timeline in IAR Embedded Workbench.

I designed a structure to send event messages as integers over the SWO channel.The structure is shown in figure 7. To have a low latency, the ITM-packagesshould be as small as possible, so I used a width of 8 bits. The state informationuses one bit, so there are 7 bits left to indicate the part number. This allows128 parts in the system to be instrumented, with numbers from 0 to 127.

A snippet from the instrumented program is shown in listing 2. The codethat controls the LEDs has been broken out into separate driver functions.The application must control the LEDs using the instrumented drivers. Theinstrumentation will fail if the LEDs are controlled directly at GPIO-level.

Listing 2: The instrumentation from a source code perspective. The programsends an event message when it takes an action that affects power consumption.The EVENT macro is a wrapper to sendMessage in listing 1.

1 #d e f i n e EVENT( e , s ) sendMessage (ITM_CHANNEL, (( e)<<1) | ( ( s )&1))2 void greenLEDon ( void ) {3 EVENT(GREEN_LED, 1 ) ;4 GPIO_setDio (GREEN_PIN) ;5 }6 void redLEDoff ( void ) {7 EVENT(RED_LED, 0 ) ;8 GPIO_clearDio (RED_PIN) ;9 }

24

Page 25: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

3.9 Acquiring and exporting measurement data

I collected measurement data from the two platforms with IAR EmbeddedWorkbench. I saved the logs for post-processing. The logs contain time-stampedSWO data and the voltages that the probe has measured. There are also PC-samples. They tell what part of the program that runs at that very moment.

I did two kinds of measurements with the I-scope. I measured both voltage andcurrent with varying supply voltage. I also measured only current with a fixsupply voltage. For the measurements that were current only, I measured thesupply voltage with a multimeter and added it manually. The supply voltageto the device is affected by the shunt resistor voltage, as a higher current willlower the voltage that reaches the device. But, as the shunt voltage is measuredby the probe, it is possible to compute the supply voltage to the chip in thecurrent only measurements.

I performed my measurements around 3 V. I did not go below 2.8 V for theautomated measurements, because I ran into problems with the internal DC-DC converter in the CC2650. I kept the supply voltage to the SensorTag under3 V because I was not sure if all the sensors on the board could handle highervoltages. I tested the LaunchPad up to 3.6 V as there are only two ICs on thatboard and they can both handle 3.6 V according to their data sheets.

The SWO-log format is tab-separated text, a small snippet is shown in listing 1.The measurements are reported in microvolts, channel 0x280 is the shunt voltageand 0x290 is the supply voltage. The probe resends the previous voltage andcurrent when a PC-sample is sent. This repeated data was removed in the actualanalysis.

The SWO trace buffer in IAR Embedded Workbench is normally limited to 1million items. This means less than five seconds at a sampling rate of 200 kHz.With help from the staff at IAR, I could increase this limit to allow longermeasurements.

A2D: 0x290 15482670 0x2bc0e0 2867424

A2D: 0x280 15482910 0x11e6 4582

A2D: 0x290 15483150 0x2bc0e0 2867424

A2D: 0x280 15483390 0x12db 4827

ITM 15483526 0x1

A2D: 0x290 15483594 0x2bc0e0 2867424

A2D: 0x280 15483594 0x12db 4827

PCSample 15483594 0xc34 CMP R0, R1

A2D: 0x290 15483630 0x2bc0e0 2867424

A2D: 0x280 15483870 0x143c 5180

A2D: 0x290 15484110 0x2bb542 2864450

A2D: 0x280 15484350 0x1b06 6918

Listing 1: A small snippet from an IAR Embedded Workbench SWO-trace log.The log contains message type, timestamp and data. The timestamp is theprocessor cycle counter, running at 75 MHz.

25

Page 26: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

3.10 Data processing

I computed the model parameters with linear least square regression. I con-structed an overdetermined linear system with a state matrix and a vector withcurrent measurements.

The model parameters summarize the consumption of the system. From themodel parameters and the instrumentation data, I computed the raw estimateof the current consumption. The raw estimate is the product of the state matrixand the model parameters.

To compute the dynamics of the system, I computed the FIR Wiener filterthat minimizes the residual between the raw estimate and measured current asdescribed in 3.5. This filter is the impulse response of the power delivery routecircuitry between the measurement point and the power sink.

I increased the number of filter taps until the response got accurate enough.The sum of the filter taps, the constant gain, should be very close to 1 if thefilter is reasonable. I truncated the filter when the last tap in the filter was lessthan 0.01. This means that the truncation error in the step response is 1%. Thefigures 17 and 18 in section 4.4.2 illustrate what this looks like.

The data processing and visualization was done with Python 2.7 and the mod-ules numpy, scipy and matplotlib.

26

Page 27: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

4 Results and analysis

This chapter presents the results from my measurements.

4.1 Prestudy with manual analysis

I first did some manual analysis on the SensorTag and LaunchPad by varyingthe supply voltage and measuring the current consumption. The results areshown in the figures 8 and 9.

The current consumptions of the LEDs are independent and additive; the cur-rent increase from one LED is the same regardless of if the other LED is on or off.The dashed line in figures 8 and 9 is the sum of the two single LED consumptionincreases relative to the base consumption: Base + (Red-Base) + (Green-Base).It corresponds very well to the measurement with both LEDs on.

The base consumption is the same in both the SensorTag and the Launchpad.This is the “Active Mode (MCU Running, No Peripherals) Current Consumptionvs Supply Voltage (VDDS)” graph in the data sheet for this processor. [24]

The largest difference between the boards in the manual measurement was thered LED. The red LED in the SensorTag consumed much less current than thered LED in the LaunchPad.

The change in supply voltage has different effect on different system parts. Thediodes consume more current for higher voltages, and the MCU consumes lesscurrent for higher voltages.

The current consumption has several discontinuities occurring at the same sup-ply voltages for both the SensorTag and LaunchPad. The discontinuities areonly present in the LED-dependent part of the current consumption. The baseconsumption is not affected. The discontinuities are located on approximately{5, 6, 7}·390 mV. I am not sure what causes this phenomenon, but it might berelated to the DC-DC converter, as a lower voltage gives a lower efficiency.

The current consumption is a linear function of voltage as long as the supplyvoltage does not vary too much and does not cross any of the discontinuities.The automated measurements were performed at voltages above 2.8 V.

27

Page 28: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

1800 2000 2200 2400 2600 2800 3000Supply voltage [mV]

5

6

7

8

Curre

nt [m

A]

Varying voltage for SensorTagBoth LEDs onRed onGreen onNo LED onLinear estimate

Figure 8: The average current consumption of the SensorTag for differentsupply voltages and states. The higher currents have a slightly lower supplyvoltage due to the voltage drop over the shunt resistor. The higher current datapoints are shifted slightly to the left.

1750 2000 2250 2500 2750 3000 3250 3500Supply voltage [mV]

4

5

6

7

8

9

10

11

Curre

nt [m

A]

Varying voltage for CC2650 LaunchPadBoth LEDs onRed onGreen onNo LED onLinear estimate

Figure 9: The average current consumption of the LaunchPad for differentsupply voltages and states. The discontinuities are located at the same voltagesas in figure 8, but the current consumed by the LEDs are different.

28

Page 29: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

Table 2: The current consumption for the different parts of the system whenrunning at 3 V, computed with automated analysis.

LaunchPad Base Red Green

Active current consumption [mA] 4.150 2.318 2.158Duty cycle 100.0% 50.00% 50.03%Average current consumption [mA] 4.150 1.159 1.079

SensorTag Base Red Green

Active current consumption [mA] 4.436 1.272 2.481Duty cycle 100.0% 50.02% 50.46%Average current consumption [mA] 4.436 0.6363 1.252

4.2 Automated analysis

I used the I-scope probe to perform automatic current measurements. Fromthe measurements, I computed the parameters for the different states. As thecurrent consumption is voltage dependent, I chose to evaluate it at 3 volts.

The consumption for the different states are listed in table 2. The averagecurrent consumption is the product of the active current consumption and theduty cycle. As expected, the duty cycles of the diodes are approximately 50%.The duty cycles of the green LEDs deviate a bit more from this than the onesof the red LEDs, but that is also expected, as their cycle time was longer. TheSensorTag has a slightly higher base power consumption, probably because thatboard has more components on it that consumes power through leakage.

4.3 Parameter visualization

Although a table with parameters is an exact representation of the parameterdata, it is helpful to visualize it to get an overview of how the power consumptionis distributed in the system.

There are several ways to visualize the data, and different visualizations suitsdifferent needs. I present two ways here.

4.3.1 Pie chart

A pie chart is an easy way to present the power distribution. It gives an overviewof where the power goes, but does not tell if a system part has a high consump-tion because it has a high active consumption or a high duty cycle.

29

Page 30: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

Red LED

18.2%

Base

64.9%

Green LED

16.9%

LaunchPadRed LED

10.1%

Base

70.1%

Green LED

19.8%

SensorTag

Figure 10: The average current consumers in the LaunchPad and SensorTag.The base consumption is the largest consumer on both systems. The red LEDin the SensorTag consumes less power than the LED in the Launchpad.

10% 20% 30% 50% 100%Duty cycle

1

10

2

3

4

56789

Activ

e cu

rrent

con

sum

ptio

n [m

A]

LaunchPad

BaseRed LEDGreen LED

10% 20% 30% 50% 100%Duty cycle

1

10

2

3

4

56789

Activ

e cu

rrent

con

sum

ptio

n [m

A]

SensorTag

BaseRed LEDGreen LED

Figure 11: The current consumers in the LaunchPad and SensorTag. Thedashed lines indicate points with equal average current consumption. The redLED consumes less power in the SensorTag because it is more efficient. If ithad consumed less because of a lower duty cycle, it had been moved to the leftin the diagram.

30

Page 31: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

4.3.2 Log-log diagram

A more advanced way to visualize the summarized consumption is to use a log-log diagram. Although more refined, it might need some more explanation thanthe pie-chart.

As the average current consumption is the product of the duty cycle and theactive current consumption, the logarithm of the average current consumptionis the sum of the logarithms of the duty cycle and the active current.

A log-log diagram is formed by plotting the logarithm of the active currentconsumption against the logarithm of the duty cycle. Data points with the sameaverage current consumption will form diagonal lines in the log-log diagram.

4.3.3 Comparison

The data from table 2 is visualized in figures 10 and 11. The largest current con-sumer for both systems is the base consumption, both regarding active currentconsumption and duty cycle.

Both the pie-chart and the log-log diagram say that the red LED consumes lesspower than the green LED. But it is only from the log-log diagram that wecan see that the reason to this is that the red LED has a lower active currentconsumption.

A pie-chart does not need much explanation but does not show as much infor-mation as the log-log diagram. It is not clear what actions to take to reduce theconsumption by only looking at the pie-chart. Note that the information in thepie-chart is one-dimensional whereas the log-log diagram is two-dimensional.

From a power reduction perspective, it would be best to try to reduce the largestconsumer, the base consumption. The base consumption catches everything thatis not modeled, the largest non-modeled consumer is the MCU itself. It wouldbe wise to try to add the MCU to the model and then reduce the duty cycleof the MCU by making it go to sleep, or change it to one that consumes lesspower.

4.4 Time-based visualization

I previously mentioned that time-based visualizations can be hard to comparedue to synchronization problems, but there is an exception to this.

An instrumented measurement can be compared with a modeled consumptionif the model is driven from the instrumentation data, as this guarantees syn-chronization. This makes it possible to validate a set of model parameters tosee how well they fit and where they deviate.

31

Page 32: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

Figure 12: The measured and raw model current for the SensorTag. There arespikes in the residual on every state transition.

Figure 13: A zoomed in view on one of the residual peaks in the LaunchPad.

4.4.1 The raw model

To verify that the model is reasonable, the model errors should be small. Themeasurement residual is used to verify how big the model errors are. Figure 12shows the measured and modeled currents and their difference, the residual.

The model adapts well when the consumption is constant, but there is a mis-

32

Page 33: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

Figure 14: The measured current and filtered model current for the SensorTag.The spikes that were present in figure 12 are now suppressed.

match in the state transitions. Figure 13 shows a more zoomed in view ofa transition. The actual measurement takes some time to react to a systemchange, but the model changes immediately.

4.4.2 Model extended with system dynamics

To account for the rise/fall times in the measurement, I computed Wiener filtersto filter the modeled current. The filtered results are shown in figures 14, 15and 16. The filtering has removed the spikes that were previously present atthe state transitions. As a side result, the computed Wiener filters are theimpulse responses of the power delivery route. The impulse and step responsesare shown in figures 17, 18 and 19.

The impulse response for the SensorTag is twice as long as for the LaunchPad.This is probably because the LaunchPad has 1510 nF of decoupling capacitanceand the SensorTag has 3122 nF. If we see the power delivery circuitry as an RClow-pass filter, the rise/fall-time will double if we double the capacitance. Itwould probably be possible to compute the bandwidth of the measurements byFourier analysis of the impulse response.

The measurement with combined current/voltage in figure 16 is much noisierthan the current-only measurements. The impulse response from the combinedcurrent/voltage measurement, shown in figure 19, was also not as smooth as theones where only current was measured. The channel switching in the I-scopeintroduces noise. It is however much easier to perform the measurement thisway, as there is no need to measure the supply voltage separately.

33

Page 34: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

Figure 15: The measured current and filtered model current for the LaunchPad.

Figure 16: The filtered current for the LaunchPad with varying supply voltage.The modeled current follows the measured current when the voltage varies. Themeasured current is more noisy, as the I-scope measures both current and voltagein this setup and has to switch between the two channels.

34

Page 35: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

0 2000 4000 6000 8000Samples [1]

0.00

0.02

0.04

0.06

0.08

Impu

lse Step responseImpulse response

0.0

0.2

0.4

0.6

0.8

1.0

Step

Step and impulse responses for the LaunchPad

Figure 17: The impulse and step responses for the LaunchPad. The last tapin the impulse response holds the truncation for the filter. Its value is 0.01, sothe last jump in the step response is 1% of the total step.

0 5000 10000 15000 20000Samples [1]

0.00

0.01

0.02

0.03

0.04

Impu

lse Step responseImpulse response

0.0

0.2

0.4

0.6

0.8

1.0

Step

Step and impulse responses for the SensorTag

Figure 18: The impulse and step responses for the SensorTag. The last taphas the same height as in the LaunchPad, but its height relative to the rest ofthe filter is larger as this impulse response is distributed over more taps withlower intensities.

35

Page 36: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

0 1000 2000 3000 4000 5000Samples [1]

0.0

0.2

0.4

0.6Im

pulse Step response

Impulse response

0.0

0.2

0.4

0.6

0.8

1.0

Step

Step and impulse responses for the LaunchPad with varying voltage

Figure 19: The impulse and step responses for the LaunchPad when bothcurrent and voltage are measured with the I-scope.

4.5 Residual analysis

With a filtered model, the residual stays around zero. Any non-modeled phe-nomenon would be seen as a peak in the residual. This makes it possible tolocate new sources of power consumption in the system, and add them to themodel.

I connected a third LED to the LaunchPad, and told it to blink. But, I didnot add any instrumentation to this diode. The results are shown in figure 20.When the non-instrumented LED blinks there is a spike in the residual, so it ispossible to see that the model does not cover all of the system behaviour.

4.5.1 Current consumption depends on counter value

There is some information left in the signal after matching it to the model. Theresidual should be spectrally white if the prediction model is perfect.

I integrated the residual over time to see if there was a static error. The inte-grated residual is shown in figure 21.

There was no big static error, as the integral stayed around zero over time. Fora specific run, it it drifted at most 10 µJ from the estimate. The total energyconsumption for the system over 2.2 seconds was 49.5 mJ for the same run. Thedrift was about 0.02% of the total consumption.

There was a periodic variation in the integrated residual. The period of thispattern followed the green diode, but with a shift in phase.

36

Page 37: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

Figure 20: The measured current and filtered model current for the LaunchPadwith an extra non-instrumented LED connected. There is a peak in the residualwhen this new LED is turned on.

I suspected that the regular variation was due to the value of the counter variablein the program. I computed the Hamming-weight, the number of set bits, in anup-counting 16-bit counter. The expected Hamming-weight is the mean value8, so the residual is the Hamming weight minus 8. I computed the cumulativesum, this plot is shown in figure 22. The pattern is very similar to figure 21.

To verify this hypothesis, I did a measurement with a decrementing counter.The resulting shape, shown in figure 23, is flipped compared to figure 21.

The difference in current consumption between a 1-bit and 0-bit was in the orderof 10 µA. The consumption is more likely due to memory read/write operationsthan leakage, as the consumption of the CC2650 itself is only 1 µA in standbymode.[24] The difference between the model and measurement is visible in figure13 as the counter changes from many to few bits set at the transition.

4.5.2 Periodic peaks

There are still some small periodic spikes in the residual. They can be seenin figures 14 and 15. I’m not sure what causes these peaks, but it is out ofscope for this work to investigate that further. The peaks might come from theCortex-M0 coprocessor in the CC2650 or the DC-DC converter.

The integral of the small peaks can be seen in figure 24. The consumption ofthese peaks are included in the static consumption, as the curve does not driftaway.

37

Page 38: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

Figure 21: The cumulative sum of the residual. There is no constant errorin the residual, as the integrated signal stays around zero. There is a periodicpattern, so there is still information in the residual that the model has not takenin account.

Figure 22: A computer-generated plot of the cumulative sum of the Hammingweight minus its mean for a counter over two periods. Note the resemblancewith figure 21.

38

Page 39: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

Figure 23: The cumulative sum of the residual with a downwards counter. Theimportant part is the shape of the curve, which is flipped compared to figure21.

Figure 24: A close-up of figure 21, showing the cumulative sum of the residual.The steps are caused by the small periodic peaks that can be seen in figures 14and 15. Every peak consumes about 50-100 nJ.

39

Page 40: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

4.6 Failures and dead ends

This work has not been without failures. Some of my work has not lead tofruitful results. I list some of my mistakes here and hope that they are notrepeated by others.

4.6.1 State modeling

Before I found the work in [19], I simply used the mean value for each state.This was not good enough, as it did not take the varying voltage into account.

4.6.2 Dynamics modeling

I tried a few different filtering methods before I decided on the Wiener filterto model the system dynamics. My first approach was a single pole low passIIR-filter, on the form

y(n) = k · y(n − 1) + (k − 1) · x(n)

where 0 < k < 1. This filter worked to some degree, but required manual tuningof the constant k.

My second approach was to normalize all step responses to go from 0 to 1 andthen compute their mean value. This approach was more complicated to do,but did not require manual tuning. However, it did not have the same solidtheoretical foundation as the Wiener filter and the results were noisy. TheWiener filter also reliably gives the impulse response of the system. The noisymean step response can not be differentiated with good result.

4.6.3 Other hardware platforms

I had planned to compare more platforms in this work. I had four developmentboards with different Gecko processors from Silicon Labs. However, I couldnot get reliable measurements from these boards as the SWO-channel was notsynchronized with the current measurement data in IAR Embedded Workbench.

I also tried to use Silicon Labs own IDE, Simplicity Studio, to perform mea-surements, but I could not get timestamped ITM messages.

40

Page 41: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

5 Discussion

The measurement method is slightly intrusive to the software, as the programmust have instrumentation code added. But getting the same measurementusing only hardware is even more intrusive, so this is a reasonable trade-off.

Every part of the system that consumes power must be instrumented to beincluded in the model. However, this is typically only done once at the driverlevel. The instrumentation should be resilient to changes in the applicationlogic.

As of now, the model can not learn these new consumers automatically, as itneeds to have instrumentation in place. However, if the method can be inte-grated with a debugger it would be possible to make the instrumentation processeasier. IAR Embedded Workbench already has a feature to halt the programexecution when the power consumption exceeds certain limits. It would be pos-sible to halt the system when the power consumption deviates too much fromthe expected consumption and from there backtrack to the code that causedthe increase.

Adding instrumentation might increase power consumption, as more parts ofthe MCU are used. But the instrumentation is only used during development.It should be used to look at how a change affects the system. The effect ofa system change will probably be the same both with and without enabledinstrumentation.

The model generalizes to other forms of embedded systems. The state modelingand power prediction are not restricted to the Arm architecture, or even tomicrocontrollers. It would be possible to add similar instrumentation to anFPGA-based embedded system.

The model is scalable, adding more states only requires a larger state matrix.

The measurement method itself has been my focus in this study, but the methodcan be applied to a more complex system than I have studied. This requiresthat the application software has a well-defined hardware abstraction layer.Much like it is easier to add automated tests to software that is broken up intological functions, it would be easier to add instrumentation to software that doesnot touch hardware registers from the application logic. The instrumentationwould be added step by step for every system part until the model captures theconsumption behaviour well enough. The non-modeled consumption would bea part of the base consumption until it has been instrumented.

41

Page 42: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

It can be hard to prove that a system has optimal power consumption, as thereare many ways to reduce the power consumption of a system. Optimality mostoften requires some kind of limits, and limiting factors come as requirements.

Formal requirements make it easy to accept or dismiss suggested improvementsin a system. With requirements such as “The radio transmission power mustbe at least 10 dBm”, “The display rate must be at least 5 Hz” or perhaps mostcommon “The project must be finished within six months” the number of choicesare limited and everything within these limits can be tried. Data from measure-ments form a base to make well informed decisions that allow efficient allocationof development efforts. Good tools are essential when time is a limiting factor.

42

Page 43: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

6 Conclusions

The method can measure and present the individual power consumptions andduty-cycles of instrumented parts in an embedded system. As a side result, themethod also computes the impulse response of the power delivery route. Themodel can verify itself by computing the measurement residual and showingwhere there are model errors, and how big they are.

The method has not been limited by the resolution of the measurement equip-ment, the I-jet/I-scope. It was possible to observe power consumption variationsdepending on the values of variables in the program. It would not be practi-cal to extend the model to capture these variations. There is a trade-off whenmeasuring both current and voltage, the measurement setup is easier but theresults contain more noise.

The method requires the code to be instrumented. As of now, this must bedone manually but only needs to be done once for every system part. Themethod relies on that the I-jet/I-scope can synchronize debug data with powermeasurements.

43

Page 44: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

7 Future work

This chapter describes possible improvements to the method and other ideas forfuture work.

7.1 Automatic placement of instrumentation

In the present form, the method requires instrumentation to be added manually.It is however enough to do this once, if it is done at driver level. Can this processbe automated?

There is currently a feature in IAR Embedded Workbench to stop the executionwhen the power consumption goes above or below a threshold. With a powerestimation model this functionality could be extended to halt the executionwhen the power consumption deviates too much from the estimate. From thispoint it could be possible to backtrack to the point where the consumptionchange occurred.

The debug probe I-jet Trace has support for the more advanced debugginginterface ETM. The full instruction trace that ETM provides could be used tolocate the exact point where a consumption change occurred. The sampled PCon the SWO channel does not give enough resolution to allow this.

The Data Watchpoint and Trace Unit (DWT) could be used to monitor writesto the peripheral units. It is possible to capture both write destination and whatcode that caused the write. The DWT on CC2650 can monitor four 32 kB areasat once, but its peripherals use 14 MB of the address space. The instrumentationpoints could be located by sweeping the monitor areas over the address spaceduring several program executions.

7.2 Extending the model with transient events

Not all events that consume power are state-based, there are also transientevents. This could be seen as an event where only the ON-transition is instru-mented and the OFF-transition occurs after a fix time.

44

Page 45: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

7.3 Extending the model with variance

The expected noise level could be included in the prediction model. Some partsof the system might consume power in a stochastic way. For example, the powerconsumption of a UART might have a base cost and a part that depends on thetransmitted data.

The impact of noise in the model will be that the expected variance of theresidual will be larger. The mean value of the residual should be zero if thereare no model errors. If there was an expected variance, it would be possible tohalt the program if the residual exceeded this level too much.

7.4 Other architectures

In this work I have only looked at the Arm architecture and ITM instrumenta-tion. However, the method applies to other architectures as well. For FPGAs,it would be possible to insert monitoring on the signals that hold the systemstate and export them for external analysis. What would be the best way to dothis?

For the MSP430 architecture from TI, there exists a power monitoring featurecalled EnergyTrace++. This allows the developer to monitor not only powerconsumption and program counter, but also the state of the peripheral devices.This might mean that this architecture can use the measurement method with-out any manual instrumentation at all.

7.5 Driving the model to new states from power

measurements only

For a system with few states, low noise and distinct power levels it might bepossible to determine the system state solely from the current consumption. Inmy study, this holds for the SensorTag.

When is it possible to deduce the internal system state from power measure-ments? Can the measured current consumption be combined with debug datato make the method even more powerful?

45

Page 46: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

A Abbreviations

ADC Analog to Digital ConverterCMOS Complementary Metal Oxide SemiconductorCMSIS Arm Cortex Microcontroller Software Interface StandardDC Direct CurrentDPM Dynamic Power ManagementDV(F)S Dynamic Voltage (and Frequency) ScalingDWT Data Watchpoint and Trace UnitETM Embedded Trace MacrocellFIR Finite Impulse ResponseFPGA Field Programmable Gate ArrayGPIO General Purpose input and OutputIDE Integrated Development EnvironmentIIR Infinite Impulse ResponseITM Instrumentation Trace MacrocellLED Light Emitting DiodeMCU MicroController UnitPC Program CounterSPICE Simulation Program with Integrated Circuit EmphasisSWO Serial Wire OutputUART Universal Asynchronous Receiver and Transmitter

CCS Code Composer StudioTI Texas Instruments

46

Page 47: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

B Bibliography

[1] Elecia White. Making Embedded Systems: Design Patterns for Great Soft-ware. O’Reilly Media, Inc., 2011.

[2] Žilvinas Nakutis. Embedded systems power consumption measurementmethods overview. MATAVIMAI, 2(44):29–35, 2009.

[3] Luca Benini and Giovanni de Micheli. System-level power optimization:techniques and tools. ACM Transactions on Design Automation of Elec-tronic Systems (TODAES), 5(2):115–192, 2000.

[4] Sparsh Mittal. A survey of techniques for improving energy efficiency inembedded computing systems. International Journal of Computer AidedEngineering and Technology, 6(4):440–459, 2014.

[5] Roman Lim and Lothar Thiele. Testbed assisted control flow tracing forwireless embedded systems. In Proceedings of the 2017 International Con-ference on Embedded Wireless Systems and Networks, EWSN ’17, pages180–158, 2017.

[6] ARM. CMSIS-Core, Cortex Microcontroller Software Interface Standard,February 2017. Version 5.0.1.

[7] ARM. Coresight R© Technical Introduction, August 2013. Document: ARM-EPM-039795.

[8] ARM. Coresight R© Components Technical Reference Manual, July 2009.Document: ARM DDI 0314H.

[9] Atmel Corporation. Power Debugger User Guide, November 2016. Docu-ment: Atmel-42696D-Power-Debugger_User Guide-10/2016.

[10] IAR Systems. IAR Debug probes User Guide, seventh edition, October2017. Document: IARprobes-7.

[11] T. Dirsch and G. Keding. User Manual PowerScale. Hitex DevelopmentTools GmbH, December 2011. Rev. 12/2011 - 008.

[12] Lauterbach GmbH. IProbe User’s Guide, November 2016.

[13] SEGGER. J-Link / J-Trace User Guide. SEGGER Microcontroller GmbH& Co. KG, June 2016. Document: UM08001 V6.00 Rev. 1.

[14] Silicon Laboratories. USER MANUAL : Starter Kit EFM32ZG-STK3200,October 2013. Document: t0032_1.00.

47

Page 48: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

[15] Texas Instruments. XDS110 Debug Probe User’s Guide, January 2017.Document: SPRUI94.

[16] J. Zipperer and P. Weber. Electronic device and method for power mea-surement, June 20 2013. US Patent App. 13/329,073.

[17] Torkel Glad and Lennart Ljung. Reglerteori, Flervariabla och olinjärametoder. Studentlitteratur, second edition, 2003.

[18] Stefan Schürmans, Diandian Zhang, Dominik Auras, Rainer Leupers, GerdAscheid, Xiaotao Chen, and Lun Wang. Creation of ESL power models forcommunication architectures using automatic calibration. In Proceedingsof the 50th Annual Design Automation Conference, page 58. ACM, 2013.

[19] Stefan Schürmans, Gereon Onnebrink, Rainer Leupers, Gerd Ascheid, andXiaotao Chen. Frequency-aware ESL power estimation for ARM Cortex-A9 using a black box processor model. ACM Transactions on EmbeddedComputing Systems (TECS), 16(1):26, 2016.

[20] Fredrik Gustafsson, Lennart Ljung, and Mille Millnert. Signalbehandling.Studentlitteratur, second edition, 2001.

[21] Amanda Nordhamn. Design and implementation of a demonstrator for aBluetooth low energy based fleet service system for hand-held gardeningand forestry products. Master’s thesis, Uppsala University, 2016.

[22] Anna Lindholm, Marika Karlsson, and Nilsánu Pirak Sikku. Praktisk im-plementering av fjärrstyrt lås: Baserad på RTOS-teknik och Bluetooth lowenergy. Technical report, Uppsala University, 2016.

[23] Andrew Aziz, Ludwing Franquiz, Max Wijnbladh, Eric Wang(Yiqing),Maria Namaghi Rajabzadeh, Johan Snider, Sami Kaivonen, AdrianAmigues, and Eirini Petraki. Design, development and deployment of aninformation-centric networking based solution for the internet-of-things.Technical report, Uppsala University, 2017.

[24] Texas Instruments. Datasheet: CC2650 SimpleLink R© Multistandard Wire-less MCU, July 2016. Document: SWRS158B.

[25] Analog Devices. LTspice Information Flyer & Shortcuts, March 2017.

48

Page 49: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

C Computation example

This is a hands on example of how to compute the model parameters from mea-surement data and how to create measurement data from computer simulations.

C.1 Acquiring data from a simulated circuit

A measurement session with an I-jet/I-scope can generate several hundred mega-bytes of data, so this report can not provide a full set of real measurement data.However, it is possible to run a computer simulation to generate data to test thecomputation process with. This allows those who don’t have access to hardwareor prefer a simulated environment to evaluate the method.

Electrical circuits can be simulated on a computer, this is called SPICE - Simu-lation Program with Integrated Circuit Emphasis. A popular program to do thiswith is LTspice from Analog Devices. This program is freeware and features aSPICE engine, schematic capture and a waveform viewer. [25]

Figure 25 shows an LTspice model for a circuit with two LEDs. The circuitis heavily influenced from the power delivery schematics in [2]. The LEDsare controlled with two switches operated by two pulse generators. As whenmeasuring with the I-scope probe, the circuit has a shunt resistor connectedin series with the power supply. The power consumption of the circuit can bedetermined by measuring the supply and shunt voltages.

The major difference between a simulation and real hardware is the instrumen-tation process. In a real measurement, the state is given by ITM messagesto the debugger. The simulated circuit has no microcontroller, but it can beinstrumented by exporting the two control voltages together with the currentconsumption and supply voltage.

The computation needs four signals: the two measurement signals V1 and I+,and the two instrumentation signals Vctrl1 and Vctrl2. To export data fromLTspice, first run the simulation then select the menu File, Export data as

text, and tick the four signals to export.

The exported data is a tab-separated flat file, listed in section C.3. The datais sampled at non-regular time intervals to capture enough detail when neededand not be too verbose when the signals are not changing. The data must beresampled as FIR filtering requires a fixed sample frequency.

49

Page 50: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

Vsupply

PWL(0 3.2 200ms 3.3) R1

220

R2

220

R3

1k

R4

10

C1

10µF

PULSE(0 1 30ms 1us 1us 50ms)

V2

PULSE(0 1 50ms 1us 1us 50ms)

V3

S1 S2

D1

NSCW100

D2

LXK2­PW14

V1I+

Vctrl1 Vctrl2

.tran 0 110ms 10ms 500us

.model mysw SW(Ron=1 Roff=1Meg Vt=.5 Vh=­.4)

Power deliveryroute model

Baseconsumption

First LED model Second LED modelMeasurement point

Figure 25: A model circuit set up in LTspice.

0 20 40 60 80 100Time [ms]

2

0

2

4

6

Curre

nt [m

A]

Raw model

Measured currentModel estimateResidual

0 20 40 60 80 100Time [ms]

0

1

2

3

4

5

6

7Cu

rrent

[mA]

Filtered model

Measured currentModel estimateResidual

Figure 26: The residual plots from the simulated data.

C.2 Implementation of parameter computation

The full computation process is shown in listing 3. The program parses theLTspice trace file, constructs the linear equation system for the consumption ofthe different states and computes the system dynamics.

A part that might need some explanation are lines 65-69. Here the matrix from(3.2) is extended with a new column and row. As the autocorrelation matrixis a symmetric Toeplitz matrix, the new column/row contains the values of theprevious last column combined with the new correlation value in the cornersfurthest away from the diagonal.

For the dynamics computation there is trick involved to avoid a sharp step atthe start of the measurement. All values are shifted down, so that the firstsample becomes zero. These are the variables ending with ADJ at lines 52-53.

The resulting plots are shown in figure 26. The raw model data fits well to themeasurements, but the filtered data matches even in the state transitions.

50

Page 51: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

Listing 3: Python implementation

1 ’’’2 Computes power consumption parameters from the LTspice trace data stored3 in the file "schematic.txt" and plots the results to the file "plot.pdf".45 If you copy and paste this code, you will need to replace the characters: ’∗−6 ’’’7 __author__ = ’Lars Haulin’89 import numpy as np

10 from matplotlib import pyplot as plt11 import scipy.signal1213 ## Extract the data from LTSpice trace file14 lines = open(’schematic.txt’).readlines()15 columns = lines[0].split() # first line contains column names16 data = [map(float, l.split()) for l in lines[1:]]1718 tRaw = [d[columns.index(’time’)] for d in data]19 ipRaw = [d[columns.index(’V(i+)’)] for d in data]20 v1Raw = [d[columns.index(’V(v1)’)] for d in data]21 d1Raw = [d[columns.index(’V(vctrl1)’)] for d in data]22 d2Raw = [d[columns.index(’V(vctrl2)’)] for d in data]2324 R = 10 # Shunt resistance of circuit is 10 ohms25 iRaw = [(ip−v)/R for ip,v in zip(ipRaw,v1Raw)]2627 ## Resample the data, as LTSpice does not use regular time intervals28 N = 10001 # 10000 steps are 10001 data points29 tSamp = np.linspace(0, max(tRaw), N)30 iSamp = np.interp(tSamp, tRaw, iRaw)31 vSamp = np.interp(tSamp, tRaw, v1Raw)32 state_s1 = (np.interp(tSamp, tRaw, d1Raw) > 0.5) ∗ 1.033 state_s2 = (np.interp(tSamp, tRaw, d2Raw) > 0.5) ∗ 1.03435 ## Create parameter equation system, the state matrix36 S = np.ones((N,6)) # The first column holds only ones37 S[:,1] = state_s138 S[:,2] = state_s239 S[:,3] = vSamp40 S[:,4] = vSamp ∗ state_s141 S[:,5] = vSamp ∗ state_s24243 ## Compute model parameters using least squares44 parameters, _, _, _ = np.linalg.lstsq(S, iSamp, rcond=−1)4546 # Compute the raw model current by inserting the parameters in the system47 iEstimate= S.dot(parameters)48

51

Page 52: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

49 # In this example, the data is so short that the first transient will have50 # a large (and invalid) impact on the filter. We shift all values so that51 # the computation does not see any initial transient.52 iEstimateADJ = iEstimate − iEstimate[0]53 iSampADJ = iSamp − iEstimate[0]5455 ## Iteratively compute the filter to model the system dynamics. This is the56 # filter f that minimizes the 2−norm of (iSamp − convolution(f, iEstimate))5758 # Create an initial 1x1 autocorrelation matrix and a covariance vector b59 autoCorr = np.array([[iEstimateADJ.T.dot(iEstimateADJ)]])60 b = np.array([iSampADJ.dot(iEstimateADJ)])6162 for filterLen in xrange(1,200): # 200 is just an arbitrary high limit63 # The actual filter length is filterLen+1, but easier to code this way6465 # Compute new autocorrelation value and add to autocorrelation matrix66 corrVal = iEstimateADJ[filterLen:].T.dot(iEstimateADJ[:−filterLen])67 col = np.concatenate(([[corrVal]],autoCorr[:,−1:]))68 autoCorr = np.append(autoCorr, col[:−1],1)69 autoCorr = np.append(autoCorr, col.T,0)7071 # Compute new covariance value and append to covariance vector72 b = np.append(b,iSampADJ.T[filterLen:].dot(iEstimateADJ[:−filterLen]))7374 # The filter is the solution to the autocorrelation/covariance system.75 f = np.linalg.solve(autoCorr, b)7677 # Sum of FIR taps should be 1, the constant gain.78 # Last filter tap is approximately the truncation error.79 if abs(f[−1]) < 0.01:80 # Truncation error less than one percent, we are done.81 break

8283 ## Apply filter to estimate, and truncate to N samples84 fiEst= scipy.signal.convolve(iEstimate, f, mode=’full’)[:N]8586 ## Plot the results, using milli−prefix87 plt.figure(figsize=(10,4))88 for sp, est, t, in ((’121’,iEstimate,’Raw’), (’122’,fiEst,’Filtered’)):89 plt.subplot(sp)90 plt.plot(1000∗tSamp, 1000∗iSamp,’−’,label=’Measured current’)91 plt.plot(1000∗tSamp, 1000∗est,’−.’, label=’Model estimate’)92 plt.plot(1000∗tSamp, 1000∗(iSamp−est), ’:’,label=’Residual’)93 plt.legend()94 plt.ylabel(’Current [mA]’)95 plt.xlabel(’Time [ms]’)96 plt.title(t+’ model’)97 plt.savefig(’plot.pdf’)

52

Page 53: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

C.3 Simulation data from LTspice model

time V(i+) V(v1) V(vctrl1) V(vctrl2)

0.000000000000000e+000 3.205000e+000 3.173187e+000 0.000000e+000 0.000000e+000

1.999900000000000e-002 3.214999e+000 3.183087e+000 0.000000e+000 0.000000e+000

2.000000000000000e-002 3.215000e+000 3.183087e+000 4.545455e-002 0.000000e+000

2.000010000000000e-002 3.215000e+000 3.183087e+000 1.000000e-001 0.000000e+000

2.000030000000000e-002 3.215000e+000 3.183081e+000 3.000000e-001 0.000000e+000

2.000040181963920e-002 3.215000e+000 3.183062e+000 4.018196e-001 0.000000e+000

2.000045428056004e-002 3.215000e+000 3.183026e+000 4.542806e-001 0.000000e+000

2.000049494070488e-002 3.215000e+000 3.182973e+000 4.949407e-001 0.000000e+000

2.000054359338815e-002 3.215000e+000 3.182908e+000 5.435934e-001 0.000000e+000

2.000057861516245e-002 3.215000e+000 3.182890e+000 5.786152e-001 0.000000e+000

2.000061017182567e-002 3.215000e+000 3.182897e+000 6.101719e-001 0.000000e+000

2.000064746615520e-002 3.215000e+000 3.182905e+000 6.474662e-001 0.000000e+000

2.000068569478713e-002 3.215000e+000 3.182904e+000 6.856948e-001 0.000000e+000

2.000073685647676e-002 3.215000e+000 3.182896e+000 7.368565e-001 0.000000e+000

2.000078748054886e-002 3.215000e+000 3.182889e+000 7.874805e-001 0.000000e+000

2.000088872869308e-002 3.215000e+000 3.182873e+000 8.887287e-001 0.000000e+000

2.000100000000000e-002 3.215000e+000 3.182857e+000 1.000000e+000 0.000000e+000

2.000750937145467e-002 3.215004e+000 3.181955e+000 1.000000e+000 0.000000e+000

2.001401874290934e-002 3.215007e+000 3.181110e+000 1.000000e+000 0.000000e+000

2.002052811436401e-002 3.215010e+000 3.180324e+000 1.000000e+000 0.000000e+000

2.002703748581869e-002 3.215013e+000 3.179596e+000 1.000000e+000 0.000000e+000

2.003354685727336e-002 3.215017e+000 3.178926e+000 1.000000e+000 0.000000e+000

2.004005622872803e-002 3.215020e+000 3.178314e+000 1.000000e+000 0.000000e+000

2.004656560018270e-002 3.215023e+000 3.177760e+000 1.000000e+000 0.000000e+000

2.009214232749609e-002 3.215046e+000 3.174709e+000 1.000000e+000 0.000000e+000

2.018329578212287e-002 3.215092e+000 3.171527e+000 1.000000e+000 0.000000e+000

2.036560269137644e-002 3.215183e+000 3.169444e+000 1.000000e+000 0.000000e+000

2.073021650988357e-002 3.215365e+000 3.168924e+000 1.000000e+000 0.000000e+000

2.113021650988357e-002 3.215565e+000 3.169106e+000 1.000000e+000 0.000000e+000

2.153021650988356e-002 3.215765e+000 3.169302e+000 1.000000e+000 0.000000e+000

2.193021650988356e-002 3.215965e+000 3.169494e+000 1.000000e+000 0.000000e+000

2.233021650988356e-002 3.216165e+000 3.169688e+000 1.000000e+000 0.000000e+000

4.000000000000000e-002 3.225000e+000 3.178222e+000 1.000000e+000 0.000000e+000

4.000010000000000e-002 3.225000e+000 3.178222e+000 1.000000e+000 1.000000e-001

4.000030000000000e-002 3.225000e+000 3.178203e+000 1.000000e+000 3.000000e-001

4.000048341062950e-002 3.225000e+000 3.178055e+000 1.000000e+000 4.834106e-001

4.000063317874100e-002 3.225000e+000 3.177838e+000 1.000000e+000 6.331788e-001

4.000079583551169e-002 3.225000e+000 3.177690e+000 1.000000e+000 7.958355e-001

4.000082744843113e-002 3.225000e+000 3.177684e+000 1.000000e+000 8.274484e-001

4.000089067427000e-002 3.225000e+000 3.177682e+000 1.000000e+000 8.906743e-001

4.000100000000000e-002 3.225000e+000 3.177678e+000 1.000000e+000 1.000000e+000

4.000107652801100e-002 3.225001e+000 3.177674e+000 1.000000e+000 1.000000e+000

4.000116398859500e-002 3.225001e+000 3.177665e+000 1.000000e+000 1.000000e+000

4.000133890976301e-002 3.225001e+000 3.177639e+000 1.000000e+000 1.000000e+000

4.000168875209902e-002 3.225001e+000 3.177564e+000 1.000000e+000 1.000000e+000

4.000206450963400e-002 3.225001e+000 3.177471e+000 1.000000e+000 1.000000e+000

4.000718077564484e-002 3.225004e+000 3.176203e+000 1.000000e+000 1.000000e+000

4.001229704165569e-002 3.225006e+000 3.175005e+000 1.000000e+000 1.000000e+000

4.001741330766653e-002 3.225009e+000 3.173877e+000 1.000000e+000 1.000000e+000

4.002252957367739e-002 3.225011e+000 3.172817e+000 1.000000e+000 1.000000e+000

4.002764583968823e-002 3.225014e+000 3.171827e+000 1.000000e+000 1.000000e+000

4.003276210569907e-002 3.225016e+000 3.170907e+000 1.000000e+000 1.000000e+000

4.003787837170992e-002 3.225019e+000 3.170056e+000 1.000000e+000 1.000000e+000

4.007386047965778e-002 3.225037e+000 3.165194e+000 1.000000e+000 1.000000e+000

4.014582469555349e-002 3.225073e+000 3.159602e+000 1.000000e+000 1.000000e+000

4.028975312734492e-002 3.225145e+000 3.155271e+000 1.000000e+000 1.000000e+000

4.057760999092779e-002 3.225289e+000 3.153550e+000 1.000000e+000 1.000000e+000

4.097760999092778e-002 3.225489e+000 3.153586e+000 1.000000e+000 1.000000e+000

4.137760999092778e-002 3.225689e+000 3.153791e+000 1.000000e+000 1.000000e+000

4.177760999092778e-002 3.225889e+000 3.153971e+000 1.000000e+000 1.000000e+000

4.217760999092778e-002 3.226089e+000 3.154159e+000 1.000000e+000 1.000000e+000

4.257760999092777e-002 3.226289e+000 3.154345e+000 1.000000e+000 1.000000e+000

4.297760999092777e-002 3.226489e+000 3.154531e+000 1.000000e+000 1.000000e+000

4.674903856235632e-002 3.228374e+000 3.156286e+000 1.000000e+000 1.000000e+000

5.052046713378487e-002 3.230260e+000 3.158041e+000 1.000000e+000 1.000000e+000

5.429189570521342e-002 3.232146e+000 3.159796e+000 1.000000e+000 1.000000e+000

5.806332427664198e-002 3.234032e+000 3.161551e+000 1.000000e+000 1.000000e+000

6.183475284807053e-002 3.235917e+000 3.163306e+000 1.000000e+000 1.000000e+000

6.560618141949909e-002 3.237803e+000 3.165060e+000 1.000000e+000 1.000000e+000

6.937760999092762e-002 3.239689e+000 3.166815e+000 1.000000e+000 1.000000e+000

6.960200000000001e-002 3.239801e+000 3.166919e+000 1.000000e+000 1.000000e+000

7.000100000000001e-002 3.240000e+000 3.167105e+000 1.000000e+000 1.000000e+000

7.000110000000001e-002 3.240000e+000 3.167106e+000 9.000000e-001 1.000000e+000

7.000130000000002e-002 3.240001e+000 3.167129e+000 7.000000e-001 1.000000e+000

7.000146089450701e-002 3.240001e+000 3.167184e+000 5.391055e-001 1.000000e+000

7.000165151073830e-002 3.240001e+000 3.167272e+000 3.484893e-001 1.000000e+000

7.000167544016939e-002 3.240001e+000 3.167279e+000 3.245598e-001 1.000000e+000

7.000172329903157e-002 3.240001e+000 3.167286e+000 2.767010e-001 1.000000e+000

53

Page 54: A state-based method to model and analyze the power ...uu.diva-portal.org/smash/get/diva2:1256415/FULLTEXT01.pdf · UPTEC F 18050 Examensarbete 30 hp September 2018 A state-based

7.000181901675592e-002 3.240001e+000 3.167301e+000 1.809832e-001 1.000000e+000

7.000185852542275e-002 3.240001e+000 3.167306e+000 1.414746e-001 1.000000e+000

7.000192098266636e-002 3.240001e+000 3.167315e+000 7.901733e-002 1.000000e+000

7.000200000000001e-002 3.240001e+000 3.167327e+000 0.000000e+000 1.000000e+000

7.000207111560029e-002 3.240001e+000 3.167337e+000 0.000000e+000 1.000000e+000

7.000214223120058e-002 3.240001e+000 3.167347e+000 0.000000e+000 1.000000e+000

7.000221334680086e-002 3.240001e+000 3.167357e+000 0.000000e+000 1.000000e+000

7.000228446240114e-002 3.240001e+000 3.167367e+000 0.000000e+000 1.000000e+000

7.000235557800143e-002 3.240001e+000 3.167377e+000 0.000000e+000 1.000000e+000

7.000242669360171e-002 3.240001e+000 3.167388e+000 0.000000e+000 1.000000e+000

7.000249780920199e-002 3.240001e+000 3.167398e+000 0.000000e+000 1.000000e+000

7.000294966224603e-002 3.240001e+000 3.167462e+000 0.000000e+000 1.000000e+000

7.000343093350002e-002 3.240002e+000 3.167530e+000 0.000000e+000 1.000000e+000

7.000411924933749e-002 3.240002e+000 3.167626e+000 0.000000e+000 1.000000e+000

7.000495836604695e-002 3.240002e+000 3.167743e+000 0.000000e+000 1.000000e+000

7.000626698304897e-002 3.240003e+000 3.167923e+000 0.000000e+000 1.000000e+000

7.000780238853759e-002 3.240004e+000 3.168131e+000 0.000000e+000 1.000000e+000

7.001001474797071e-002 3.240005e+000 3.168425e+000 0.000000e+000 1.000000e+000

7.001268623079712e-002 3.240006e+000 3.168770e+000 0.000000e+000 1.000000e+000

7.001655411792448e-002 3.240008e+000 3.169253e+000 0.000000e+000 1.000000e+000

7.002125692998906e-002 3.240011e+000 3.169815e+000 0.000000e+000 1.000000e+000

7.002789400938300e-002 3.240014e+000 3.170560e+000 0.000000e+000 1.000000e+000

7.003610679226918e-002 3.240018e+000 3.171413e+000 0.000000e+000 1.000000e+000

7.004781690443224e-002 3.240024e+000 3.172507e+000 0.000000e+000 1.000000e+000

7.006295572439532e-002 3.240031e+000 3.173730e+000 0.000000e+000 1.000000e+000

7.008592706188943e-002 3.240043e+000 3.175243e+000 0.000000e+000 1.000000e+000

7.011997672706025e-002 3.240060e+000 3.176877e+000 0.000000e+000 1.000000e+000

7.018588540497740e-002 3.240093e+000 3.178757e+000 0.000000e+000 1.000000e+000

7.031770276081172e-002 3.240159e+000 3.180369e+000 0.000000e+000 1.000000e+000

7.058133747248035e-002 3.240291e+000 3.181237e+000 0.000000e+000 1.000000e+000

7.098133747248035e-002 3.240491e+000 3.181520e+000 0.000000e+000 1.000000e+000

7.138133747248035e-002 3.240691e+000 3.181702e+000 0.000000e+000 1.000000e+000

7.178133747248035e-002 3.240891e+000 3.181895e+000 0.000000e+000 1.000000e+000

7.218133747248035e-002 3.241091e+000 3.182085e+000 0.000000e+000 1.000000e+000

7.258133747248034e-002 3.241291e+000 3.182276e+000 0.000000e+000 1.000000e+000

9.000100000000001e-002 3.250000e+000 3.190572e+000 0.000000e+000 1.000000e+000

9.000110000000001e-002 3.250000e+000 3.190574e+000 0.000000e+000 9.000000e-001

9.000130000000002e-002 3.250001e+000 3.190639e+000 0.000000e+000 7.000000e-001

9.000160000000002e-002 3.250001e+000 3.190871e+000 0.000000e+000 4.000000e-001

9.000163346093142e-002 3.250001e+000 3.190892e+000 0.000000e+000 3.665391e-001

9.000170038279422e-002 3.250001e+000 3.190912e+000 0.000000e+000 2.996172e-001

9.000183422651982e-002 3.250001e+000 3.190948e+000 0.000000e+000 1.657735e-001

9.000200000000001e-002 3.250001e+000 3.190993e+000 0.000000e+000 0.000000e+000

9.000214919613218e-002 3.250001e+000 3.191033e+000 0.000000e+000 0.000000e+000

9.000229839226437e-002 3.250001e+000 3.191073e+000 0.000000e+000 0.000000e+000

9.000244758839654e-002 3.250001e+000 3.191113e+000 0.000000e+000 0.000000e+000

9.000259678452871e-002 3.250001e+000 3.191152e+000 0.000000e+000 0.000000e+000

9.000274598066088e-002 3.250001e+000 3.191192e+000 0.000000e+000 0.000000e+000

9.000289517679307e-002 3.250001e+000 3.191232e+000 0.000000e+000 0.000000e+000

9.000304437292524e-002 3.250001e+000 3.191271e+000 0.000000e+000 0.000000e+000

9.000410532319847e-002 3.250002e+000 3.191550e+000 0.000000e+000 0.000000e+000

9.000554586483266e-002 3.250003e+000 3.191925e+000 0.000000e+000 0.000000e+000

9.000770646350982e-002 3.250004e+000 3.192475e+000 0.000000e+000 0.000000e+000

9.001081810703396e-002 3.250005e+000 3.193245e+000 0.000000e+000 0.000000e+000

9.001607978022524e-002 3.250008e+000 3.194491e+000 0.000000e+000 0.000000e+000

9.002351369650533e-002 3.250012e+000 3.196137e+000 0.000000e+000 0.000000e+000

9.003509666844636e-002 3.250018e+000 3.198459e+000 0.000000e+000 0.000000e+000

9.005170391180432e-002 3.250026e+000 3.201330e+000 0.000000e+000 0.000000e+000

9.007833567202882e-002 3.250039e+000 3.205032e+000 0.000000e+000 0.000000e+000

9.011652621947740e-002 3.250058e+000 3.208889e+000 0.000000e+000 0.000000e+000

9.017608992412225e-002 3.250088e+000 3.212673e+000 0.000000e+000 0.000000e+000

9.026186197660124e-002 3.250131e+000 3.215491e+000 0.000000e+000 0.000000e+000

9.039615751710450e-002 3.250198e+000 3.217216e+000 0.000000e+000 0.000000e+000

9.059033802917736e-002 3.250295e+000 3.217921e+000 0.000000e+000 0.000000e+000

9.089235638519280e-002 3.250446e+000 3.218181e+000 0.000000e+000 0.000000e+000

9.129235638519280e-002 3.250646e+000 3.218380e+000 0.000000e+000 0.000000e+000

9.249235638519279e-002 3.251246e+000 3.218974e+000 0.000000e+000 0.000000e+000

9.969235638519275e-002 3.254846e+000 3.222538e+000 0.000000e+000 0.000000e+000

1.000000000000000e-001 3.255000e+000 3.222691e+000 0.000000e+000 0.000000e+000

e15ddd9 54