0% found this document useful (0 votes)
129 views25 pages

Slaa 363 A

slaa363

Uploaded by

Eduardo Pretel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
129 views25 pages

Slaa 363 A

slaa363

Uploaded by

Eduardo Pretel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Application Report

SLAA363A – June 2007 – Revised October 2007

PCB-Based Capacitive Touch Sensing With MSP430


Zack Albus MSP430 WW Applications

ABSTRACT

This application report discusses the design of a single-touch capacitive sensor interface
using the MSP430 microcontroller. With ultra-low power features and integrated
peripherals, integrating a single-touch user interface into MSP430 applications can be
readily accomplished. This application report provides an overview of the technology,
details about system careabouts and details for different methodologies of capacitive
touch sensing implementations using the MSP430 family. Figure 1 shows a graphical high
level representation of the system described in detail in the remainder of the document.

Capacitive keys
(built into PCB layers )

MSP430
Control/
(Measure CDELTA for each c ommunicate
sensor and determine the system activity
location of a single touch)

Figure 1. Capacitive Touch Sensor System Overview Using the MSP430

Software source files and hardware design files can be downloaded from
http://www.ti.com/lit/zip/slaa363.

All trademarks are the property of their respective owners. 1


SLAA363A – June 2007 – Revised October 2007

Contents
1 Capacitive Touch Sensing Overview ............................................................................................3
2 Sensor and Interface Construction ...............................................................................................4
2.1 PCB Sensor Specifics ...............................................................................................................4
2.2 Sensor Insulating Overlay .........................................................................................................6
3 Measuring a Capacitive Touch Sensor Using the MSP430 .........................................................8
3.1 Oscillator-Based Capacitive Measurement ...............................................................................8
3.2 Resistor-Based Capacitive Measurement ...............................................................................11
4 Software Implementation .............................................................................................................15
4.1 Tracking Sensor Base Capacitance ........................................................................................15
4.2 Implementing Button Function.................................................................................................17
4.3 Implementing Slider Function..................................................................................................17
4.4 Handling Slider Endpoints .......................................................................................................19
4.5 Sensor Multiplexing for Sliders................................................................................................20
5 Summary........................................................................................................................................22
6 References.....................................................................................................................................22
Appendix A. Flexible Evaluation and Demonstration Hardware ......................................................23
Appendix B. Simple Demonstration Hardware...................................................................................24

Figures
Figure 1. Capacitive Touch Sensor System Overview Using the MSP430 ...................................1
Figure 2. Open Capacitor Acting as a Sensor .................................................................................3
Figure 3. Plate Capacitor Basics.......................................................................................................4
Figure 4. Example Four-Sensor System for Button and Slider Function .....................................5
Figure 5. Pour Styles (Red = Top Signal Layer, Blue = Bottom Signal Layer = GND Pour) ........5
Figure 6. Theoretical and Empirical Sensor Sensitivity vs Insulator Thickness..........................7
Figure 7. Basic Capacitive-Dependent Relaxation Oscillator ........................................................8
Figure 8. Frequency Measurement Principle...................................................................................9
Figure 9. Multi-Sensor System Using Comparator_A+...................................................................9
Figure 10. Current Consumption and Measurement Time for One Sensor ..................................10
Figure 11. Basic Resistive Discharge Capacitance Measurement ................................................11
Figure 12. Measurement Methodology Using the GPIO Threshold and Timer_A ........................12
Figure 13. Multi-Sensor Charge/Discharge Configuration .............................................................13
Figure 14. Single Measurement Cycle for Improved Noise Rejection...........................................13
Figure 15. Resistive Charge/Discharge ICC and Measurement Time: Single Sensor ....................14
Figure 16. Example Algorithm for Tracking Baseline Sensor Capacitance..................................16
Figure 17. Button Press in a Four Key System ...............................................................................17
Figure 18. Fundamental and Neighboring Sensor Response ........................................................18
Figure 19. Example Slider Position Determination Methodology..................................................18
Figure 20. Representation of Count Measurement Results for Max Endpoint .............................19
Figure 21. Example Slider Endpoint Handling.................................................................................20
Figure 22. Example Sensor Multiplexing of 12 Capacitive Sensor Elements...............................21
Figure 23. Flexible 4-Button RO/RC System Block Diagram..........................................................23
Figure 24. Simple 4-Button RC System Block Diagram and Image...............................................24

Tables
Table 1. Dielectrics for Example Materials .....................................................................................6
Table 2. 64-Position Slider Key .....................................................................................................18

2 PCB-Based Capacitive Touch Sensing With MSP430


SLAA363A – June 2007 – Revised October 2007

1 Capacitive Touch Sensing Overview


The fundamental element required in the capacitive touch sensing application described is the
variable capacitor itself. This capacitor should be easy to construct as well as sensitive to human
touch in order to enable this as an alternative to mechanical buttons and switches. Such a touch
sensitive sensor element can be constructed by “opening up” a capacitor structure so that the
electric field can be interfered with by a conductive foreign object, in this case, a finger. Figure 2
shows the top and cross-sectional views of such a capacitive sensor as implemented in the
printed circuit board itself.

Figure 2. Open Capacitor Acting as a Sensor

