MSP430 Low Cost PinOsc Capacitive Touch Overview

From Texas Instruments Wiki
Jump to: navigation, search

Introduction

When considering the appropriate capacitive touch solution, cost vs. performance often comes to mind. However, now add flexibility and the total solution becomes even more complicated. Conventional wisdom might say utilize a fixed function capacitive touch solution. The problem is that these solutions are often lacking in flexibility or are too expensive.

The MSP430 Value Series addresses all of these needs with a variety of low cost MCU options. Specifically utilized in this application report is the MSP430G2553 featuring PinOsc GPIOs designed for capacitive touch sensing along with integrated 16-bit Timer0_A3 and Timer1_A3 modules for timing control of measurement process and scan interval to permit low-power and low-cost flexible capacitive touch solutions.

In the next sections, the system components will be introduced and discussed. This will include the Sensor Element, PinOsc GPIO usage, Timer0_A3 for measurement operation, and Timer1_A3 for scanning interval. This will be followed up by the Sensor Measurement Software discussion that will focus on Sensor Element Measurement, Sensor Processing, and Sensor Analysis.  Included in the Sensor Measurement Software discussion, we will also highlight the Filtering techniques and Baseline adjustment operation that is used in the Sensor Processing stage.  As a final piece, Sensor Element calibration will also be addressed.

As follow-up to this document, also refer to the MSP430 Low Cost PinOsc Capacitive Touch Keypad application example.

System Overview

Within the System Overview section, the system sub-components will be addressed in detail. Figure 1 shows one system example that implements multiple MSP430 PinOsc Capacitive Touch Sensors.  Figure 2 shows the implementation of one sensor element for PinOsc capacitive touch measurement.

PinOsc System Block Sensor Diagram.jpg

Figure 1. Example PinOsc Capacitive Touch System

PinOsc Block Diagram.jpg

Figure 2. Single Sensor Element PinOsc

Throughout this section, details will be discussed relative to the MSP430G2553. Other MSP430 devices also have the PinOsc GPIO structure, so be certain to reference the appropriate device datasheet for exact use case details.


PinOsc Sensor Elements

The first user interface component of the system is the sensor. When using the PinOsc feature of the MSP430 family, you will notice several important features. No external discrete components are required. As shown in Figure 1, each sensor element is independently connected to any PinOsc GPIO pin (on the MSP430G2553, all 24 GPIOs have the PinOsc capability). There is a high degree of flexibility in the sensor element shape and size along with the sensor configuration.

Keep in mind here that the definition of a sensor is the functional implementation of the desired capacitive touch sensing and can include one or more individual elements. A sensor could be a single element button or a multiple element slider or wheel. A sensor could also be single element used for proximity detection or an array structure for a keypad or even a trackpad.  The following are a few examples of Sensor types featuring the individual Elements used to create the Sensor.

PinOsc Button Element.jpg  PinOsc Slider Elements.jpg PinOsc Array Elements.jpg
Figure 3. Sensor Examples

Even though the sensor structure might appear different, the MSP430 GPIO interface to each sensor element remains the same.

 

PinOsc GPIO (Frequency Generation)

Connected to an external sensor element, the PinOsc (Pin Oscillator) GPIO is a very simple structure on certain MSP430 devices that enables low cost capacitive touch sensing without the need for external components. When the PinOsc structure is enabled in the GPIO, the internal structure combined with an external sensor capacitance produces an internal oscillator. This oscillation is directly related to the capacitance of the external sensor element. It is this frequency that will be measured.

PinOsc Block Diagram.jpg  

Figure 4. PinOsc GPIO Block


 

Timer0_A3 (PinOsc Measurement)

To perform the sensor measurement, the Timer0_A3 shown in Figure 2 is utilized. TA0CLK is connected internally to the PinOsc and provides the clock source to the timer. The TA0CLK PinOsc in conjunction with a low frequency source (internal VLO or external LFXT1) connected to the TA0CCR0 capture input allows for the PinOsc frequency measurement.

In this example, the MSP430G2553 device is used, but it is important to refer to the appropriate device datasheet as internal connections and timer modules can differ. 

PinOsc Timer0 A3 Block Diagram.jpg

Figure 5. PinOsc Timer0_A3 Block

 

Timer1_A3 (Scanning Interval)

