Adding a Capacitive-Touch User Interface With Resources Already Present In Your System JONATHAN DILLON, MICROCHIP TECHNOLOGY INC. For many systems, the building blocks for implementing capacitive sensing, as either a proximity sensor or a button, are already present in the peripherals of a microcontroller, and these resources may currently be unused. This Article will discuss the methods for adding a capacitive-touch user interface with resources already present in your system: ith your embedded system already containing a microcontroller, you may be able to replace buttons and proximity sensors with Wcapacitive-touch controls for minimal expense, or even cost savings. Capacitive-touch user interfaces have become popular for modern applications because of their aesthetically pleasing, sleek controls; the fact that they do not have moving parts, allows the system to be sealed from the elements; and because they enable high tech control panels. However, the implementation of capacitive-touch user interfaces has been regarded as a mysterious art. For many systems, the building blocks for implementing capacitive sensing, as either a proximity sensor or a button, are already present in the peripherals of a microcontroller, and these resources may currently be unused. This Article will discuss the following methods for adding a capacitive-touch user interface with resources already present in your system: 1. Capacitive sensing using just the MCU s internal Analog-to-Digital Converter () 2. Measuring capacitance using an internal precision current source and the 3. Using the capacitive-sensing circuitry embedded into the I/O pins of a number of microcontrollers and onboard counter/timers. The Article will also explain the software handling required to overcome noise and other environmental issues, as well as methods for lowering power consumption when capacitive touch is used to turn systems on and off. Some of the design techniques required for implementing reliable capacitive touch sensing will also be covered. Introduction Capacitive-touch-sensing user interfaces have grown in popularity, due to the fact that they offer sleek, single-panel controls which, beyond their stylish design aspects, offer increased reliability and robustness. The lack of moving parts in capacitivetouch-sensing user interfaces prevents contact wear or corrosion and mechanical failure of push buttons, which improves product life. The ability to sense touch through materials allows panels to be sealed, protecting internal electronics from harsh environments and with greater durability than membrane technology. However, capacitive touch is not a purely binary signal, unlike a mechanical button; but instead, capacitive touch is an interpretation of an analog signal. As capacitive-touch technology does not require a direct electrical connection, but instead senses through material, it can also be used as a proximity sensor for user interfaces that react to users approaching the interface, rather than touching it. With many systems and user-interface control circuits already containing a microcontroller, implementing a capacitive user interface may lower system costs and component count. Buttons, sliders and dials can be replaced by capacitive sensors, which may be simple as conductive pads on the circuit board. These can essentially cost nothing while bringing far greater reliability. Capacitive touch functions when the user presses the surface of the panel, creating a capacitor to ground, where one plate is a conductive pad on the circuit board and the other is the user s finger. The conductive pad also has parasitic capacitance, as
Fig. 1. Sensor Capacitance do the circuit traces that connect it to the microcontroller. This parasitic capacitance can vary due to environmental changes, such as those associated with temperature and humidity. As these two capacitances are in parallel, as seen in Figure 1, we cannot simultaneously measure them. The capacitance created by a user s finger is dependant upon the area of the plate and finger, as well as the thickness and dielectric of the panel material, as given in Equation 1. C f = å å A 0 r d Equation 1: Capacitance of Parallel Plates C f is the capacitance created by the user s finger e0 is the permittivity of free space, 8.85 10-12 er is the dielectric constant of the material between the two plates A is the overlapping area of the two plates d is the separation between the two plates The larger the capacitance created, the easier it is to detect a touch or sense proximity. From Equation 1, we can discern that the key factors in the capacitance created are the material selected for the user-interface panel and its thickness. The material choice determines the dielectric, and the thickness determines the separation between the user s finger and the conductive pad. Enlarging the area of the conductive pad on the board is only effective up to the area of the user s finger, since it is the overlapping area that is important. However, for proximity sensing, the conductive pad may be sized to couple with a user s hand, and the increased area improves the sensing range. For mechanical reasons, such as bracing ribs on the interface panel, it may not be possible to adjacently mount the circuit board. This can be overcome by mounting a spring on the circuit board instead of a conductive pad. The spring should press tightly against the button area on the interface panel, bridging the gap between it and the circuit board. The user s finger then couples to the spring through the panel. This method minimizes the capacitive-plate separation and avoids an airgap, which can significantly diminish responsiveness. A capacitive-touch interface continually measures the capacitance of the conductive pad and tracks the gradual environmental changes in parasitic capacitance, thus keeping an internal estimate for use in determining when a touch has occurred, which induces a frequency change in capacitance. Measurement Methods Methods suitable for a microcontroller to measure the capacitance of the conductive pad are: Capacitive Voltage Divider Charge Time Measurement Capacitive Sensing Module All three methods require no external components; however they do place some requirements on the microcontroller to measure and interpret the capacitance. Capacitive Voltage Divider This method requires a microcontroller with an internal Analog-to-Digital Converter (), which is already a common requirement for many systems, and no other features of the microcontroller. This method uses the internal holding capacitor of the with the capacitance of the conductive sensing pad on the circuit board to create a voltage, which is dependant upon the capacitance of the sensor. This voltage is then measured using the and handled by software. In normal operation, when performing an analogto-digital conversion, the analog mux in Figure 2-1 is used to select and measure the voltage on the pin of the microcontroller, referred to as the selected channel. The holding capacitor is allowed to charge to the voltage on the pin the acquisition I/O or Analog inputs Analog mux Sampling switch VCHOLD CHOLD - Holding capacitor Fig. 2-1. Analog Channel and Circuitry in a
time, and then the sampling switch is opened and the creates a digital representation of the voltage across the holding capacitor. The pins of the microcontroller can also be configured as digital I/O while they are selected by the analog mux, which allows us to charge and discharge the holding capacitor to the power rails. This measurement method requires a number of steps. The timing of some steps can be critical, as capacitors exhibit leakage and delay will cause readings to drift. i) To initialize the system for a measurement, we need to appropriately charge and discharge the capacitors in our system. By using the analog mux to select an unused pin and configure it as an output driven high, we can charge the internal holding capacitor. Meanwhile, we need to ensure that the sensor is uncharged. Thus, we configure the connected pin as an output driven low, which grounds the sensor. The states of the analog mux and outputs can be seen in Figure 2-2. ii) Once the sensor capacitance has been discharged and the holding cap has charged to the positive supply voltage, the output drive on the pin VCHOLD CHOLD - Fig. 2-2: CVD Measurement Initialization State connected to the sensor is disabled, as shown in Figure 2-3. At this time, the line to the capacitor is floating, and the capacitor may acquire some charge through pin or board leakage. As a result, this stage needs to be kept as short as possible. iii) The pin connected to the sensor is selected using the analog mux, which places the holding capacitor in parallel to the sensor. The holding capacitor was charged to VDD, while the sensor is CHOLD Fig. 2-3: Sensor no longer discharged - VCHOLD completely discharged. As a result, current flows from the holding capacitor to the capacitive sensor. The analog mux allows for bi-directional current flow, though its impedance does cause some losses. iv) After allowing sufficient time for the system to stabilize, an analog-to-digital conversion is initiated that opens the sampling switch, as seen in CHOLD - VCHOLD Fig. 2-4: Sensor Capacitance and Holding Capacitor in Parallel Figure 2-1. The voltage across the holding capacitor is then measured. This stabilization time is very short, and a conversion can usually be started on the following instruction. The voltage across the holding capacitor is dependant upon the capacitance of the sensor, which is the sum of its parasitic capacitance and of the user s finger, if present. This leads to the below relationship, with the voltage measured by the. C Equation 2-1: hold V Chold = X V C hold C p C dd Voltage across f Holding Capacitor VChold is the voltage measured by the is the supply voltage to the microcontroller Chold is the capacitance of the holding capacitor, which is 10pF for the device tested Cp is the parasitic capacitance of the sensor Cf is the capacitance created by a finger press From the equation, we can see that the additional capacitance of a finger press will cause a reduced voltage on the holding capacitor. This translates as a lower result from the. The resolution of the readings is governed by the s resolution. For this reason, a 10-bit is recommended. A lower-resolution can be used, but it will require a greater change in capacitance, which typically requires less plate separation and a thinner interface panel. To increase the resolution, conversions can be performed using a lower reference than the power rails, since the voltage measured is typically much
Untouched Touched Sampled Fig. 2-5: Voltage across the Sensor lower. This reference change will increase the voltage resolved per bit, but care needs to be taken to avoid saturation. Saturation is when the voltage being converted exceeds the reference voltage, and the can only respond with its maximum output code. As capacitive measurements are very fast, typically 10-20 µs, the sensor can be oversampled to improve resolution. The prior text discussed charging the holding capacitor with an unused pin. However, if multiple capacitive-touch sensors are to be measured, the pin used for another sensor may temporarily be employed for charging the holding capacitor. The sensor for that input is not currently being measured and thus can be driven high, as the capacitances involved are small, and so is the output impedance of a digital output. Any internal references to the may also be used to charge the holding capacitor. Charge Time Measurement Some microcontrollers incorporate a constant current source that can be used to charge the sensor s capacitance for a fixed period and then measure the voltage developed, as shown in Figure 2-6. The additional capacitance of a user s finger coupling to the sensor will reduce the voltage being measured by the. V is the voltage measured by the i is the current from the constant-current source tcharge is the fixed time period that the sensor is charged Chold is the capacitance of the holding capacitor, which is 10pF for the device tested Begin Charge Sample Fig. 2-6: Charge Time Measurement Unit (CTMU) Voltage across Sensor V = Cp is the parasitic capacitance of the sensor Cf is the capacitance created by a finger press This implementation uses the analog channelselect mux of the, as shown in figure 2-7, to select different pins of the microcontroller. This allows it to scan multiple sensors, and the holding capacitor is charged in parallel to the sensor capacitance to avoid creating a capacitive voltage divider. Before the current source can be enabled, the capacitor s charge needs to be a known value. Thus, it is grounded through an internal gate in the microcontroller to ensure it is completely discharged. The current can be adjusted in software to give a fast charging time, thus allowing rapid measurements for the scanning of multiple sensors. The constant-current source is implemented on a number of Microchip higher pin count microcontroller, which have many analog channels allowing many capacitive sensors to be implemented. Sensor 0 Sensor 15 i x t E q u a t i o n 2-2 : charge Voltage Developed C hold C p C f across Sensor AN0 AN15 Current Source CTMU Fig. 2-7: Circuitry and Current Source A/D Conversion Trigger Capacitive Sensing Module Several newer general-purpose microcontrollers include a capacitive-sensing module that incorporates specific circuitry for capacitive sensing. It includes a large analog mux, which allows multiple capacitive sensors to be scanned for multi-button interfaces and uses a pair of internal counter timers, in addition to the CSM module. The module uses internal constant-current sources, and sinks to alternatively charge and discharge the sensor capacitance based off a lower and upper trip point, causing the waveform seen in Figure 2-9. The switching between the current source and sink is handled automatically by the module, and the
charge/discharge period is dependant on the sensor capacitance, where an increase in the capacitance will increase this time. To measure the frequency of the waveform, it is used to provide a clock signal for a digital logic counter/timer. By clearing and enabling the counter for a specific time window and reading its Sensor 0 Fig. 2-8: CSM Connections and Resources ending value, we know how many oscillations occurred in that time period. An increase in capacitance, such as from a press, lowers the oscillation frequency leading to less counts being recorded, as seen in Figure 2-10. The time window period can be controlled by another counter, which can also disable the oscillation count automatically to allow the processor to handle other tasks. The time window can also be provided using the V 2 V 1 CPS0 CPS15 Fig. 2-9: CSM Sensor Waveform Cap Sense Module (Oscillator) Frequency Capture TMR1 TMR0 TMR2 oscillator from the Watchdog supervisor timer, WDT, which is extremely low power. The microcontroller can be in a low-power sleep mode while the CSM is still running and incrementing the counter/timer. The WDT will periodically wake the microcontroller, where the oscillation can be read and handled by the software. To handle the changing parasitic capacitance of the circuit, we need to keep a baseline value for the current parasitic capacitance, which is typically handled using a moving average filter acting on the results of prior measurements of the sensor. Due to the limited memory available, it is common to employ an IIR-based moving average, to avoid t having to store multiple previous samples. To determine whether there has been a press, the result of the last measurement of the sensor s capacitance is tested against the baseline. If the variation is greater than a design threshold, then a touch is determined to have occurred and should be handled by the software. Instead of using the c a p a c i t a n c e m e a s u r e m e n t directly, a filtered o r a v e r a g e d m e a s u r e m e n t First Time Window Second Time Window time Fig. 2-10: Clock Signal to the Internal Counter/Timer About Author may be used i n s t e a d, depending upon the application. The Capacitive Sensing Module can be used for proximity sensing as well as touch, since they are effectively the same operation; but the separation of the two plates is much greater. By increasing the size of the measurement time window, smaller variations in capacitance can be seen and transient noise is also averaged out over the time window. However, this is only effective up to a point, as it can make the interface slow to respond due to the time lag. For proximity sensing, the resolution can be increased by using the counter timers to measure the period for a number of oscillations of the waveform. This configuration has increased resolution, which compensates for the increased plate separation. Discussion Capacitive sensing offers many advantages, and new practices in user interaction and styling. The lack of moving parts increases system reliability and the ability to seal the user interface from its operating environment. If a microcontroller is already used in the application, then additional switch gear can be replaced with a capacitive interface at effectively no cost, since it only requires a conductive sensor pad. However, capacitive touch sensing can place other requirements on the system namely, the mechanical mounting and material dielectric to ensure acceptable levels of capacitive coupling. Jonathan Dillon, Applications Engineer Security, Technology Development Division, Microchip technology Inc.