As shown, a PCB-based capacitor is formed between the center copper pad and the ground
pour surrounding it. The electric field is allowed to leak into the area above the capacitor. The
interaction of this sensor pad and the surrounding ground pour (also the ground plane
underneath) create a baseline capacitance that can be measured. The base capacitance of such
a sensor is in the range of ~10 pF for a finger-sized sensor. When a conductor, e.g., a finger,
comes into the area above the open capacitor, the electric field is interfered with causing the
resulting capacitance to change. The coupling of the conductive finger into the capacitive sensor
increases the capacitance of the structure beyond the baseline capacitance, the capacitance of
the sensor with no touch. By continuously measuring the capacitance of the sensor(s) in the
system and comparing each result to a predetermined baseline capacitance, the system
microcontroller can determine not only on/off button functions for each sensor element but also
“amount” of press used for more complex interfaces such as positional sliders.
The sensitivity of this sensor is dependent on the gap between the surrounding ground and the
sensor plate. A gap of around 0.5 mm is recommended. In addition, PCB thickness plays into
the overall sensitivity as well: when it is very thin as in the case of a flexible PCB, this increases
the tight coupling between the sensor and the ground plate beneath it and decreases its
sensitivity. A standard FR4 PCB with 1-mm to 1.5-mm thickness is ideal.

PCB-Based Capacitive Touch Sensing With MSP430 3


SLAA363A – June 2007 – Revised October 2007

The sensor pad size of around 10-mm diameter is typically used. This size is similar to the
surface area of a human finger when pressed down. Such a sensor using the above careabouts
typically has ~5 pF to 10 pF of capacitance untouched.
The highlighted ground plane underneath the sensor aids in shielding it from potential
interference generated by other electronics in the system. It also helps to maintain a more
constant baseline capacitance needed as a reference for each measurement.
The base capacitance of such a design is affected by stray capacitances on the PCB as well as
potentially other environmental effects such as temperature and humidity. Therefore, the
detection system needs to constantly monitor and track this variation for correct comparison to
touch events.

2 Sensor and Interface Construction


The complete interface consists of the actual PCB-based capacitive sensors themselves, as well
as some type of insulator between the sensors and the user.

2.1 PCB Sensor Specifics


At a high level, the capacitive sensor dependencies can be visualized by understanding the
basics of a plate capacitor. Figure 3 represents the key elements.
y

ε 0ε r A
X

C=
A
d

d
Figure 3. Plate Capacitor Basics

First the base capacitance must be accounted for. The term “base capacitance” refers to the
measurement result of an “untouched” or uninfluenced sensor element. For simplicity, the base
capacitor can be assumed to be constructed from the sensor pad on the topside of the PCB and
the ground pour on the bottom side of the PCB. These are the top and bottom plates in Figure 3.
The PCB itself makes up the “d” in the equation. As mentioned earlier, as d gets smaller (such is
the case with flex PCBs), the baseline capacitance increases resulting in reduced sensitivity.
The permittivity of free space (ε0) and the material (εr) define the dielectric constant of the PCB
insulator and will affect the ultimate base value.
The area of the sensor, “A”, is typically limited to the size of the interacting finger. Usually this is
designed to be somewhere between a child’s small fingers and an adult’s larger fingers for a
good compromise, but is ultimately application-dependent. Keep in mind that any sensor area
that extends outside of the overlap of the finger is essentially wasted, as it does not contribute to
the changing capacitance desired.

4 PCB-Based Capacitive Touch Sensing With MSP430


SLAA363A – June 2007 – Revised October 2007

The design careabouts for the capacitive sensor are simple in theory: minimize the base
capacitance of the sensor while maximizing the potential for user interaction. The more ideal that
each of these are made results in increased capacitive change between a touched and
untouched sensor, the key to good sensitivity and robust design. Of course, these two goals
works against each other: as the area gets larger to match to the full size of the interacting finger
the base capacitance also increases, as it is proportional to A. For a given sensor construction,
the maximum change that can be created by a finger press is essentially fixed. As the base
capacitance for the same sensor increases, the percent change in measured capacitance goes
down, resulting in lower sensitivity and overall performance of the sensor interface.
One solution to help in this effort, given a fixed A for the sensor, is to manage the ground pour
underneath the sensor pad. Figure 4 shows the simple orientation of a four key sensor interface
for single-touch functions such as buttons or sliders. This four key sensor is used as an example
throughout the application report.

Figure 4. Example Four-Sensor System for Button and Slider Function

Figure 5 shows the actual PCB layout of such a sensor key pad, but with four different
approaches to implementing the ground pour.

Figure 5. Pour Styles (Red = Top Signal Layer, Blue = Bottom Signal Layer = GND Pour)

The upper left image shows only a top signal layer: four sensor pads surrounded by a top layer
ground pour; no bottom layer is implemented. The upper right section shows the same board
design; except now a bottom layer 25% hatched ground pour is implemented. The lower left
version is with a 50% pour and the lower right with a 100% filled ground pour, each below the
sensors constructed in the top layer.

PCB-Based Capacitive Touch Sensing With MSP430 5


SLAA363A – June 2007 – Revised October 2007

At least some bottom layer ground pour is recommended beneath each sensor in order to
isolate the sensor elements from noise and external variation that could affect the sensor based
capacitance. While the obvious choice might be a 100% fill as shown in the lower left
implementation providing maximum noise isolation, it also maximizes the area of the lower plate
in the capacitor constructed between the sensor and ground pour. This increases the base
capacitance through an increased area, A. To get the benefits of noise isolation as well as
minimized base capacitance, a fill in the order of 50% to 75% is typical.

2.2 Sensor Insulating Overlay


