EFM32 Low Energy Sensor Interface -Capacitive Sense

 

Introduction

This application note covers the basics of capacitive sense and describes how to use the Low Energy Sensor Interface (LESENSE) to scan a number of capacitive sensors while remaining in EM2, achieving current consumption around 1.5µA.
Operation through several millimeters of plastic, glass or similar non-conductive overlay is also possible.

The software example simplifies LESENSE configuration for capacitive touch while operating with minimal energy consumption. It works on the EFM32 Tiny Gecko Starter Kit and the EFM32 Giant Gecko Starter Kit. This application note focuses on how to implement capacitive touch with the EFM32 microcontroller. For hardware design of printed circuit boards for capacitive touch, please refer to the capacitive touch hardware design application note (AN0040).

1 Introduction

1.1 Capacitive sensing

Capacitive sensing is a technology now widespread across different industries. High performance capacitive sensors are capable of high resolution measurements of proximity, position, humidity, fluid levels or acceleration of a conductive target. Lower cost capacitive touch sensors are less advanced and mostly used for human-device interface by measuring the capacitance change when a user's finger is near by. These kind of sensors are increasingly common in mobile devices of all sorts.

This application note will focus on the second type of sensors used to interface with users in a variety of applications. They can be implemented at very low cost and bring many advantages over mechanical switches, such as having no moving parts and less degradation over time and with usage and environmental changes. The EFM32 capacitive touch feature is primarily made for implementing capacitive touch buttons and sliders with very low energy consumption, but it can also be adapted to other capacitive sensing applications.

EFM32's with the Low Energy Sensor Interface can use this peripheral to scan several touch pads and only wake the cpu when a touch is detected. To get the best performance possible, it helps to understand what affects performance and which parameters can be tuned to increase performance and decrease current consumption. Although understanding the possibilities and limitations of LESENSE really helps when configuring a custom capacitive touch application, the software example included should make it easy to implement capacitive touch with good performance, quickly.

 

1.2 LESENSE

The Low Energy Sensor Interface (LESENSE) is a peripheral state machine which utilizes other onchip standard peripherals to perform sequenced measurement of a configurable set of analog sensors. LESENSE uses the analog comparators (ACMP) for measurement of sensor signals. Figure 1.1 (p. 3) gives an overview of the LESENSE peripheral and how it is connected to the analog comparators.

With LESENSE, almost every imaginable sensor interface tasks which uses analog comparators, DACs and counters can be automated and handled while the EFM32 is in EM2 (deep sleep mode). A wake up to EM0 (run mode) is only needed when sensor readings change and a trigger threshold is reached or when some higher level calibration is needed.

image

Figure 1.1. LESENSE overview

LESENSE supports multiple sensor types: inductive (LC), capacitive and general analog sensors. This application note focuses on the configuration of LESENSE and the analog comparators to scan capacitive touch sensors and how the different settings affects the performance and power consumption.

 

2 Capacitive Touch Sensing

image

Figure 2.1. Capacitive Sense Overview

2.1 Theory

The working principle of a capacitive touch (or proximity) sensor is to measure the change in capacitance of a given, and otherwise constant, capacitor when approached or touched by a larger body such as a human finger or hand. The capacitive touch pad can be implemented with different technologies, ranging from a trace on a printed circuit board to various conductive coated surfaces like glass. The printed circuit board approach can of course be used with an overlay, typically made of plastic or glass.

If the 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. Capacitance refers to the "capacity" of the two plates to "hold" this charge, i.e. a large capacitance is able to hold more charge than a small capacitance. The amount of existing charge determines how much current must be used to change the voltage on the plate.

When implementing a capacitive touch sensor there are a few different possible configurations which can be categorised in two different types, self- and mutual-capacitance. The difference is what the other side of the measured capacitance is. It can either be another electrode with different potential than ground, which is the mutual-capacitance type of setup. Or it can be ground, which is the self-capacitance type of setup. The EFM32 is designed for self-capacitance measurements where the absolute capacitance to ground is the measured entity.

 

2.2 Capacitive sense for the EFM32

The analog comparators in the EFM32 include specialized hardware for capacitive sensing of capacitive pads. The capacitance is measured by including the pad as a capacitance to ground in a free-running RC oscillator (see Figure 2.2 (p. 5) ).

By keeping the resistor, drive voltage and reaction speed of the analog comparator constant, the frequency produced will ideally only be dependent on the pad to ground capacitance. Because the user's finger represents both a change in the dielectric material between the plates (pad and ground) and a parallel capacitor to (virtual) ground, it will be seen as a change in the pad capacitance upon touch, see Figure 2.1 (p. 4) .