For the scanning interval period, a second timer resource is used on the MSP430G2553. While it is possible to also re-use the same Timer0_A3 module, the Timer1_A3 shown in Figure 1 maintained separately enables the easiest control for the periodic sensor scanning interval. This interval helps control the sensing detection rate and power consumption of the system.

PinOsc Timer1 A3 Block Diagram.jpg

Figure 6. PinOsc Timer_A3 Block

 

Sensor Measurement Software Implementation

Regardless of the sensor type, there are 3 common stages of the capacitive sensing process. The first is the sensor measurement itself, the second is the measurement processing, and the third is the data analysis.

Figure 2. Sensor Measurement Flow Diagram 

Figure 7. Sensor Measurement Flow Diagram

Measure

Measuring the frequency of the PinOsc involves individually scanning the Sensor element(s) to generate a Raw Count for each element. This Raw Count is then stored for each element of the sensor. This feature is identical for every sensor type.

Generation of this Raw Count is implemented using the sensor element PinOsc input as the clock source to the Timer0_A3 (TA0CTL.TASSEL=3=PinOsc) and counting over a fixed period (accumulation cycle) controlled by a capture input to the Timer0_A3 (TA0CCTL0.CCIS=1=ACLK). The Raw Count is the count relation of the PinOsc frequency to the Accumulation Cycle (controlled by ACLK).

Figure 3. Measure Flow Diagram 

Figure 8. Measure Flow Diagram

Process Measurement

After the measurement stage is performed, the resulting sensor element’s Raw Data is analyzed.

Several sub-steps are described in more detail in sections below.

Raw Data is compared relative to each sensor element’s Baseline value (base_cnt) to generate a Delta Count value (delta_cnt).  After generating the delta_cnt value for each sensor element, a filtering stage is applied (optional, but recommended). 

Once filtered, the sensor element data is compared to the sensor element's threshold_sense level.  This determines if a sensor is active or inactive.  If inactive, Baseline adjustment can occur. As the capacitance changes on each element, so does the resulting PinOsc frequency. It is important to remember that temperature and voltage will also impact the PinOsc frequency, so adjusting the Baseline value during operation is always necessary (see Baseline Setting and Adjustment below).

After all sensor elements are processed, the resulting sensor_state is returned.
Figure 4. Process Flow Diagram
Figure 9. Process Flow Diagram

Analyze Sensor

Sensor Data Analysis can take on numerous meanings. This could be a simple button decode, a position on a slider or wheel, a certain gesture type, or something else. The following is simply analysis of the individual sensor element states defined by the input parameter sensor_press.  The sensor_press value is taken from the Process function sensor_state decoded value.
Figure 5. Analyze Flow Diagram
Figure 10. Analyze Flow Diagram

Filtering Techniques

Before continuing onto managing the Baseline, we might want to look at our Raw acquistion data.  There are many applications that experience noise or other disturbances.  These influences can impact the reliability of the data to be interpreted.  However, in many cases, some simple software filtering can assist the measurement interpretation with little impact to the overall system performance (power and speed).

Normally this step takes place in the Process Measurement stage.

Three simple methods are an IIR Filter, Summing Filter, and Cumulative Moving Average Filter (Nominalized Summing Filter).  If we choose to take advantage of the amplified signal, then we can neglect the CMA Filter.

There are benefits and drawbacks to each method, but implementing either can make event detection more robust and immune to interferences.

Filter Method

Positives

Negatives

IIR Low Pass Filter 

 IIR LPF Block Diagram.jpg

Updates are only dependent only on current measurement states

Gain depends on Filter Weighting

Moderate to Slow Signal Response


Summing Filter

SUM_valuen = valuen + valuen-1 + valuen-2 + valuen-3

Fast to Moderate Signal Response

Prior measurement states must be stored.

Gain depends on number (n) of summed measurement values.

Cumulative Moving Average Filter (Nominalized Summing Filter)

CMA_valuen = (SUM_valuen) / n

Same as Summing Filter

Same as Summing Filter


 


PinOsc Filtering IIR Summing Plots.jpg 

Figure 11. Analyze Flow Diagram

As can be observed, the Summing Filter (C2SUM) responds faster than the IIR Filter (C2IIR).  However, for this case, the Summing Filter requires 4x the memory requirement for the delta_cnt_value (16-bit integer value).

For a sensor with many elements, the Summing Filter memory requirements can be a limiting factor for low cost solutions. 