In this type of application, an insulating layer, typically plastic, overlays the sensors on the PCB
from the user. Therefore, the finger does not make physical contact with the sensor plate itself.
Maintaining an insulated separation between sensor and the user is critical in maximizing the
usefulness of the capacitive touch interface.
The plate capacitor concept from Figure 3 used to describe the base capacitance of the sensor
can also be used to visualize the interaction of the finger in changing the capacitance. In this
case, the sensor is now the bottom plate of the capacitor and the user’s finger is the top
conductive plate. The insulator between the two is at a minimum the solder mask covering the
sensors or most likely the plastic housing the given sensor system is contained within. It
becomes clear that as the area of interaction increases to the full size of the finger, an
increasing A, the change in capacitance is maximized. Also, as the d of the insulator increases,
the change in capacitance goes down in an inversely proportional relationship. A key factor that
cannot be ignored is the actual material used as the user interface insulator. The dielectric
constant of this material as well as its thickness play a very large role in dictating the sensitivity
and usability of a given capacitive touch sensor. Table 1 highlights the dielectric constants
(ε0 × εr) of some example materials, plastics generally being in the 2-3 range.

Table 1. Dielectrics for Example Materials

Material Dielectric Constant

Vacuum 1 (by definition)

Air 1.00054

Polyethylene 2.25

Paper 3.5

Pyrex glass 4.7

Rubber 7

Silicon 11.68

6 PCB-Based Capacitive Touch Sensing With MSP430


SLAA363A – June 2007 – Revised October 2007

In addition to the insulator itself, the connection between the insulator and the sensor is critical.
Given the low dielectric constant of air, any gap in the coupling of the insulating overlay and the
sensor results in a rather poor capacitive change. Assuring that the connection between the two
elements is as good as possible is important to maintaining uniform sensitivity to touch.
Adhesives are commonly used to achieve this but, in addition to being thin and very tactile, they
must also respond to environmental changes with minimum shift in thickness or adhesiveness.
Nonconductive adhesive films such as 467MP and 468MP from 3M have resilient properties for
such an application.
To illustrate the impact of insulator thickness on sensor sensitivity, Figure 6 plots the theoretical
relationship as the d of the user interface insulator increases. Plotted along the continuous curve
are three empirical data points for specific tests using the specified thickness of plastic.

Capacitance Change vs. Thickness


(Fingerpress, 8x8mm pad, 1.5mm FR4 PCB)

120%

100%

80%

60%
Test Measuremnt #1:
0.13mm thick plastic insulator

40%
Test Measuremnt #2:
0.6mm thick plastic insulator Test Measuremnt #3:
3.4mm thick plastic insulator
20%

0%
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5
Plastic Thickness (mm)

Figure 6. Theoretical and Empirical Sensor Sensitivity vs Insulator Thickness

By understanding the physical and electrical tradeoffs for both the PCB sensor and the user
interface insulator, performance expectations and feasibility of the system can be balanced to
meet the given application’s requirements. Ultimately, mechanical and material constraints drive
the limits of a given implementation.

PCB-Based Capacitive Touch Sensing With MSP430 7


SLAA363A – June 2007 – Revised October 2007

3 Measuring a Capacitive Touch Sensor Using the MSP430


Now that the sensor concepts and construction are defined, two different methods used to
measure the capacitive touch sensor can be described. Implementations and performance
results are detailed in each case along with a comparison and discussion of tradeoffs for each
method.

3.1 Oscillator-Based Capacitive Measurement


The first methodology used to measure a capacitive touch sensor described is using an
oscillator. Fundamentally, a simple relaxation oscillator can be created using the MSP430’s on-
chip comparator and the capacitive sensor as the tuning element. Any change in capacitance of
the sensor corresponds to a change in frequency which can be measured using the internal
Timer_A hardware of the MSP430. Figure 7 shows the implementation of such a system using
an MSP430 with the Comparator_A peripheral.

MSP430

RC

CSENSOR PX.Y
R -
CA
+
R TACLK
R
TAR

Figure 7. Basic Capacitive-Dependent Relaxation Oscillator

The R ladder network, when Px.y is high, creates a reference for the comparator that changes
with its output. This toggling reference is opposite in polarity to the charge or discharge of the
sensor capacitor (CSENSOR), resulting in a continuous oscillation. With equal R’s in the ladder
network providing 1/3VCC and 2/3VCC trip points, the frequency of oscillation is given by:
fOSC = 1/[1.386 × RC × CSENSOR]
By counting the oscillation periods over a fixed time duration, the frequency can be determined
and the capacitance measured. For this application report, a sensor resistor, RC, of 100k is used.
This results in approximately a 600-kHz oscillation frequency for a typical ~10-pF sensor.
Figure 8 shows this counting principle as it can be implemented in the MSP430 hardware.

8 PCB-Based Capacitive Touch Sensing With MSP430


SLAA363A – June 2007 – Revised October 2007

(SLOW)
ACLK WDT

measurement window
1st TAR 2nd TAR
Capture Capture
(FAST)

TAR

Capture
Oscillator Output Signal
(CAOUT = TACLK)
TAR

Figure 8. Frequency Measurement Principle

Figure 8 show use of the very slow ACLK signal, in this case the 12-kHz integrated VLO, to
clock the WDT to create a measurement window. With each WDT interrupt, the CPU in software
takes a snapshot of the continuously counting Timer_A register, TAR. The difference between
two of these snapshots, or captures, is the measurement result.
In reality, the actual capacitance is of no interest, only the change in capacitance between the
baseline measurement and a touched sensor. To determine this only the actual number of
counts captured during the measurement window is of any importance. By storing a base
capacitance count used for comparison of future measurements, the relative change in
capacitance can be determined.
While one sensor can be easily measured using Comparator_A as shown in Figure 7, to
implement multiple sensors using the oscillator method requires use of Comparator_A+ enabled
devices. The analog multiplexer built into Comparator_A+ allows for multiple capacitive sensors
to independently be measured using the oscillator technique. As shown in Figure 9, a multi-
sensor system using Comparator_A+ can resolve the position of a single touch along a slider.

