Using hardware to save energy in MCU-based sensing applications -

Using hardware to save energy in MCU-based sensing applications

Low-power design is an exercise that demands a combination of software, hardware and application understanding to minimize the energy consumed by the embedded system. It is easy to waste energy by failing to balance the trade-offs of flexible software-based processing against more restricted but often more energy-efficient hardware. But subtle changes to hardware implementation can make large differences to overall energy consumption.

The goal of low-energy MCU design generally is to maintain a low duty cycle such that the processor within the system spends almost all of its time asleep. This has proved highly effective in the design of utility meters where the processor core may sleep for 99% of its overall life cycle. It wakes only to collect data from sensor inputs, normally at a scheduled time or to respond to rare, unscheduled interrupts.

The importance of duty cycle can be seen from an analysis of the dynamic energy consumption of an MCU versus its energy demand during sleep. Time is the enemy in any battery-powered application where long periods of autonomy are needed as even apparently small power consumption values become significant over long periods of activity.

During periods of activity, the power consumption of any logic is given by the formula CV²f where C is the total capacitance of the circuit paths within the device, V is the supply voltage and f is the operating frequency. This formula is slightly complicated by the widespread use of clock gating in most modern processor cores, which limits switching activity in unused logic by temporarily disabling the clock signal to those circuits. However, the approximation provides a good guide to active power consumption.

Low-power MCUs are generally implemented on low-leakage processes but there remains a leakage component to energy consumption that becomes significant for any logic block that is active over a long period of time. The leakage power is a constant value, although it tends to rise with operating temperature because of the increase of thermally generated carriers in the transistors. The only way to reduce leakage power beyond careful process design is to withdraw power from the logic block.

To provide designers with a number of ways to combat power consumption, low-energy MCUs provide a number of sleep modes that progressively withdraw power from the various component cores, storing their state in non-volatile memory or dedicated low-leakage registers, until almost all of the device has been powered down.

To provide an example of the difference, an Energy Micro EFM32 Gecko consumes 5mW while running fully active at a clock frequency of 10MHz and a supply voltage of 3V. In its lowest-power mode, the same device consumes 60nW – almost six orders of magnitude lower.

A further consideration in determining overall power consumption is the energy cost of wake-up time (Figure 1 below ). It can take time for the phase-locked loops (PLLs) that supply a stable clock signal to the core to stabilize and for state information to be fully restored. During this period, the power demand will ramp up but the waking parts of the device will not be able to perform useful work until they have had their power and state fully restored. Therefore, an important consideration in selecting a low-energy MCU is how long this period is.

Figure 1: The inefficient wake-up period from deep sleep mode to active mode simply cannot be neglected. By reducing wake-up period, as little energy as possible is consumed before the CPU starts performing its tasks.

At a duty cycle of 1 per cent, where the device designed to run at 10MHz wakes every second for a period of 10ms with a wakeup time of 2ms, an MCU rated at 200µA/MHz with a deep-sleep mode running at 2µA may operate for 12.7 years from a pair of AA cells. If this active cycle increases to 2 per cent then the lifetime will be cut to seven years.

However, it is important to consider how the duty cycle operates. If the aim is to improve responsiveness to events by waking the MCU core twice a second, the wakeup time component will double, reducing the system’s battery autonomy by at least six months. Cutting the wakeup time to 2µs can improve the lifetime, assuming the system wakes up twice a second, by more than a year.

Clearly, it is important to maintain a low duty cycle with a low wakeup time overhead. However, it is not always possible to predict when sensors will register an important event. Take, for example, the capacitive sensing, which is a technology now widespread across different industries.

High-performance capacitive sensors are capable of high-resolution measurements of proximity, position or displacement, humidity, fluid level and acceleration of any conductive target.

Since the introduction of the Apple iPhone, consumer device makers have recognized the advantages of incorporating capacitive touch into their products to provide more responsive and intuitive user interfaces. These sensors are generally lower-cost devices and call for a degree of processing on the MCU that can be difficult to realize where ultra-low power consumption is essential.

Capacitance describes how the space between two conductors affects an electric field between them. If two metal plates are placed with a gap between them and a voltage is applied to one of the plates, an electric field will exist between the plates. This electric field is the result of the difference between electric charges that are stored on the surfaces of the plates. The amount of charge determines how much current must be used to change the voltage on the plate.

When using a capacitive sensor in a user interface device, the sensing surface of the probe is the electrified plate and the user’s finger or stylus is the other plate. The driver electronics will continually change the voltage on the sensing surface.