Keeping this in mind and depending on the IIR Weighting Factor Gain requirements, the response vs. memory trade-off might be considered.

Baseline Setting and Adjustment

In continuing with components of the Process stage, the "baseline" needs to be discussed.  A baseline is simply the untouched reference point of the system from which touch is determined. Therefore, the baseline (base_cnt) value for each sensor element must be initialized and maintained.

Maintaining the baseline is extremely important to remember due to the fact that the system is impacted by external forces (temperature, moisture, humidity) as well as system parameters (voltage).  These factors can cause the untouched reference baseline results to drift. If this drift is not taken into account, then errors can occur with unpredicted effects. Therefore, as part of the Process stage, adjustment of the baseline (base_cnt) also takes place.

For Capacitive Touch sensing, there are three key error conditions that are potentially impacted by the baseline adjustment.

1) False Positives - When a sensor element is interpreted as active when in reality it is not active.

False Positives can occur for two reasons.  The first is that system noise has resulted in one or more erroneous measurement(s) corrupting the data content.  The second is that the baseline has become erroneously adjusted into a state that measurement data is interpreted in an invalid state. 

These two reasons are mitigated with use of the PinOsc (built in hardware filtering due to the measurement technique) and appropriate baseline handling.

2) Locked Positives -  When a sensor element is interpreted as active remains locked in the active state due to baleline corruption. 

Locked Positives are relates to the second reason of the False Positives.  When the baseline is erroneously modified, meaurement readings will always fall into a Positive detection range.  This is due to poor handling of the baseline adjustment and is most often associated with the desire to perform a very fast upward movement in the baseline due to a large negative value detected.  If baseline dithering is applied, large negatives are mst often never experienced.

3) Missed Positives - When a sensor element in not interpreted as active when in reality it is active.

Missed Positives (sometimes called "Finger Creep") occurs when the baseline adjustment meant to compensate for envirnomental conditions is applied to the presence of a human finger.  If a very slow approach occurs to the sensor element, then this can be mistaken as a very slow change to the sensor elements capacitance.  This causes the baseline adjustment to occur and tracks the movement of the finger closer to the sensor element.  When the finger is in contact to the sensor element, the baseline is at the same level as the measurement level, and the detection is missed.  Keep in mind that Missed Positives typically involve two parameters (sensor element scanning rate and baseline adjustment technique).  Using some simple techniques, Missed Positives can be easily avoided.

Please see the MSP430 Low Cost PinOsc capacitive Touch Keypad Wiki for code application examples.

Sensor Element Thresholds

Before concluding the MSP430 Low Cost PinOsc Capacitive Touch Overview, one last point to address is setting of the sensor element thresholds. When performing data interpretation, it is important to keep in mind that for a given sensor element, the delta_cnt_value (base_cnt - meas_cnt ... for the PinOsc method) is compare to a specific threshold limit.  This begs the question "How do I determine the desired sensor element threshold limits?".

The simple answer is measure it.

The better answer is have your measurement process automated.  Below is an example tool to help measure the max delta_cnt_value for each sensor element.

  PinOsc Remote Sensor Calibration GUI.jpg

As you can see, the black bars show the relative delta_cnt_value with the actual max reading displayed.

Since this is the MAX reading, normally some level below this point should be used for setting the detection threshold limit.  In the MSP430 Low Cost PinOsc capacitive Touch Keypad example, these values are saved to a board_xxx.h include file in the CapTouchLib folder and referenced by the structure.c Element construct.  Each sensor element #define xxx_MAX_VALUE is applied to the .threshold_cal, .threshold_sense, and .maxResponse values.

In the structure.c, for each sensor element (const struct Element type) these levels are set as follows:

.threshold_cal = 0.1 * xxx_MAX_VALUE (or 10% of the xxx_MAX_VALUE level) = level to which the sensor element baseline adjustment occurs due to temperature drift.

.threshold_sense  = 0.3 * xxx_MAX_VALUE (or 30% of the xxx_MAX_VALUE level) = level above which the sensor element is detected as active.

These levels can be changed if desired.

References

1. MSP430 Capacitive Single-Touch Sensor Design Guide (SLAA379)
2. PCB-Based Capacitive Touch Sensing With MSP430 (SLAA363)
3. MSP430 Capacitive Touch BoosterPack (http://focus.ti.com/docs/toolsw/folders/print/430boost-sense1.html)