Figure 9. Multi-Sensor System Using Comparator_A+

PCB-Based Capacitive Touch Sensing With MSP430 9


SLAA363A – June 2007 – Revised October 2007

Using one external resistor per sensor and three additional resistors for the comparator
reference, a simple multi-sensor system can be realized using the MSP430. With 100k reference
resistors enabled as needed by a free GPIO, a sensitive yet ultra-low power capacitive touch
interface system can be created. Figure 10 shows the average current consumption and
measurement time for a single capacitive sensor using this methodology.

Current & Measurement Time vs.


Measurement Window (1% C_delta)

35
30
25
20
15
10
5
0 t_meas (ms)
64 (0) 512 (3) Icc_avg (uA)
8192
32768
1MHz SMCLK/x (50)
(199)
(counts)

Figure 10. Current Consumption and Measurement Time for One Sensor

Each measurement above is made for a 1% change in sensor capacitance. While small, this is
not an uncommon amount of change for many systems due to mechanical constraints. As the
measurement window is increased using a larger WDT divider resulting in a longer time between
consecutive interrupts, the number of counts for a given change in capacitance increases. More
delta counts correlates to more sensitivity and better usability in system. This high count delta
can be achieved for a given delta C at the price of a longer measurement time and in turn,
increased average current.

System Current Contributors


ƒ DCO: ~85 µA at 1 MHz
ƒ Comp_A+: ~45 µA
ƒ CA Vref: Vcc/(1.5R) (for 100k Rs, ~20 µA)
In order to get the most out of the application, defining t_measure for adequate counts for the
application, yet small enough to keep current consumption to a minimum is the key.
ƒ A larger delta C means a smaller t_measure window can be used
ƒ Design to fewest counts needed for lowest current

10 PCB-Based Capacitive Touch Sensing With MSP430


SLAA363A – June 2007 – Revised October 2007

3.2 Resistor-Based Capacitive Measurement


The second methodology to be described uses an external resistor to charge or discharge the
given capacitive sensor. Using the port pins of the MSP430 to charge or discharge the sensor
cap, the internal Timer_A can be used to measure the corresponding charge or discharge time.
Given a fixed external resistance to provide the charge/discharge path, the capacitance of the
sensor can be measured. Figure 11 shows this system as implemented with an MSP430 for a
discharge-only measurement.

MSP430

PX.Y

CSENSOR R TACCRx
Capture

Figure 11. Basic Resistive Discharge Capacitance Measurement

With the same small CSENSOR of ~10 pF, it is clear that R needs to be quite large in order to
provide any realistically measurable discharge time. In this implementation, R is chosen to be
5.1M, giving a discharge window from Vcc to near ground of ~250 µs (5tau). In this
configuration, Px.y can be an output high to charge the sensor capacitor. It can then be switched
to an input, allowing CSENSOR to discharge through R. Given the ±50 nA max port pin leakage of
the MSP430, such a measurement implementation is possible with little discharge contribution
via the port pin structure.
If Px.y is an interrupt-enabled GPIO (P1.x or P2.x in all MSP430’s), the internal low-level
threshold trip voltage can be used as a discharge reference, which when reached, an interrupt
can be generated. Using this interrupt, the CPU can take a snapshot of the Timer_A register
using the capture logic of the Timer_A module, storing the time taken to discharge the given
sensor. Using the internal DCO, the timer can be clocked at frequencies up to 8 MHz or 16 MHz
depending on the MSP430 used (1xx, 2xx, or 4xx devices). The higher the frequency the higher
the count delta can be for a given change in sensor capacitance. Figure 12 details the overall
measurement flow using the Timer_A peripheral.

PCB-Based Capacitive Touch Sensing With MSP430 11


SLAA363A – June 2007 – Revised October 2007

Timer Counter
Charge Sensor
Set Px.y to Start Timer_A
Output High & discharge
sensor

Discharge Sensor TAR =


Set Px.y to Input w/ H-L Count result
INT enabled

Measure tdischarge ∆TAR


TAR
Start Timer_A & Enter
LPM0
VCC

LPM0
VSENSOR

Px.y INT?

Discharging
Measure tdischarge Trip Point
VIT-
Stop Timer_A & Read TAR
Switch Px.y to Output Low VSS

t-t- t
Switch to
Enter
Active
Next Sensor
Active

LPM3 LPM0 LPM3

Figure 12. Measurement Methodology Using the GPIO Threshold and Timer_A

The flow chart and graph in Figure 12 show a single measurement cycle. When the timer is
started from zero for the measurement, the TAR value after the trip point is reached is the
resulting number of counts for the measurement. Alternatively, the timer can be allowed to run
continuously, in which case a timer capture needs to happen at both the start of the discharge
and at the completion, then the difference in counts from the two points is the count result.
As the sensor capacitance increases, the time to discharge also increases and the number of
counts measured goes up. The more counts that can be realized between an untouched sensor
and a touched sensor, the better the sensitivity of the system.
The described setup in Figure 11 shows one port pin and one resistor for each sensor in the
system. The setup can be further optimized by sharing a single resistor for each pair of sensors.
During measurement of one sensor in the pair, the GPIO connected to the other sensor and the
other side of the resistor can be set to a low output, creating the ground point for the discharge.
These orientations can be swapped for the measurement of the second sensor in the pair.
Figure 13 shows this configuration, optimizing the resistor count to ½ the number of sensors in
the system for an even sensor count.