The frequency produced will thereby decrease when the button is touched, compared to when it is not touched. This frequency change can be measured. LESENSE does this by counting analog comparator pulses within a fixed time window. A change in count value is used as an indication of a button being touched or not.

image

Figure 2.2. Capacitive Sense in the EFM32

The analog comparator contains a complete feedback loop with an adjustable resistor through which the capacitive pad is charged and discharged. The output of the analog comparator drives the switches that select the reference for the negative input of the comparator. This feedback will in turn cause the capacitor to charge or discharge as depicted in Figure 2.3 (p. 6) . The voltage will oscillate between VDD/4 (lower voltage threshold) and VDD_SCALED (upper voltage threshold).

image

Figure 2.3. Capacitor Charge and Discharge

When the output of the ACMP is high VDD/4 is selected as reference, and due to the inverter the capacitor starts to discharge. When the capacitor voltage drops below VDD/4 the ACMP output toggles. VDD_SCALED is selected as reference and the capacitor starts charging. When the capacitor voltage again reaches

VDD_SCALED the ACMP output toggles and the cycle repeats. The closer VDD_SCALED and VDD/4 are the shorter the oscillation period will be. The VDD_SCALED reference can be adjusted using the VDDLEVEL bitfield in ACMPn_INPUTSEL register. The resulting voltage is given by Equation 2.1 (p. 6)

VDD Scaled

                                          VDD_SCALED = VDD×VDDLEVEL/63                                                             (2.1)

The frequency of the oscillation is mainly determined by VDD_SCALED, resistor and capacitance, but also the delay through the analog comparator affects the frequency. This makes calculating the exact frequency difficult. Fortunately it is only the change in frequency that is important when detecting a touch.

The frequency of the oscillation is mainly determined by VDD_SCALED, resistor and capacitance, but also the delay through the analog comparator affects the frequency. This makes calculating the exact frequency difficult. Fortunately it is only the change in frequency that is important when detecting a touch.

 

2.3 External Disturbances

Touch detection is based on detecting a difference from a "normal" capacitance value. Because of this it is necessary to keep track of what the untouched capacitance value really is. The problem is that this value will change with the environment. Changes in humidity for example will change the base capacitance.

Since the measurement itself is a frequency count during a fixed time window, it is not only the button capacitance that affects the untouched reading of a button, jitter in measurement-period also affects the measurement. For example when the supply voltage, VDD changes, the frequency will also change because of a change in pull-level for the RC-oscillator. Another effect that will cause noise in the readout is changes in the sample time window. This can for example be caused by low accuracy oscillator or changes in temperature.

Because a touch event is assumed to be rather quick in nature, slow changes in capacitance and count values are generally easy to filter out by low pass filtering or taking the median value over time. Fast changing disturbances are more difficult to filter out since a fast change in capacitance could either be a touching finger or just noise.

As a general rule, slow changes like changes in battery voltage when the battery is discharged, changes in humidity or oscillator frequency changes caused by temperature can easily be filtered out. Disturbances that can look like a finger touch on the other hand needs to be minimized, this means that noise on VDD, oscillator jitter and radiated noise from other signals on the PCB should be minimized.

 

2.4 Signal to Noise Ratio

The change in capacitance when a finger is placed near the sensor element is generally very small. This means that the noise level in the count values needs to be even smaller to be able to reliably detect touches. As a rule of thumb, the signal to noise ratio should be above 5. The "signal" refers to the difference between the average count for touch and no touch. The ratio between this difference and the noise-jitter for an untouched button is then the signal to noise ratio. See Figure 2.4 (p. 7) for an example of signal to noise ratio.

NOTE:  As a rule of thumb, the signal to noise ratio should be above 5 for good performance.

When developing a capacitive touch application one should check that the signal to noise ratio criterion is fulfilled for the actual PCB with the final overlay (same material and thickness that will be used). For evaluating the signal level the register view can be used in debug mode, or the actual values can be sent over a serial connection to a computer for analysis.

image

Figure 2.4. Signal to Noise Ratio

3 LESENSE for Capacitive Touch

3.1 Capacitive Touch Sequence

For capacitive touch there is no need for many of the advanced features of LESENSE like excitation phase, measure delay or start delay configurations (see the EFM32 reference manual). Only the sample delay phase is necessary, the following list indicates the flow of a measurement for one capacitive touch button. See Figure 3.1 (p. 8) for a typical capacitive touch measurement sequence.