This is called the excitation voltage. The amount of current required to change the voltage is measured by the circuit and indicates the amount of capacitance between the probe and the target. Conversely, a fixed amount of current can be pumped in and out of the probe and the resulting voltage change can be measured.

In a typical implementation, the sensor circuit includes a free-running RC oscillator. This generates a changing excitation voltage at a nominally constant frequency. When the user’s finger approaches the sensor, the overall frequency of the circuit will change because the capacitance within the sensor element increases. The MCU detects this change in frequency using a counter – if the counter value after a fixed period of time drops significantly from the nominal value the algorithm will register that as a touch event.

The measurement algorithm therefore demands two main components: a timer and a counter. The timer is first programmed by the MCU to count down from a fixed value. When the timer reaches zero, it generates an interrupt to the MCU. During this time, the MCU counter increments on every positive swing of the oscillator. When the MCU receives the timer-at-zero interrupt, it can simply look at the counter value to determine whether a touch event has occurred.

The problem with this implementation is that the processor core needs to be active during the sensor reading process in order to respond to the interrupts and manage the counter. During this time, the MCU may have little other work to do so may simply run in an idle loop while it is awake. One way to reduce power consumption is to only wake up periodically in order to sample the touchpad.

However, in a user-interface application, the sensing subsystem (Figure 2, below ) has no idea when the next contact will be made by the user. Although the host microcontroller could sleep periodically, longer sleep periods will negatively affect responsiveness. In turn, this will make the system harder to use as some touches may not be registered correctly until the system has fully woken up and put itself into a state that allows it to take accurate measurements.

Figure 2: As most events occur asynchronously, embedded systems should be able to react only when thresholds are reached and without the need to waste energy by periodically polling sensors.

It would be more energy efficient to perform these operations in hardware and only wake the MCU once a touch event has been registered. This is because dedicated hardware does not incur a large amount of overhead. A processor spends most of its energy supplying instructions and data to the execution units rather than performing the computations themselves.

Researchers working on the Stanford University ELM low-power processor project concluded that instruction supply alone was responsible for 42 per cent of total processor power consumption. You also have to take into account the energy demand of moving variable contents from data memory to registers and on into the processing data path and back out again. This data movement, which generally involves higher-capacitance – and therefore higher energy – bus connections, is not needed in hardware implementations.

In the case of a capacitive-sensing subsystem, it is possible to build a circuit that periodically excites the oscillator, sets a timer and then counts the number of pulses before the timer expires. At the end of the process, if the counter value is below a set minimum, it can raise an interrupt that wakes the MCU.

In this implementation, there is no need for the MCU to wake up periodically, unless there are other management functions to handle. The MCU will only be active when it has work to do, which reduces power consumption to the minimum level possible based on user activity.

A similar problem with sensor predictability arises with inductive sensing. These are electronic proximity sensors, which are able to detect the presence of a conductive target. Some common applications of inductive sensors include metal detectors, traffic lights, car washes and various automated industrial applications. Because there is no need for physical contact, inductive sensors are particularly used in harsh environmental conditions where dirt is prevalent and which may obscure optical or infrared proximity sensors.

High-performance inductive sensors, also known as eddy-current sensors, can do high-resolution measurements of the position and/or change of position of any conductive target. Lower-cost inductive sensors are used as proximity switches giving a simple on-off output indicating whether a conductive target is present or not. It is this latter group that causes more problems for power consumption when it comes to algorithm implementation on an MCU.

Inductive proximity sensors detect magnetic loss due to induced current generated on a conductive surface or target by an external magnetic field. When an AC current is applied to a coil, it generates an AC magnetic field. If a conductive target approaches the sensor it generates currents also known as eddy currents, on the sensed object due to the alternating magnetic field.

One way of producing oscillation on an inductance is using what is called a tank circuit, which consists of an inductive coil and a capacitor – broadly similar to the RC circuit used in capacitive sensing but with the addition of the inductive coil.

The capacitor stores energy in the form of an electric field while the coil stores energy in the form of a magnetic field. When the switch is in its first position, the capacitor is charged up to the DC supply voltage. When the capacitor is fully charged the switch changes to its second position, placing the capacitor in parallel with the inductor coil and starts to discharge through the coil.

The voltage across the capacitor starts falling as the current through the coil begins to rise. This rising current creates a magnetic field around the coil. When the capacitor is fully discharged the energy previously stored in the capacitor is now stored in the inductive coil.

