Simplifying Capacitive Touch Sensor Design Using the Cypress PSoC® 4000S MCU

Contributed By Digi-Key's North American Editors

Touch control is a fundamental requirement for many consumer products ranging from appliances to wearables. For developers, however, touch sensor design often seems as much an art as engineering due to the interdependencies between functional design and physical layout. Consequently, development teams can find themselves delayed as they work through multiple design interactions to achieve the best possible performance of buttons, sliders, and other elements.

To help develop projects, the Cypress Semiconductor PSoC 4000S CapSense Prototyping Kit provides a full complement of hardware and software needed to evaluate capacitive touch sensing and speed its implementation in a wide range of products.

This article will describe how the various capacitive touch sensing approaches work, and some caveats designers need to understand when designing with them. It will then introduce the PSoC CapSense kit, how it works, and how to design with it. Code examples are provided.

Why capacitive touch?

The nature of capacitive touch sensors makes them well suited to a wide range of applications. By eliminating the moving parts in conventional mechanical buttons and switches, touch sensor systems are highly reliable and unlikely to fail due to wear and tear. Further, because they can be completely encapsulated in protective materials, they are able to operate in harsh environments. Beyond their reliability, touch sensors can conform easily to different shapes, helping engineers respond to consumer demand for sleek, elegant designs in home appliances, automobiles, and other mainstream products.

Capacitive touch sensors take advantage of the change in capacitance that occurs when a finger or hand approaches a specially constructed touch surface. Touch sensors detect this change using two different approaches: self-capacitance or mutual capacitance.

In a self-capacitance touch sensor, a finger placed on the sensor pad causes a conductive pathway to ground, causing a sudden increase in capacitance that is significantly larger than the various sources of parasitic capacitance between the sensor pad and ground plane (Figure 1). Self-capacitance is typically preferred for single-touch applications such as buttons or sliders.

Image of self-capacitance detects changes in capacitance

Figure 1: Self-capacitance detects changes in capacitance between an I/O pin and ground. Surrounding the sensor with a hatch fill connected to ground improves the noise immunity of the sensor. (Source: Cypress Semiconductor)

In contrast, mutual-capacitance sensing measures the capacitance between transmit and receive electrodes (Figure 2). Here, when a controller applies a voltage to the transmit pin, the amount of charge measured on the receive pin is directly proportional to the mutual capacitance between the two electrodes. This technique can offer a higher signal-to-noise ratio (SNR) than self-capacitance, resulting in greater noise immunity. This higher SNR also provides the ability to work through thicker overlays, such as the protective screens and displays required in industrial applications.

Further, sensors arranged in an array can allow developers to track changes in mutual capacitance at different points simultaneously. Consequently, this approach is preferred in multi-touch applications using trackpads typically found in smaller consumer products, or touchscreens used in display-oriented applications in appliances and automobiles.

Diagram of mutual-capacitance sensing system

Figure 2: In a mutual-capacitance sensing system, a controller switches voltage onto a transmit (TX) electrode. The amount of charge measured on the receive (RX) electrode is proportional to the mutual capacitance between them. The touch of a conductive object such as a finger causes a change in the measured mutual capacitance. (Source: Cypress Semiconductor)

Sensor design

As illustrated in Figures 1 and 2, capacitive sensor pads are built from traces on multilayer boards. For a basic self-capacitance button, the simplest design places the sensor pad trace, surrounded by a hatched ground plane, on the top of the board. The sensor pad connects to an input pin of a controller that is typically attached at the bottom of the board, which also provides the ground plane. Finally, the top layer is covered with a non-conductive protective compound forming the sensor overlay. For keypads, engineers extend this basic design by building individual sensor pads into an array of addressable buttons.

Designers can build linear sliders out of multiple sensor pads typically arranged in a zigzag pattern. As described below, this arrangement provides information that associated touch sensor software can use to more accurately calculate finger position. Trackpads and touchscreens further extend this approach using two linear sliders to determine the X-Y position of a finger placed on the surface of the pad or screen.

In practice, the physical design of touch capacitance sensors can be quite complex as engineers work to decrease parasitic capacitance, which reduces sensitivity of the sensor. Along with careful design of the ground plane itself, the hatched ground plane requires close adherence to specific physical design rules. Further, in home appliances and other products where liquid can distort sensor readings, engineers build more complex structures to help eliminate false readings when liquid is present on the sensing surface. Mutual-capacitance sensor arrays further extend design complexity with arrays of sensors built from transmit and receive traces on multiple pc-board layers.