• The analog comparators are switched on in capacitive touch mode. This starts the RC-oscillations on the selected channel.

• The analog comparator output is gated to the LESENSE counter which starts counting. The sample delay counter is started at the same time.

• When the sample delay counter reaches the configured sample delay, the counted value is stored and compared to a threshold value.

• If the count compare is true, an interrupt request is sent. Either way, LESENSE turns off the analog comparators again and sleeps until the next scan cycle. Notice that the CPU itself is never woken up during a measurement cycle.

If LESENSE is configured to scan more than one channel the sequence will repeat itself for each channel in rapid succession before going to sleep. The scan period and sample delay should be configured so there is time to complete the measurement for all channels before a new scan is started. If the desired scan frequency is 100 Hz for example, each scan should not take more than 10 ms, which again must be divided between all the channels that is enabled.

image

Figure 3.1. LESENSE Sequence for Capacitive Touch

3.2 LESENSE Configuration

To get the lowest noise level and thereby highest signal to noise ratio, it is important to configure both the analog comparators and LESENSE correctly. The following section lists the different settings, how they affect performance and what they should be set to or how to tune them. There are other settings that are not directly connected to capacitive touch, the configuration of those can be found in the software example.

 

3.2.1 Fixed Settings

These are settings that can be set to a fixed value which should be optimal for most capacitive touch applications.

Table 3.1. Fixed settings for best capacitive touch performance

image

3.2.2 Adjustable Settings

These settings can and should be tuned for different capacitive touch applications. A good starting point for a general capacitive touch application is given.

Table 3.2. Adjustable settings for best capacitive touch performance

image

3.3 Performance Trade-off

The performance trade-off for a capacitive touch application is typically between current consumption and sensitivity. The sensitivity determines how thick the overlay can be. These two parameters are inversely correlated, for thick overlays more sensitivity is needed and the current consumption goes up. For thin overlays, or even touch buttons directly on the PCB, the current consumption can be brought down because a shorter measurement window is sufficient to determine if a touch has occurred.

For LESENSE the sensitivity is increased by increasing the sample delay. This increases the count value and this in turn gives higher resolution in the measurements. While increasing the sample delay, the time the analog comparators are kept running also increases. This increases the current consumption.

The approach to get the correct trade off between low power and good performance is to start out with a large sample delay and first configure the sensitivity by setting the threshold value. The count threshold should be set to a value which gives a touch event at the moment a finger is touching the overlay. Then the sample delay can be decreased until the count value only changes by a few LSBs when a touch occurs.

 

3.3.1 Current Consumption

The software example included, configured for scanning 4 pads at 5 Hz per pad through 1.8 - 2.0mm of plastic, consumes around 3.4µA. Scanning just 1 pad with the same settings reduces the consumption to approximately 2.1µA. The current consumption scales linearly with scan-frequency, sample delay and the number of pads scanned.

If the PCB layout is made more ideal than the starter kit, with larger pads (1.5 - 2.0cm), a thicker overlay can be implemented. With the same settings as above, the total consumption with 6mm overlay for 4 buttons (2.0cm) at 5 Hz per channel is 3.1µA. Some examples of achievable current consumption for different configurations are listed in Table 3.3 (p. 11) .

image

Table 3.3. Current consumption for different software and hardware configurations

3.3 Performance Trade-off

The performance trade-off for a capacitive touch application is typically between current consumption and sensitivity. The sensitivity determines how thick the overlay can be. These two parameters are inversely correlated, for thick overlays more sensitivity is needed and the current consumption goes up. For thin overlays, or even touch buttons directly on the PCB, the current consumption can be brought down because a shorter measurement window is sufficient to determine if a touch has occurred.

For LESENSE the sensitivity is increased by increasing the sample delay. This increases the count value and this in turn gives higher resolution in the measurements. While increasing the sample delay, the time the analog comparators are kept running also increases. This increases the current consumption.

The approach to get the correct trade off between low power and good performance is to start out with a large sample delay and first configure the sensitivity by setting the threshold value. The count threshold should be set to a value which gives a touch event at the moment a finger is touching the overlay. Then the sample delay can be decreased until the count value only changes by a few LSBs when a touch occurs.

 

4 Software Example

This application note comes with a software example for the EFM32 Tiny Gecko Starter Kit (EFM32TGSTK3300) and the EFM32 Giant Gecko Starter Kit (EFM32GG-STK3700). The example uses the capacitive touch slider on the lower right corner of the starter kit. By touching one of the slider elements the user LED is lit during the touch event and turns off again upon no touch.

 