As there is no external voltage in the circuit to maintain a current within the coil, current flows back to the capacitor, which is then charged with the opposite polarity of its original charge. After that the whole cycle is repeated resulting in a periodic energy transfer between the two circuit elements. The polarity of the voltage changes as the energy is passed between the inductor and capacitor producing an AC voltage and current waveform.

Every time energy is transferred between the two circuit elements losses occur which will decay the oscillations. This is due to the resistive circuit components, which will dissipate energy over time. The amplitude of the oscillation decreases at each half cycle of oscillation until the circuit loses all power.

This damping process happens more quickly, however, if a metallic object is near the coil. By detecting this change in decay, MCU algorithm can determine whether an object is within range of the sensor. This is normally performed by reading the change in voltage at regular intervals and comparing it to a reference voltage. If the input voltage falls below this reference, the MCU can trigger a proximity event.

As is the case for capacitive sensing, a software implementation requires that the MCU be awake to generate the excitation signal and process the analog comparator inputs. In the case of a flow metering for water or gas utilities, it can be hard to determine how often the MCU needs to wake up to be sure of registering all turns of the impeller. The supply may not be used for long periods, which will mean the MCU is waking to process no useful input.

Moving the sensing circuitry into hardware can greatly reduce the energy consumption of the system (Figure 3, below ). However, the hardware components needed to perform inductive sensing are subtly different to those needed for capacitive sensing.

Figure 3: The MCU’s LESENSE hardware block monitors the capacitive sensor and not until the counter is below the comparator trigger level does the CPU wake up. As a result CPU can spend more time in deep sleep mode.

Many of the same features are present, such as the analog comparator to monitor the sensor voltage output and timers and counters to define a measurement period and proximity detection. But the inductive sensor requires an additional DAC to provide a voltage level that the sensor can oscillate around and requires that the individual components be wired in a different way. If an MCU needs to be designed to support both forms of sensor, it will increase system cost.

The commonality between the two types of sensor interface can be exploited by careful design of a hardware subsystem: the key is recognizing that the primary changes lie in how the individual hardware components such as analog comparators, DACs, counters and timers are connected to each other and the way in which MCU sensing algorithms are composed.

The algorithms are primarily state based and move between states based on certain properties being true: such as the count value being less than a certain value after timer expiry or the analog comparator input being below a certain threshold before the timer expires.

These conditions can be monitored and controlled by a state machine, which, if made programmable, can be configured to handle a wide range of sensor-processing functions without waking the processor core. This was the approach that was taken in implementing a proprietary peripheral block developed by Energy Micro engineers (Figure 4, below ).

Figure 4: Very important for energy efficient operation are the new autonomous MCU functions blocks. The LESENSE low energy sensor interface can be configured to support monitoring of virtually any type of analog sensor without the need for CPU intervention. (To view larger image, click here)

A problem with many programmable state machines is that they can only act on and trigger a fixed set of outputs when they move from state to state. In this specialized peripheral block, states and the conditions used to select them are programmed through descriptors that can be chained together to form relatively complex operations where needed, or restricted to simple outputs if that is all that is required. In this way, it is possible to build quite complex logic before intervention need be sought from the processor core.

By adding a configurable decoder to the peripheral, it becomes possible to extend the reach of the state machine to process inputs from multiple sensors For example, quadrature decoding is common in flow-rate metering and other rotational sensing applications that employ inductive techniques.

With quadrature decoding, the sensors repeatedly pass through a set of states that correspond to the position of the sensors. The decoder makes it possible to choose a set of sensors in turn for analysis without involving the processor core. As a result, the MCU only needs to be woken up once a positive reading has been taken by one of the quadrature positions and a recording taken.

By looking at the combination of hardware and software that can be implemented in an MCU-based system as a whole – and by moving functions between them – it is possible to ensure that the full flexibility of software is only called upon when necessary. By calling upon software to process sensor inputs when there are inputs to process, overall energy consumption is kept to the bare minimum.

Rasmus Christian Larsen heads Energy Micro's technical support team and is responsible for training customers and sales force. As one of the designers of Energy Micro’s first microcontroller series, the EFM32 Gecko, Rasmus has in-depth knowledge of the complete EFM32 product family. He has previously worked as a digital design engineer for Atmel AVR and has a Masters degree in electronics from The Norwegian University of Science and Technology (NTNU) in Trondheim, Norway.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.