Although designers need to exercise care in creating these sensors, the development of capacitance touch sensors largely follows a typical design flow.  However, before  full production of the sensor boards occurs, engineers typically need to adjust hardware parameters and software settings to account for specific characteristics in components, sensor pads and boards, as well as specific requirements for sensor performance and overall power requirements. Specialized system-on-chip (SoC) devices, such as the Cypress Semiconductor PSoC 4000S, integrate specific functionality designed to simplify capacitive touch sensor implementations, including tuning requirements.

Cypress CapSense

Based on an ARM® Cortex®-M0+ processor core, the Cypress PSoC 4 device family combines memory with programmable analog and digital peripherals designed to address a wide range of applications. In particular, the PSoC 4000S provides Cypress' proprietary CapSense functionality, which is comprised of a complete signal chain for processing capacitive touch sensors. As a result, engineers can implement a touch sensor design with only a few additional components (Figure 3).

Diagram of Cypress Semiconductor PSoC 4000S device

Figure 3: The Cypress Semiconductor PSoC 4000S device integrates an ARM Cortex-M0+ core, memory, and peripherals with Cypress' CapSense capacitive sensor signal chain. Developers need only a few additional components to implement sensing solutions based on self-capacitance or mutual-capacitance designs. (Source: Cypress Semiconductor)

For self-capacitance sensor designs, engineers connect each sensor pad to a GPIO pin and add an additional external CMOD capacitor (Figure 3). Mutual-capacitance sensor designs use separate GPIOs for each sensor receive and transmit line, as well as a pair of external capacitors, CINTA and CINTB. In addition, an external CTANK capacitor supports implementation of shield electrodes used to reduce sensitivity to the presence of liquids on the surface of the sensor overlay.

The PSoC 4000S supports both self-capacitance and mutual-capacitance methods. For self-capacitance sensing, the SoC's CapSense Sigma Delta (CSD) function measures changes in self-capacitance at a GPIO using a current-to-digital converter. For mutual-capacitance sensing, the SoC's CapSense Crosspoint (CSX) function drives a Tx electrode and senses the charge on an Rx electrode. The measured charge on the Rx electrode is proportional to the mutual capacitance between the two electrodes.

In both approaches, the converter generates a raw count that reflects measured self-capacitance at a GPIO or mutual capacitance measured at an Rx pin. By comparing the raw count to programmable noise and signal thresholds, the firmware can determine if a finger is present on a button sensor pad, or on a sensor associated with a particular location on a slider or touchpad (Figure 4).

Graph of Cypress PSoC 4000S CapSense block

Figure 4: The Cypress PSoC 4000S CapSense block generates counts that indicate touch when count values rise above a programmable noise threshold and reach programmable touch thresholds. CapSense also supports hysteresis levels above and below the target touch-detection threshold. (Image source: Cypress Semiconductor)

The CapSense block can perform this scan without requiring CPU intervention. Consequently, designers could program the Cortex-M0+ core to perform other tasks during sensor scans. In practice, however, changes in current associated with independent processor activity can introduce noise in the sensitive analog circuits within the CapSense block. As a result, developers typically limit processor activity during scans, particularly for applications that require high sensitivity and correspondingly low noise environments.

In fact, different sensors can exhibit different noise levels and sensitivity due to manufacturing variations, requiring careful tuning of hardware and software parameters to correct for these differences. Beyond these systematic variations, however, more immediate changes in environmental conditions can introduce factors that dynamically impact sensitivity, performance, and accuracy.

To maintain performance despite changing conditions, the PSoC 4000S device's SmartSense feature provides an auto-tuning capability that automatically sets parameters to maintain optimum sensitivity and performance. When the CapSense block is initialized, SmartSense recalculates parameters such as scan resolution, as well as settings for internal clocks and other key internal circuits. At the beginning of each scan, however, SmartSense can automatically update more dynamic parameters including noise-threshold and touch-threshold values. As a result, SmartSense can dynamically compensate for different noise environments and even for random noise spikes that cannot be anticipated during design.