12 PCB-Based Capacitive Touch Sensing With MSP430


SLAA363A – June 2007 – Revised October 2007

Figure 13. Multi-Sensor Charge/Discharge Configuration

Another benefit of this configuration is that each sensor can be measured in both directions:
charged from ground to the high level threshold and then discharged from Vcc to the low level
threshold trip point. Figure 14 shows this method.

Timer Counter
GPIOSENSOR = Vcc
GPIOR = Gnd

GPIOSENSOR = GND
GPIOR = Vcc

∆TAR
TAR ∆TAR
TAR

VCC
Charging Trip
Point
VIT+
VSENSOR

Discharging
Trip Point
VIT-

VSS
t+t+ t-t- t
Active

Active

Active
Active

LPM0 LPM3 LPM0 LPM3

Figure 14. Single Measurement Cycle for Improved Noise Rejection

PCB-Based Capacitive Touch Sensing With MSP430 13


SLAA363A – June 2007 – Revised October 2007

The measurement count is now the combination of the two results. These can be averaged or
simply summed, as the absolute result is not of interest, but instead the difference from the base
measurement result. By measuring both the charging and the discharging phases, system noise
such as 50/60-Hz mains noise can be better rejected from influencing the final result.
Average current consumption for the charge/discharge system is quite low. For the given sensor
and a 1% capacitance change, Figure 15 charts the average current consumption and
measurement time for a single sensor based on the DCO frequency used to clock Timer_A.

Current & Measurement Time vs.


Measurement Window (1% C_delta)

0.16
0.14
0.12
0.1
0.08
0.06
0.04
0.02
0 t_meas (ms)
1MHz (1) Icc_avg (uA)
8MHz (4)
12MHz
16MHz
(6)
(8)
SMCLK
(counts)

Figure 15. Resistive Charge/Discharge ICC and Measurement Time: Single Sensor

Given a 5.1M resistor and using the charge/discharge combined measurement, a single sensor
can be measured in a fraction of a millisecond. Since the measurement time is set by the time
taken to charge or discharge the sensor, the actual time needed is quite small due to the very
small sensor capacitance. This time is essentially fixed in this method of measurement, so the
variable under design control is the frequency used to drive the timer. The higher the frequency
used for the Timer_A TAR, the larger the count result for a given change in capacitance. In the
measurement shown in Figure 15, using 1 MHz provides a count delta of only 1 count, not
usable for button determination. At 16 MHz, the count delta realized goes up to ~8, providing
some margin for a touched/untouched switch detection event.
As the change in capacitance goes up, the larger the resulting measurement number will be for
use in the system. Increasing the amount of influence of the user by reducing the thickness of
the overlay is a good method to increase the usable count delta.

14 PCB-Based Capacitive Touch Sensing With MSP430


SLAA363A – June 2007 – Revised October 2007

4 Software Implementation
Once the raw measurement result is obtained, the user software must now interpret the data for
the given application. Given the sensitivity of the measurement, noise due to power supply,
measurement clock frequency shift, and external factors such as 50/60-Hz mains noise can all
lead to noisy results.
Often it may be good enough to simply ignore some number of LSBs of the result. When a large
change in measured counts are achieved for a given touch event, this approach is likely
acceptable. For instance, when doing simple key press detection for on/off function, noisy LSBs
can often be ignored. When the application requires better resolution, e.g., implementation of a
multi-point slider, it may be necessary to handle the data more carefully. Low pass filtering of the
data and simple averaging of multiple samples can help to smooth out position detection in such
a system. As system constraints such as power budget and specifically the insulator thickness of
the sensor overlay are tightened, the resulting LSB content is more critical to extract.

4.1 Tracking Sensor Base Capacitance


Whether implementing a simple button sensor or more complex slider, tracking of each sensor’s
base capacitance is a key element of any touch sensing software algorithm. The base
capacitance is the capacitance of a given sensor when untouched by the user. Voltage stability,
PCB mechanics, insulator properties as well as ambient conditions such as temperature and
proximity to other objects all play a role in the base measurement of a PCB-based capacitive
sensor.
Without a dynamic ability to track this changing baseline value, instability can result in false
press detection or “stuck key” behavior. Consider a simple button that has a preset on/off
threshold without dynamic baseline tracking. In the case that the baseline result drifts, it may
move towards the trip threshold for a valid key press. If there is enough drift in the base
(untouched) result, it can reach the pre-set trip point and create such a false trigger.
One method for dynamically measuring and adjusting (tracking) the base capacitance is shown
in Figure 16. Keep in mind that this must be done for each sensor independently. Also note that
an increase or decrease in the variable “base” in the Figure is not necessarily reflecting a
respective increase or decrease in base capacitance. Only the variable used in the algorithm is
being adjusted. The sign of the “Delta” calculation and “base” adjustment is different for the RO
and RC methodologies. (For RO the measured count decreases when the capacitance of the
sensor increases; for RC the measured count increases when the capacitance of the sensor
increases.)

PCB-Based Capacitive Touch Sensing With MSP430 15


SLAA363A – June 2007 – Revised October 2007

Figure 16. Example Algorithm for Tracking Baseline Sensor Capacitance