4.1 Working Principle

The software example simplifies the configuration of LESENSE for capacitive touch. LESENSE is configured to scan the enabled buttons with a certain scan-frequency and wake up if a button has a count value below a certain threshold. The touch threshold for each button is specified in percent of the average count for an untouched button as described in Table 3.2 (p. 10) .

It uses an RTC interrupt to run a calibration routine. The interval between calibrations can be adjusted for different usage scenarios. The calibration routine tries to find the count values for the untouched buttons. It then reconfigures the wake-up threshold values for LESENSE based on the percent-values configured at initialization.

 

4.2 Calibration Routine

The calibration routine is executed at fixed intervals. It works by storing count values for each pad from the N previous calibration runs, it then takes the maximum count value seen in the previous N calibration events as the new untouched level.

Since a touch event is always characterized by a decrease in the count value, the system is allowed to quickly calibrate the threshold count upwards, but it should take longer to change the threshold down. With this approach it only takes one calibration event to change the threshold upwards, but it takes N calibration events to change the threshold down. Rising voltage and falling temperature will both contribute to an increase in the nominal count values, this will be corrected after one calibration event. Falling voltage and rising temperature will result in decreasing nominal count values, this will be corrected after N calibration events.

The calibration routine should be run frequently enough to catch small changes in the untouched count level before it changes enough to trigger a false touch. To save power it should not be run too frequently either.

The idea is that during the N last calibration events, there should at least be one calibration event that is executed when the user does not touch any buttons. The count value from that event will be the maximum count value encountered. In other words, the calibration count N multiplied by the interval between calibrations should be higher than the longest expected touch event. If a longer touch event occurs, it will only take one more calibration event to get back to the correct threshold value.

In the included software example, both the calibration frequency and N can be adjusted. The default value is 5 seconds between each calibration and N = 10. This will contribute less than 100nA to the average current consumption.

 

4.3 Initialization

To start the capacitive touch operation, an array containing the trigger threshold in percent for each of the LESENSE channels is declared and initialized. This is used by the calibration routine to configure the correct thresholds later on.

The calibration routine interval can also be configured depending on how fast supply voltage and other environmental factors are expected to change. Once every 10 seconds with N = 5 to 10 are reasonable values, supply voltage or temperature does not change significantly during a couple of minutes. If the application is moved between different environments, and thereby must withstand quicker changes in environment, the calibration routine can be run more frequently, every second for example.

At start up the calibration routine is executed N times in fast succession, during this period the buttons should not be touched for the calibration to work correctly. If a pad is touched during this initialization it will only take one calibration event after the touch event is over to correct the threshold value.

 

4.4 Touch Event

If a count value below the threshold for any channel is observed, LESENSE will trigger an interrupt. The interrupt routine stores and clears the interrupt flag, then it finds the channel that triggered the interrupt. The interrupt routine then reconfigures the scan frequency and checks the particular channel again a number of times (#define VALIDATE_CNT). This ensures that an actual touch event has occurred.

If all the validation measurements are positive, the evaluation criterion on that particular channel is inverted, this will result in a new interrupt on that particular channel when the touch event is over. By inverting the touch criterion in LESENSE, a minimum amount of cpu time is spent keeping track of touched and untouched buttons, LESENSE keeps track on its own.

Touch hysteresis is also implemented by changing the threshold value when the touch criterion is inverted. Touch hysteresis prevents the system from oscillating between touch and no touch events.

 

4.5 Further Improvements

The software example implements some of the basics for a robust touch application. Depending on the application, improvements can still be made. Some ideas are mentioned in the following section.

By making use of the LESENSE decoder, LESENSE can issue an interrupt for a touch only after a certain number of sequential count values are below the touch threshold. This can reduce the energy consumption further.

Implementing use of DMA to transfer count values to memory and do more advanced filtering and processing can also be beneficial. This can be used to differentiate between a water splash or similar disturbance and actual touch events. The collected samples can also be used to continually adjust the compromise between energy consumption and sensitivity.

A reference pin can be implemented with an unused analog comparator pin. The reference pin should be left unconnected, a users finger should not be able to affect it. With a reference pin, environmental changes like temperature and supply voltage can be tracked more accurately and compensated by adjusting the threshold for the other capacitive touch pins. With this approach, the required assumption of untouched buttons in at least one of the N calibration events could be relaxed.

No comments:

Post a Comment