In some cases, however, designers may still need to use manual tuning methods. For example, SmartSense supports designs with parasitic capacitance as high as 45 pF. Consequently, designs with very high parasitic capacitance may require manual tuning. Further, SmartSense only supports self-capacitance sensor designs, so mutual-capacitance sensor designs require manual tuning. In fact, Cypress recommends the use of manual tuning even in self-capacitance designs in situations where the application requires very tight control of specific parameter settings, such as sensor scan time.

Rapid development

With all its integrated functionality, a complex device such as the PSoC 4000S can require substantial effort for programming each on-chip block. To ease programming and configuration, Cypress provides its free PSoC Creator software environment. PSoC Creator is an integrated design environment (IDE) that helps mask the complexity of device hardware configuration details and associated software layers.

PSoC Creator is designed to work with Cypress PSoC 4 design kits that include an integrated bootloader or debugger. Consequently, developing with a PSoC device is as simple as connecting the development board to a system's USB port and selecting appropriate parameters. For example, developers can enable SmartSense auto-tuning simply by selecting it in on a PSoC Creator configuration screen (Figure 5).

Image of Cypress PSoC Creator IDE

Figure 5: The Cypress PSoC Creator IDE simplifies programming and development. Device configuration and setup of features such as SmartSense auto-tuning are reduced to a series of selections on screens dedicated to specific areas of device functionality. (Image source: Cypress Semiconductor)

The combination of PSoC 4000S hardware and the PSoC Creator IDE offer a significant advantage in implementing capacitive sensing designs. Yet, as noted earlier, issues such as parasitic capacitance, noise sources, and other detailed design considerations still prove a hurdle for development teams looking to develop a capacitive touch sensor solution. Cypress addresses the need for rapid development with its PSoC 4000S Prototyping Kit, which provides a complete capacitive touch hardware implementation and sample software. The kit combines the Cypress KitProg2 debugging board, button sensor board, a linear slider board, and a main board with the PSoC 4000S and the Cypress EZ-BLE PRoC device for Bluetooth low energy (BLE) communications.

Developers can quickly begin testing sensor applications simply by plugging the board into their USB port (Figure 6). Using PSoC Creator, the developer can select and compile a sample project; use the IDE's firmware programmer to program the PSoC 4000S device on the main board; and finally use the integrated debugger to explore runtime operation. The kit supports both self-capacitance and mutual-capacitance sensing on both the button and slider boards, and developers can use PSoC Creator to configure the kit to run sensors in either configuration.

Image of Cypress PSoC 4000S Prototyping Kit

Figure 6: The Cypress PSoC 4000S Prototyping Kit provides a unique snap-away design comprising USB-connected debug board, touch sensor board, linear slider board, and main board, which can be separated for development of custom capacitive sensor designs. (Image: Cypress Semiconductor)

Both PSoC Creator and the PSoC 4000S Prototyping Kit software suite are available for free download. While PSoC Creator is used to configure and program the kit's onboard PSoC 4000S device, the software package includes a comprehensive set of software libraries along with sample software illustrating key design patterns for capacitive touch applications.

For example, the main.c routine in the buttons and slider sample package demonstrates device initialization followed by continuous sensor sampling. Within this code, a switch statement sequentially conducts a sensor scan after an optional auto-tuner pass; waits for the scan to be completed; and then finally processes all enabled sensors (Listing 1). The Cypress library includes packages that implement the low-level software calls required for each phase in the sequence.

    DEVICE_STATE currentState = SENSOR_SCAN; 

    . . .

    /* Start CapSense block */


    . . .



         /* Switch between SENSOR_SCAN->WAIT_FOR_SCAN_COMPLETE->PROCESS_DATA states */



             case SENSOR_SCAN:

                   /* Initiate new scan only if the CapSense block is idle */

                 if(CapSense_NOT_BUSY == CapSense_IsBusy())


                     #if ENABLE_TUNER

                         /* Update CapSense parameters set via CapSense tuner before the

                            beginning of CapSense scan





                     /* Scan widget configured by CSDSetupWidget API */



                     /* Set next state to WAIT_FOR_SCAN_COMPLETE  */

                     currentState = WAIT_FOR_SCAN_COMPLETE;




             case WAIT_FOR_SCAN_COMPLETE:


                 /* Put the device to CPU Sleep until CapSense scanning is complete*/

                 if(CapSense_NOT_BUSY != CapSense_IsBusy())




                 /* If CapSense scanning is complete, process the CapSense data */



                     currentState = PROCESS_DATA;




             case PROCESS_DATA:


                 /* Process data on all the enabled widgets */



                 /* Controls LEDs Status based on the result of Widget processing. */


    . . .