When a measurement is completed, it must first be determined if a valid touch is occurring. This
can be done by looking for a threshold that would represent the smallest real touch to be
detected. For a simple on/off button this can be a number much smaller than the on/off
threshold.
Once determined that no touch is occurring, the base value can be adjusted. How the base
value is adjusted is dependent on the direction in which it is perceived to have changed. For
instance, if the result of the measured sensor indicates that the base capacitance is decreasing,
the base value is automatically adjusted down. Since a touched sensor will increase in
capacitance, the decreasing result is taken as a genuine decrease in the base value. This is
implemented by a simple average of the old base value with the new measured value, resulting
in the new base value to be used in the next measurement.
When the measured result indicates an increase in base capacitance, it is recommended that
the base value be tracked more slowly. While an increase may mean that that it is truly shifting
up, it may also mean that a finger is nearby that will soon be in contact with the sensor in
question. If the base value is adjusted upwards too quickly, the change calculated when the
finger is really in contact with the sensor may not be enough to indicate a press. For a detected
increase in an untouched sensor, the base value is simply adjusted by a single count in the
algorithm represented in Figure 16.

16 PCB-Based Capacitive Touch Sensing With MSP430


SLAA363A – June 2007 – Revised October 2007

4.2 Implementing Button Function


Implementing simple button functionality is relatively straight forward using capacitive touch
sensing. Because a single level of detection is required for a simple on/off button, the sensitivity
and magnitude of the change in capacitance for a touch event is minimal. Figure 17 shows a
graphical representation of the measured counts in a system for four keys. Untouched keys
provide a count representing the base capacitance. The second key that is touched provides a
larger delta count result, due to the increased capacitance. Sensitivity of each key is tuned by
adjusting the threshold to a higher or lower value between the base and maximum count results.

∆TAR

Figure 17. Button Press in a Four-Key System

The threshold set point should be above any noise in the measurement to allow for a robust and
accurate key press result.

4.3 Implementing Slider Function


Extending beyond simple buttons with on/off functionality, it is possible to determine more than
one threshold using the capacitive sensor to implement multiple “positions” for a single “button”.
As more of the capacitive sensor is interacted with by the user, the larger the capacitance will
be. Figure 18 represents the response as a single touch moves across the four sensor
elements.

PCB-Based Capacitive Touch Sensing With MSP430 17


SLAA363A – June 2007 – Revised October 2007

Figure 18. Fundamental and Neighboring Sensor Response

A simple slider implementation can be realized by assigning multiple positions to each sensor.
The example here establishes 16 positions to each sensor of the four sensor configuration
providing detection of 64 individual steps. The number of steps a sensor can accommodate is a
function of the sensitivity of the sensor to a given touch, which is the amount of capacitive
change induced. The greater the change in capacitance, the greater the number of delta counts
measured, and the greater the number of individual positions per sensor. Figure 19 defines a
simple algorithm that implements a 64 position slider with four sensors.

Set max delta expected