Listing 1: Sample software from Cypress demonstrates use of the PSoC 4000S capacitive sensing capabilities. In this sample application, after the PSoC 4000S CapSense block is initialized, an endless loop sequentially performs sensor scans (CapSense_ScanAllWidgets), waits for scans to be completed, and then processes the results (CapSense_ProcessAllWidgets). (Code source: Cypress Semiconductor)

When they are ready to test their own sensor designs, developers can snap off the debugger board and both sensor boards to continue development with only the main board. The kit brings out headers for the connections between kit sensors and the PSoC 4000S GPIO pins, allowing easy extension to custom-designed sensor pads.

For developers looking to build on the kit design, the associated reference design provides complete hardware schematics and associated software. For example, the hardware reference design illustrates the use of a series of sensor pads for the linear slider (Figure 7). The accompanying software suite provides sample software that demonstrates a technique for enhancing the accuracy of finger-position estimation.

Diagram of Cypress PSoC 4000S Prototyping Kit reference design

Figure 7: In the Cypress PSoC 4000S Prototyping Kit reference design, a linear slider comprises an array of sensor pads laid out in a zigzag pattern to enhance resolution of finger-placement identification. The design includes a transmit electrode, enabling operation in mutual-capacitance mode, as well as self-capacitance mode. (Image source: Cypress Semiconductor)

The zigzag layout of a linear slider ensures that when a finger touches a particular point on the slider, the finger will also partially touch adjacent segments. The software kit uses this information in a low-level routine (capsense_CalcCentroid) that calculates the centroid of count values using the sensor (Si) exhibiting the maximum counts as well as the sensors (Si-1, Si+1) on either side of it (Listing 2). By interpolating finger position in this fashion, the software is able to generate a finger-placement solution at a higher resolution than what is possible simply by finding the sensor exhibiting the highest count value. The sample software application then turns on the LEDs, that sensor, and the sensors below it (S0,S1,…,Si-1,Si).

    . . .

        /* Si+1 - Si-1 */

        numerator = (uint32) capsense_centroid[capsense_POS_NEXT] -

                    (uint32) capsense_centroid[capsense_POS_PREV];


        /* Si+1 + Si + Si-1 */

        denominator = (int32) capsense_centroid[capsense_POS_PREV] +

                      (int32) capsense_centroid[capsense_POS] +

                      (int32) capsense_centroid[capsense_POS_NEXT];


        /* (numerator/denominator) + maximum */

        denominator = (((int32)(uint32)((uint32)numerator << 8u)/denominator) + (int32)(uint32)((uint32) maximum << 8u));

    . . .

        /* Round result and put it to uint8 */

         position = ((uint8) HI16((uint32)denominator + capsense_CENTROID_ROUND_VALUE));

         return (position);

Listing 2: The capsense_CalcCentroid routine extracts sensor counts from an array of count values for each sensor (capsense_centroid) for the previous, current, and next sensor in the linear array to return the result of the centroid calculation shown here. (Code source: Cypress Semiconductor)


Based on capacitive sensing techniques, touch-sensitive interfaces offer users an intuitive method for controlling devices ranging from wearables to washing machines. Along with its minimal power requirements, capacitive sensing offers reliability and extended lifespan that is difficult to achieve with mechanical buttons and switches. Yet, developers looking to implement robust sensing systems can easily find themselves delayed by design iterations required to resolve interdependent circuit design and physical layout characteristics in capacitive sensing systems. A comprehensive prototyping kit and reference design based on the Cypress Semiconductor PSoC 4000S offers a ready solution that is able to help developers rapidly deploy robust capacitive touch sensing designs for a wide range of applications.

Disclaimer: The opinions, beliefs, and viewpoints expressed by the various authors and/or forum participants on this website do not necessarily reflect the opinions, beliefs, and viewpoints of Digi-Key Electronics or official policies of Digi-Key Electronics.

About this publisher

Digi-Key's North American Editors