Set steps per key (stepsKEY)
DELTAMAX Step size = max delta / stepsKEY
(slider steps = stepsKEY * #keys)

Count Delta Step size


Get key delta & limit to max
value
positionKEY = delta / step size

0 If KEY pressed: Slider position =


1 2 3 ... Steps positionKEY + steps*weightKEY
(0, 1, 2, 3...)

Figure 19. Example Slider Position Determination Methodology

This implementation simply limits the maximum response to an upper value which can always
be achieved for a given system. This max delta is then divided by the desired steps per key.
Each key is weighted to linearly result in steps 1 through 64 (position “0” is defined by no key
press). The most significant sensor touched is used for determining the position. Table 2
indicates the associated steps from each key.

Table 2. 64-Position Slider Key

Sensor Positions per sensor Weight factor Resulting Position

1 to 16 0 1-16 + 16×0: 1-16


1 (min to max delta)

1 to 16 1 1-16 + 16×1: 17-32


2 (min to max delta)

1 to 16 2 1-16 + 16×2: 33-48


3 (min to max delta)

1 to 16 3 1-16 + 16×3: 49-64


4 (min to max delta)

18 PCB-Based Capacitive Touch Sensing With MSP430


SLAA363A – June 2007 – Revised October 2007

One drawback to this simple method is that once the maximum delta is achieved for a given
sensor, the position calculated will not change until the next most significant sensor is
influenced. While not described in the context of this document, it is possible to realize robust
implementations providing a more linear transfer characteristic by interpolating position based
on not only the maximally influenced sensor, but also its neighbors.

4.4 Handling Slider Endpoints


The simple slider described previously determines position across a 4-sensor array. Position “0”
is for no key press and position “1” is the lowest key press. It is associated to the left-most
position of the slider. Position “64” is the maximum position and is associated to the right-most
position of the slider.
The simple algorithm implemented inherently handles proper increase or decrease in position at
the minimum end point and up through the sensors moving left to right. However the maximum
endpoint must be managed more directly. This is because the measured result for the most
significant end will decrease from the maximum delta once the touch extends beyond the center
of the last sensor and will increase from the minimum with a touch beginning at the rightmost
edge of the same sensor. Figure 20 represents both scenarios.

Figure 20. Representation of Count Measurement Results for Max Endpoint

In the figure, the A portion represents a touch extending up to and then beyond the desired
maximum position and the B portion shows a touch approaching from the maximum position. In
both cases, this influence must be correctly assessed and the expected position calculated
accordingly.
In the case of this 64-position slider, a touch extending beyond the maximum position, left-to-
right, will result in a decrease in measured response for the end key until the key is no longer
touched measured as a “0” delta result. Without any special handling, this will appear as a
decrease from position 64 gradually down to 49 and then 0, even though the touch did not move
in the decreasing direction.

PCB-Based Capacitive Touch Sensing With MSP430 19


SLAA363A – June 2007 – Revised October 2007

Similarly, a touch approaching from the right-most position, tight-to-left, it will appear as an
increase in measured response for the end key until the maximum influence is applied resulting
in a maximum delta measurement. Without any special handling, this will appear as an
immediate change from 0 to 49 and then gradually increase up to 64, even though the touch
started at the physical end of the slider.
The algorithm defined in Figure 21 manages both conditions. In the case that condition A in
Figure 20 is occurring, it is detected by monitoring the last position calculated as well as the next
to last sensor (the third sensor in this example). When the third sensor is determined to be
decreasing in influence and the prior position was the max, 64, the new position calculated will
be held at 64, even if the actual measured result for the last sensor is decreasing.

Figure 21. Example Slider Endpoint Handling

In the case condition B is occurring, it is detected by determining that the rightmost key is
beginning to be touched without any response form the next key to the left. This is interpreted as
a touch moving right to left beginning at the rightmost sensor and results in an immediate
position determination at the maximum, 64.

4.5 Sensor Multiplexing for Sliders


When implementing sliders, it is often possible to extend the number of sensors used beyond
the actual number of MSP430 pins available for measurement. This is achieved by connecting
more than one sensor to a given measurement pin. To the measurement, the additional sensor
simply appears as a larger base capacitance and does not impact the functionality of the
system. However, since the base capacitance is increased and only one of the two sensors is
influenced at a time, the response of the parallel sensors decreases. A practical limit for the
number of sensors connected in parallel is considered to be two.

20 PCB-Based Capacitive Touch Sensing With MSP430


SLAA363A – June 2007 – Revised October 2007

In terms of the sensor pairs being measured, the MSP430 cannot distinguish between the two
and “sees” the same result for both, independent of which sensor in the pair is actually touched
by the user. In order to use such a setup for a slider implementation, it is assumed that the
mechanical design allows for multiple sensors to be influenced along any point of the slider. If
this is achieved, and the sensors are organized in a way that the combined response of multiple
sensors being influenced is unique for any position along the slider, the usability of the slider and
positions can be extended. Figure 22 show a 6-to-12 pairing and the positions of each of the
6 pairs. Analyzing the figure it can be determined that for a touch anywhere along the slider, a
unique response will be established across the group of sensors. Using an interpolating
algorithm that accounts for this unique response detection, the sensor count can be extended
beyond the actual pin count for a given device.

1 2 3 4 5 6 2 4 1 5 3 6

Figure 22. Example Sensor Multiplexing of 12 Capacitive Sensor Elements

PCB-Based Capacitive Touch Sensing With MSP430 21


SLAA363A – June 2007 – Revised October 2007

5 Summary
Two methods of implementing single-touch capacitive sensing on the MSP430 have been
discussed. While each method has its own advantages and disadvantages, each can be used to
realize a solution when the proper measures are taken both from a mechanical assembly and
hardware/software standpoint.
In summary, each method’s key takeaways are:

MSP430 RO Method
o Works in Comp_A+ devices only
o Number of independent sensors limited by available CA+ mux inputs
o Needs one external resistor per sensor plus reference ladder (three additional
resistors)
o Sensitivity limited by current consumption (programmable measurement time)

MSP430 RC Method
o Can be implemented on any MSP430
o Up to 16 independent sensors (16 interruptible GPIOs)
o Single external resistor per two sensors
o Sensitivity limited by on-chip maximum clock frequency (fixed measurement time)
o Lowest power implementation
Fundamentally, the actual measurement of the capacitance is quite simple; however, the
mechanics of the assembly regarding the sensors and touch interface along with the software
algorithms used to determine the nature of the touch provide the implementation in an end-
equipment with significant challenges. The contents of this application report are not to provide a
one-size-fits-all solution, but rather to establish the fundamentals of the application and
methodologies used which can be extended and customized to fit a given product.

6 References
Special thanks to fellow TIers Vincent Chan and Steve Underwood for their significant
contributions to this application development.

1. Robert E Marin, Roger K Simonson, “Capacitive Keyswitch Sensor and Method” US Patent
#3931610, 1976
2. MSP430x2xx Family User’s Guide (SLAU144)
3. MSP430F20xx data sheet (SLAS491)
4. MSP430FG4618/F2013 Experimenter Board and Software
http://focus.ti.com/docs/toolsw/folders/print/msp-exp430fg4618.html
5. MSP430 USB Stick Development Tool http://focus.ti.com/docs/toolsw/folders/print/ez430-
f2013.html

22 PCB-Based Capacitive Touch Sensing With MSP430


SLAA363A – June 2007 – Revised October 2007

Appendix A. Flexible Evaluation and Demonstration Hardware


This section is the hardware description of a 4-button MSP430-based single-touch capacitive
sensing system described and used for test/measurement in the previous sections of this
document. This hardware implements both the oscillator and RC methods on a single platform
for evaluation purposes

Figure 23. Flexible 4-Button RO/RC System Block Diagram

Both methods for capacitive sensor measurement discussed can be realized with this hardware.
However, each method is implemented independent of the other, allowing the two instances to
be cut apart from a single PCB. In addition to the touch sensing interface, each implementation
provides a dedicated 2xAAA battery power supply, 14-pin header for JTAG access to each
MSP430 MCU and hardware interface to Timer_A pins. The Timer_A connections allow for
communication of-board with a PC-based application, for example, providing a means of data
transfer and control via standard UART. (Detailed implementation of a Timer_A UART can be
found in additional MSP430 Application Note collateral.)
Corresponding hardware and software materials can be found in the .zip archive associated with
this application note, downloadable from www.msp430.com.

PCB-Based Capacitive Touch Sensing With MSP430 23


SLAA363A – June 2007 – Revised October 2007

Appendix B. Simple Demonstration Hardware


This section is the hardware and software description of a simple 4-button single-touch sensing
system using the MSP430. This system implements only the RC-based measurement technique
and is designed for a use with the EZ430 development tool.

Figure 24. Simple 4-Button RC System Block Diagram and Image

Information regarding the EZ430 development tool can be found at


http://focus.ti.com/docs/toolsw/folders/print/ez430-f2013.html
Corresponding hardware and software materials can be found in the .zip archive associated with
this application note, downloadable from www.msp430.com.

24 PCB-Based Capacitive Touch Sensing With MSP430


IMPORTANT NOTICE
Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, enhancements, improvements and other
changes to its semiconductor products and services per JESD46, latest issue, and to discontinue any product or service per JESD48, latest
issue. Buyers should obtain the latest relevant information before placing orders and should verify that such information is current and
complete. All semiconductor products (also referred to herein as “components”) are sold subject to TI’s terms and conditions of sale
supplied at the time of order acknowledgment.
TI warrants performance of its components to the specifications applicable at the time of sale, in accordance with the warranty in TI’s terms
and conditions of sale of semiconductor products. Testing and other quality control techniques are used to the extent TI deems necessary
to support this warranty. Except where mandated by applicable law, testing of all parameters of each component is not necessarily
performed.
TI assumes no liability for applications assistance or the design of Buyers’ products. Buyers are responsible for their products and
applications using TI components. To minimize the risks associated with Buyers’ products and applications, Buyers should provide
adequate design and operating safeguards.
TI does not warrant or represent that any license, either express or implied, is granted under any patent right, copyright, mask work right, or
other intellectual property right relating to any combination, machine, or process in which TI components or services are used. Information
published by TI regarding third-party products or services does not constitute a license to use such products or services or a warranty or
endorsement thereof. Use of such information may require a license from a third party under the patents or other intellectual property of the
third party, or a license from TI under the patents or other intellectual property of TI.
Reproduction of significant portions of TI information in TI data books or data sheets is permissible only if reproduction is without alteration
and is accompanied by all associated warranties, conditions, limitations, and notices. TI is not responsible or liable for such altered
documentation. Information of third parties may be subject to additional restrictions.
Resale of TI components or services with statements different from or beyond the parameters stated by TI for that component or service
voids all express and any implied warranties for the associated TI component or service and is an unfair and deceptive business practice.
TI is not responsible or liable for any such statements.
Buyer acknowledges and agrees that it is solely responsible for compliance with all legal, regulatory and safety-related requirements
concerning its products, and any use of TI components in its applications, notwithstanding any applications-related information or support
that may be provided by TI. Buyer represents and agrees that it has all the necessary expertise to create and implement safeguards which
anticipate dangerous consequences of failures, monitor failures and their consequences, lessen the likelihood of failures that might cause
harm and take appropriate remedial actions. Buyer will fully indemnify TI and its representatives against any damages arising out of the use
of any TI components in safety-critical applications.
In some cases, TI components may be promoted specifically to facilitate safety-related applications. With such components, TI’s goal is to
help enable customers to design and create their own end-product solutions that meet applicable functional safety standards and
requirements. Nonetheless, such components are subject to these terms.
No TI components are authorized for use in FDA Class III (or similar life-critical medical equipment) unless authorized officers of the parties
have executed a special agreement specifically governing such use.
Only those TI components which TI has specifically designated as military grade or “enhanced plastic” are designed and intended for use in
military/aerospace applications or environments. Buyer acknowledges and agrees that any military or aerospace use of TI components
which have not been so designated is solely at the Buyer's risk, and that Buyer is solely responsible for compliance with all legal and
regulatory requirements in connection with such use.
TI has specifically designated certain components as meeting ISO/TS16949 requirements, mainly for automotive use. In any case of use of
non-designated products, TI will not be responsible for any failure to meet ISO/TS16949.
Products Applications
Audio www.ti.com/audio Automotive and Transportation www.ti.com/automotive
Amplifiers amplifier.ti.com Communications and Telecom www.ti.com/communications
Data Converters dataconverter.ti.com Computers and Peripherals www.ti.com/computers
DLP® Products www.dlp.com Consumer Electronics www.ti.com/consumer-apps
DSP dsp.ti.com Energy and Lighting www.ti.com/energy
Clocks and Timers www.ti.com/clocks Industrial www.ti.com/industrial
Interface interface.ti.com Medical www.ti.com/medical
Logic logic.ti.com Security www.ti.com/security
Power Mgmt power.ti.com Space, Avionics and Defense www.ti.com/space-avionics-defense
Microcontrollers microcontroller.ti.com Video and Imaging www.ti.com/video
RFID www.ti-rfid.com
OMAP Applications Processors www.ti.com/omap TI E2E Community e2e.ti.com
Wireless Connectivity www.ti.com/wirelessconnectivity

Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265
Copyright © 2014, Texas Instruments Incorporated

You might also like