# PSoC™ 4 and PSoC™ 6 MCU CAPSENSE™ design guide

### Scope and purpose

The CAPSENSE design guide explains how to design capacitive touch sensing applications with the CAPSENSE feature in PSoC 4 and PSoC 6 MCU device families. The CAPSENSE feature offers unprecedented signal-to-noise ratio (SNR), best-in-class liquid tolerance, and a wide variety of sensors such as buttons, sliders, touchpads, and proximity sensors. This design guide explains the CAPSENSE operation, CAPSENSE design tools, performance tuning of the PSoC Creator and ModusToolbox CAPSENSE component and design considerations. This guide also introduces Fifth Generation CAPSENSE technology which has several advantages over the previous generation devices.

Different device families are available with CAPSENSE feature. If you have not chosen a particular device, or are new to capacitive sensing, see the Getting started with CAPSENSE design guide. It helps you understand the advantages of CAPSENSE over mechanical buttons, CAPSENSE technology fundamentals, and to select the right device for your application. It also directs you to the right documentation, kits, or tools to help with your design.

### Intended audience

This document is primarily intended for engineers who need to become familiar with the CAPSENSE design principles of PSoC 4 and PSoC 6 MCU devices.

## Introduction

### Overview

Capacitive touch sensors are user interface devices that use human body capacitance to detect the presence of a finger on or near a sensor.CAPSENSE solutions bring elegant, reliable, and easy-to-use capacitive touch sensing functionality to your product.

This design guide focuses on the CAPSENSE feature in the PSoC 4 and PSoC 6 MCU families of devices. These are true programmable embedded system-on-chip, integrating configurable analog and digital peripheral functions, memory, radio, and a microcontroller on a single chip. These devices are highly flexible and can implement many functions such as ADC, DAC, and Bluetooth® LE in addition to CAPSENSE, which accelerates time-to-market, integrates critical system functions, and reduces overall system cost.

This guide assumes that you are familiar with developing applications for PSoC 4 and PSoC 6 MCU using the PSoC Creator integrated design environment (IDE). If you are new to PSoC 4, see AN79953 - Getting started with PSoC 4 or AN92167 - Getting s tarted with PSoC 4 Bluetooth® LE. If you are new to PSoC 6 MCU, see AN221774 – Getting started with PSoC 6 MCU and AN210781 - Getting started with PSoC 6 MCU with Bluetooth® LE connectivity. If you are new to PSoC Creator, see the PSoC Creator home page.

If you are new to ModusToolbox, see ModusToolbox IDE quick start guide.

This design guide helps you understand:

### CAPSENSE™ features

CAPSENSE in PSoC 4 and PSoC 6 MCU has the following features:

• Supports self-capacitance (CSD) and mutual-capacitance (CSX) based touch sensing on all CAPSENSE-capable GPIO pins1
• Provides the best in Class SNR allowing high sensitivity that provides high range proximity sensing (up to a 30-cm proximity-sensing distance) and liquid-tolerant operation (see Liquid tolerance)
• High-performance sensing across a variety of overlay materials and varied thickness (see CAPSENSE fundamentals, Overlay material, and Overlay thickness)
• SmartSense auto-tuning technology
• Pseudo random sequence (PRS) clock source, supports spread spectrum and programmable resistance switches for lower electromagnetic interference (EMI)
• Low power consumption with as low as 1.71 V operation and as low as 150 nA current consumption in hibernate mode

The PSoC 4100S Max device introduces Fifth-Generation CAPSENSE technology (Ratiometric sensing technology) and has the following additional features when compared to older generations.

• Improved SNR: Fifth-Generation CAPSENSE technology (Ratiometric sensing technology) significantly improves noise performance compared to previous generation devices
• Improved refresh rate: The better sensitivity of multi sense converter (MSC) requires less time to get similar signal as in previous generation therefore is able to achieve higher refresh rate. The two independent MSC blocks which can scan the sensors in parallel improve the refresh rate further especially in use case where large numbers of sensors to be scanned
• Improved CPU bandwidth: Scan supported in both CPU mode and DMA mode. CPU mode is conventional interrupt driven mode, while DMA mode is capable of autonomous scanning which reduces the CPU bandwidth requirement to 18% compared to previous generation
• Improved noise immunity: Rail to rail swing is used as sense voltage, this provides maximum sense voltage and provides better immunity. In Fifth-Generation CAPSENSE technology full wave differential sensing is used for self-capacitance sensing and this cancels out noise induced from external environment to the sensor routings. This sensing technology is also better immune to power supply (Vdd) noise
1 To achieve the best CAPSENSE performance, follow the recommendations in Sensor pin selection section

### PSoC™ 4 and PSoC™ 6 MCU CAPSENSE™ Plus features

You can create PSoC 4 CAPSENSE Plus applications that feature capacitive touch sensing and additional system functionality. The key features of these devices, in addition to CAPSENSE are:

• Arm®Cortex®-M0/M0+ CPU with single cycle multiply delivering up to 43 DMIPS at 48 MHz
• 1.71 V – 5.5 V operation over –40 to 85°C ambient
• Up to 128 KB of flash (CM0+ has > 2X code density over 8-bit solutions)
• Up to 16 KB of SRAM
• Up to 94 programmable GPIOs
• Independent center-aligned PWMs with complementary dead-band programmable outputs, synchronized ADC operation (ability to trigger the ADC at a customer-specifiable time in the PWM cycle), and synchronous refresh (ability to synchronize PWM duty cycle changes across all PWMs to avoid anomalous waveforms)
• Comparator-based triggering of PWM Kill signals (to terminate motor-driving when an over-current condition is detected)
• 12-bit 1 Msps ADC including sample-and-hold (S&H) capability with zero-overhead sequencing allowing the entire ADC bandwidth to be used for signal conversion and none used for sequencer overhead
• Opamps with comparator mode and SAR input buffering capability
• Segment LCD direct drive that supports up to four commons
• SPI/UART/I2C serial communication channels
• Bluetooth® LE communication compliant with version 4.0 and multiple features of version 4.1
• Programmable logic blocks, each having eight macrocells and a cascadable data path, called universal digital blocks (UDBs) for efficient implementation of programmable peripherals (such as I2S)
• Controller area network (CAN)
• Fully-supported PSoC Creator design entry, development, and debug environment providing:
• Design entry and build (comprehending analog routing)
• Components for all fixed-function peripherals and common programmable peripherals
• Documentation and training modules
• Support for porting builds to MDK Arm® environment (previously known as RealView) and others
• Support for Eclipse integrated development environment (IDE) for ModusToolbox

The main features of PSoC 6 MCU device, in addition to CAPSENSE are:

• Single CPU devices (Arm® Cortex® -M4), dual CPU devices (Arm® Cortex®-M4 and Cortex®-M0+). Support for inter-processor communication in hardware
• 1.71 V - 3.6 V device operating voltage with user selectable core logic operation at either 1.1 V or 0.9 V
• Up to 2 MB of flash memory and up to 1 MB of SRAM
• Up to 78 GPIOs that can be used for analog, digital, CAPSENSE, or segment LCD functions
• Programmable analog blocks: Two opamps, configurable PGAs, comparators, 12-bit 1 Msps SAR ADC, 12 -bit voltage mode DAC
• Programmable digital blocks, communication interfaces
• 12 UDBs, 32 TCPWMs configurable as 16-bit/32-bit timer, counter, PWM, or quadrature decoder
• Up to 13 serial communication block (SCB) configurable as I2C, SPI, or UART interfaces. See the Device datasheet for more details
• Audio subsystem with one I2S interface and two PDM channels
• SMIF interface with support for execute-in-place from external quad SPI flash memory and on-the-fly encryption and decryption
• Bluetooth® Smart connectivity with Bluetooth® LE 5.0 (applicable only to PSoC 6 MCU with Bluetooth® LE family of devices)

See AN64846 - Getting started with CAPSENSE to select an appropriate CAPSENSE device based on your requirements.

### CAPSENSE™ design flow

Figure 1. CAPSENSE product design flow illustrates the product design cycle with capacitive sensing; the information in this guide is highlighted in green. provides links to the supporting documents for each of the numbered tasks in Figure 1. CAPSENSE product design flow.

Table 1. Supporting documentation
Steps in flowchart Supporting documentation
Name Chapter
1. Understanding CAPSENSE

CAPSENSE design guide (This document)

Getting started with CAPSENSE

2. Specify requirements Getting started with CAPSENSE
3. Feasibility study

PSoC 4 datasheet

PSoC 4 Bluetooth® LE datasheet

PSoC 6 MCU datasheet

AN64846 – Getting started with CAPSENSE design guide

AN79953 – Getting started with PSoC 4

AN91267 – Getting started with PSoC 4 Bluetooth® LE

AN221774 – Getting started with PSoC 6 MCU

4. Schematic design CAPSENSE design guide (This document) Design considerations
5. Layout design CAPSENSE design guide (This document) Design considerations
6. Component configuration PSoc CAPSENSE Component datasheet/middleware document
CAPSENSE design guide (This document) CAPSENSE performance tuning
7. Performance tuning PSoc CAPSENSE design guide (This document) CAPSENSE performance tuning
8. Firmware design PSoC Component datasheet/middleware document

PSoC Creator

Example projects

See the ModusToolbox related documents:

ModusToolbox release notes

ModusToolbox user guide

ModusToolbox CAPSENSE configurator guide

ModusToolbox CAPSENSE tuner guide

PSoC Creator to ModusToolbox porting guide

9. Programming PSoC

PSoC Creator user guide for in-IDE programming

10. Prototype
11. Design validation CAPSENSE design guide (This document) CAPSENSE performance tuning
12. Production
1 To achieve the best CAPSENSE performance, follow the recommendations in Sensor pin selection section

## CAPSENSE™ technology

Capacitive touch sensing technology measures changes in capacitance between a plate (the sensor) and its environment to detect the presence of a finger on or near a touch surface.

### CAPSENSE™ fundamentals

A typical CAPSENSE sensor consists of a copper pad of proper shape and size etched on the surface of a PCB. A non-conductive overlay serves as the touch surface for the button, as Figure 2. Capacitive touch sensor shows.

PCB traces and vias connect the sensor pads to PSoC GPIOs that are configured as CAPSENSE sensor pins. As Figure 3. PSoC device, sensors, and external capacitors shows, the self-capacitance of each electrode is modeled as CSX and the mutual capacitance between electrodes is modeled as CMX. CAPSENSE circuitry internal to the PSoC converts these capacitance values into equivalent digital counts (see PSoC 4 and PSoC 6 MCU CAPSENSE for details). These digital counts are then processed by the CPU to detect touches.

CAPSENSE also requires external capacitor CMOD or CINT for self-capacitance sensing and mutual-capacitance sensing. For third- and fourth-generation CAPSENSE architecture, a single CMOD capacitor is required for self-capacitance sensing and CINTA and CINTB capacitors for mutual-capacitance sensing. If shield electrode is implemented for liquid tolerance, or for large proximity sensing distance, an additional CTANK capacitor may be required. For Fifth-Generation CAPSENSE architecture, two CMOD capacitors are required for both self-capacitance and mutual-capacitance sensing for each channel. These external capacitors are connected between a dedicated GPIO pin and ground. list the recommended values of the external capacitors.

The capacitance of the sensor in the absence of a touch is called the parasitic capacitance, CP. CP results from the electric field between the sensor (including the sensor pad, traces, and vias) and other conductors in the system such as the ground planes, traces, and any metal in the product’s chassis or enclosure. The GPIO and internal capacitances of PSoC also contribute to the parasitic capacitance. However, these internal capacitances are typically very small compared to the sensor capacitance.

#### Self-capacitance sensing

Figure 4. Parasitic capacitance shows how a GPIO pin is connected to a sensor pad by traces and vias for self-capacitance sensing. Typically, a ground (GND) hatch surrounds the sensor pad to isolate it from other sensors and traces. Although Figure 4. Parasitic capacitance shows some field lines around the sensor pad, the actual electric field distribution is very complex.

When a finger is present on the overlay, the conductive nature and large mass of the human body forms a grounded, conductive plane parallel to the sensor pad, as Figure 5. Finger capacitance shows.

This arrangement forms a parallel plate capacitor. The capacitance between the sensor pad and the finger is shown in Equation 1.

Where:

ε0 = Free space permittivity

εr = Relative permittivity of overlay

A = Area of finger and sensor pad overlap

d = Thickness of the overlay

CF = Finger capacitance.

CP and CF are parallel to each other because both represent the capacitance between the sensor pin and ground. Therefore, the total capacitance CS of the sensor, when the finger is present on the sensor, is the sum of CP and CF.

In the absence of touch, CS is equal to CP.

PSoC converts the capacitance CS into equivalent digital counts called raw counts. Because a finger touch increases the total capacitance of the sensor pin, an increase in the raw counts indicates a finger touch. Refer to the CSD specification in Device datasheet/Component datasheet/middleware document document to learn about the supported CP range for a given device with which the recommended SNR can be achieved.

#### Mutual-capacitance sensing

Figure 8. Mutual-capacitance sensing shows the button sensor layout for mutual-capacitance sensing. Mutual-capacitance sensing measures the capacitance between two electrodes, transmit (Tx) electrode and receive (Rx) electrode.

In a mutual-capacitance sensing system, a digital voltage signal switching between VDDIO 2 or VDDD3 (if VDDIO is not supported by the device) and GND is applied to the Tx pin and the amount of charge received on the Rx pin is measured. The amount of charge received on the Rx electrode is directly proportional to the mutual-capacitance (CM) between the two electrodes.

When a finger is placed between the Tx and Rx electrodes, the mutual-capacitance decreases to C1 M , as shown in Figure 9. Mutual-capacitance with finger touch. Because of the reduction in the mutual-capacitance, the charge received on the Rx electrode also decreases. The CAPSENSE system measures the amount of charge received on the Rx electrode to detect a touch/no touch condition.

3 VDDD is the device power supply for digital section.
3 VDDD is the device power supply for digital section.

### Capacitive touch sensing method

PSoC uses patented capacitive touch-sensing method CAPSENSE sigma delta (CSD) for self-capacitance sensing and CAPSENSE crosspoint (CSX) for mutual-capacitance scanning. The CSD and CSX touch sensing methods provide the industry’s best-in-class Signal-to-noise ratio (SNR). These sensing methods are a combination of hardware and firmware techniques.

#### CAPSENSE™ sigma delta (CSD)

Figure 11. Simplified diagram of CSD method shows a simplified block diagram of the CSD method.

In CSD, each GPIO has a switched-capacitance circuit that converts Cs into an equivalent current. An analog MUX (AMUX) selects one of the sensor currents and feeds it into the current to digital converter. The current to digital converter is similar to a delta sigma ADC. The output count of the current to digital converter, known as raw count, is a digital value that is proportional to the self-capacitance between the electrodes.

Where,

GCSD = Capacitance to digital conversion gain of CSD

CS = Self-capacitance of the electrode

Figure 14. Raw count versus time illustrates a plot of raw count over time. When a finger touches the sensor, the CS increases from CP to CP + CF, and the raw count increases. By comparing the change in raw count to a predetermined threshold, logic in firmware decides whether the sensor is active (finger is present).

#### CAPSENSE™ crosspoint (CSX)

Figure 12. Simplified diagram of CAPSENSE crosspoint (CSX) method shows the simplified block diagram of the CSX method.

With CSX, a voltage on the Tx electrode couples charge on to the RX electrode. This charge is proportional to the mutual capacitance between the Tx and Rx electrodes. An analog MUX then selects one of the Rx electrodes and feeds it into the current to digital converter.

The output count of the current to digital converter, , is a digital value that is proportional to the mutual-capacitance between the Rx and Tx electrodes as shown in Figure 13. Raw count and sensor capacitance relationship in CSX.

Where,

GC SX = Capacitance to digital conversion gain of mutual capacitance method

CM = Mutual-capacitance between two electrodes

Figure 14. Raw count versus time illustrates a plot of raw count over time. When a finger touches the sensor, CM decreases from CM to C1 M (see Figure 9. Mutual-capacitance with finger touch) hence the counter output decreases. The firmware normalizes the raw count such that the raw counts go high when CM decreases. This maintains the same visual representation of raw count between CSD and CSX methods. By comparing the change in raw count to a predetermined threshold, logic in firmware decides whether the sensor is active (finger is present). The normalized inverted raw count is computed using Figure 58. Formula to determine rawcountComponent.

For an in-depth discussion of the PSoC 4 and PSoC 6 CAPSENSE CSD and CSX blocks, see chapter PSoC 4 and PSoC 6 MCU CAPSENSE.

### Signal-to-noise ratio (SNR)

In practice, the raw counts vary due to inherent noise in the system.CAPSENSE noise is the peak-to-peak variation in raw counts in the absence of a touch, as Figure 15. SNR shows.

A well-tuned CAPSENSE system reliably discriminates between the ON and OFF states of the sensors. To achieve good performance, the CAPSENSE signal must be significantly larger than the CAPSENSE noise. SNR is defined as the ratio of CAPSENSE signal to CAPSENSE noise is the most important performance parameter of a CAPSENSE sensor.

In this example, the average level of raw count in the absence of a touch is 5925 counts. When a finger is placed on the sensor, the average raw count increases to 6060 counts, which means the signal is 6060– 5925 = 135 counts. The minimum value of the raw count in the OFF state is 5912 and the maximum value is 5938 counts. Therefore, the CAPSENSE noise is 5938 – 5912 = 26 counts. This results in an SNR of 135/26 = 5.2.

The minimum SNR recommended for a CAPSENSE sensor is 5. This 5:1 ratio comes from best practice threshold settings, which enable enough margin between signal and noise in order to provide reliable ON/OFF operation.

### CAPSENSE™ widgets

CAPSENSE widgets consist of one or more CAPSENSE sensors, which as a unit represent a certain type of user interface. CAPSENSE widgets are broadly classified into four categories – buttons (zero-dimensional), sliders (one-dimensional), touchpads/trackpads (two-dimensional), and proximity sensors (three-dimensional). Figure 16. Several types of widgets shows button, slider, and proximity sensor widgets. This section explains the basic concepts of different CAPSENSE widgets. For a detailed explanation of sensor construction, see Sensor construction.

#### Buttons (zero-dimensional)

CAPSENSE buttons replace mechanical buttons in a wide variety of applications such as home appliances, medical devices, white goods, lighting controls, and many other products. It is the simplest type of CAPSENSE widget, consisting of a single sensor. A CAPSENSE button gives one of two possible output states: active (finger is present) or inactive (finger is not present). These two states are also called ON and OFF states, respectively.

For the self-capacitance (CSD) sensing method, a simple CAPSENSE button consists of a circular copper pad connected to a PSoC GPIO with a PCB trace. The CAPSENSE button is surrounded by grounded copper hatch that isolates it from other buttons and traces. A circular gap separates the button pad and the ground hatch. Each button requires one PSoC GPIO. These buttons can be constructed using any conductive material on a non-conductive substrate; for example, indium tin oxide on a glass substrate, or silver ink on a non-conductive film. Even metallic springs can be used as button sensors; see Sensor construction for more details.

For the mutual-capacitance (CSX) sensing method, each button requires one GPIO pin configured as Tx electrode and one GPIO pin configured as Rx electrode. The Tx can be shared across multiple buttons, as shown in Figure 18. Simple CAPSENSE buttons for mutual-capacitance sensing method.

If the application requires many buttons (for example in a calculator keypad or a QWERTY keyboard), you can arrange the CAPSENSE buttons in a matrix, as Figure 19. Matrix buttons based on CSD shows. This allows a design to have multiple buttons per GPIO. For example, the 16-button design in Figure 19. Matrix buttons based on CSD requires only eight GPIOs.

A matrix button design has two groups of capacitive sensors: row sensors and column sensors. The matrix button architecture can be used for both self-capacitance (CSD) and mutual-capacitance (CSX) methods.

In CSD mode, each button consists of a row sensor and a column sensor, as Figure 19. Matrix buttons based on CSD shows. When a button is touched, both row and column sensors of that button become active. The CSD-based matrix button should be used only if the user is expected to touch one button at a time. If the user touches more than one diagonally opposite buttons, the finger location cannot be resolved as Figure 20. Ghost effect in matrix button based on CSD shows. This effect is called as ghost effect, which is considered an invalid condition.

Mutual-capacitance is the recommended sensing method for matrix buttons because this method is not affected from the ghost touch phenomena and provides better SNR for high Cp sensors. This is because it senses mutual-capacitance formed at each intersection rather than sensing rows and columns as shown in Figure 21. Matrix button based on CSX. Applications that require simultaneous sensing of multiple buttons, such as a keyboard with Shift, Ctrl, and Alt keys can use CSX sensing method or you should design the Shift, Ctrl, and Alt keys as individual CSD buttons.

Note: Scanning a matrix keypad using CSX sensing method may require a longer overall scan time than the CSD sensing method. This is because the CSD sensing method scans rows and columns as sensors, while the CSX sensing method scans each intersection as a sensor.

#### Sliders (one-dimensional)

Sliders are used when the required input is in the form of a gradual increment or decrement. Examples include lighting control (dimmer), volume control, graphic equalizer, and speed control. Currently, the CAPSENSE Component in PSoC Creator and ModusToolbox supports only self-capacitance-based sliders. Mutual capacitance-based sliders will be supported in future version of component.

A slider consists of a one-dimensional array of capacitive sensors called segments, which are placed adjacent to one another. Touching one segment also results in partial activation of adjacent segments. The firmware processes the raw counts from the touched segment and the nearby segments to calculate the position of the geometric center of the finger touch, which is known as the centroid position.

The actual resolution of the calculated centroid position is much higher than the number of segments in a slider. For example, a slider with five segments can resolve at least 100 physical finger positions. This high resolution gives smooth transitions of the centroid position as the finger glides across a slider.

In a linear slider, the segments are arranged inline, as Figure 22. Linear slider shows. Each slider segment connects to a PSoC GPIO. A zigzag pattern (double chevron) is recommended for slider segments. This layout ensures that when a segment is touched, the adjacent segments are also partially touched, which aids estimation of the centroid position.

A touchpad (also known as trackpad) has two linear sliders arranged in an X and Y pattern, enabling it to locate a finger’s position in both X and Y dimensions. Figure 24. Touchpad sensor arrangement shows a typical arrangement of a touchpad sensor. Similar to the matrix buttons, touchpads can also be sensed using either CSD or CSX sensing method.

CSD-based touchpads suffer from ghost touches, so it supports only single-point touch applications.

CSX touchpads can support multi-point touch applications, but these may need more scanning time compared to CSD touchpad because this method scans each intersection rather than rows and columns.

#### Proximity (three-dimensional)

Proximity sensors detect the presence of a hand in the three-dimensional space around the sensor. However, the actual output of the proximity sensor is an ON/OFF state similar to a CAPSENSE button. Proximity sensing can detect a hand at a distance of several centimeters to tens of centimeters depending on the sensor construction. Self capacitance is the recommended method of sensing for a proximity application.

Proximity sensing requires electric fields that are projected to much larger distances than buttons and sliders. This demands a large sensor area. However, a large sensor area also results in a large parasitic capacitance CP, and detection becomes more difficult. This requires a sensor with high electric field strength at large distances while also having a small area. Figure 25. Proximity sensor shows a proximity sensor using a trace with a thickness of 2-3 mm surrounding the other sensors.

You can also implement a proximity sensor by ganging other sensors together. This is accomplished by combining multiple sensor pads into one large sensor using firmware. The disadvantage of this method is high parasitic capacitance. See the Component datasheet/middleware document for details on maximum parasitic capacitance supported by a given device.

See AN92239 proximity sensing with CAPSENSE and the proximity sensing section in Getting started with CAPSENSE design guide to learn more about proximity sensors.

### Liquid tolerance

Capacitive sensing is used in a variety of applications such as home appliances, automotive, and industrial applications. These applications require robust capacitive-sensing operation even in the presence of mist, moisture, water, ice, humidity, or other liquids. In a capacitive-sensing application design, false sensing of touch or proximity detection may happen due to the presence of a film of liquid or liquid droplets on the sensor surface, due to the conductive nature of some liquids. CSD sensing method can compensate for variation in raw count due to these causes and provide a robust, reliable, capacitive sensing application operation.

In summary, if your application requires tolerance to liquid droplets, implement a Driven shield signal and shield electrode. If your application requires tolerance to streaming liquids along with liquid droplets, implement a Driven shield signal and shield electrode and a Guard sensor as shown in Figure 27. Shield electrode (SH) and guard sensor (GUARD) connected to CAPSENSE controller. Follow the schematic and layout guidelines explained in the Layout guidelines for liquid tolerance section to construct the shield electrode and guard sensor respectively.

#### Liquid tolerance for self capacitance sensing

##### Effect of liquid droplets and liquid stream on a self-capacitance sensor

To understand the effect of liquids on a CAPSENSE sensor, consider a CAPSENSE system in which the hatch fill around the sensor is connected to ground, as Figure 28. Typical CAPSENSE system layout(a) shows. The hatch fill when connected to a GND improves the noise immunity of the sensor. Parasitic capacitance of the sensor is denoted as CP in Figure 28. Typical CAPSENSE system layout(b).

As shown in Figure 29. Capacitance added by liquid droplet when the Hatch Fill is connected to GND, when a liquid droplet falls on the sensor surface, due to its conductive nature it provides a strong coupling path for the electric field lines to return to ground; this adds a capacitance CLD in parallel to CP. This added capacitance draws an additional charge from the AMUX bus as explained in GPIO cell capacitance to current converter resulting in an increase in the sensor raw count. In some cases (such as salty water or water containing minerals), the increase in raw count when a liquid droplet falls on the sensor surface may be equal to the increase in raw count due to a finger touch, as Figure 29. Capacitance added by liquid droplet when the Hatch Fill is connected to GND shows. In such a situation, sensor false triggers might occur.

CP = Sensor parasitic capacitance

CLD = Capacitance added by the liquid droplet

To nullify the effect of capacitance added by the liquid droplet to the CAPSENSE circuitry, you should drive the hatch fill around the sensor with the driven-shield signal.

As Figure 31. Capacitance added by liquid droplet droplet when the hatch fill around the sensor is connected to shield shows, when the hatch fill around the sensor is connected to the driven-shield signal and when a liquid droplet falls on the touch interface, the voltage on both sides of the liquid droplet remains at the same potential. Because of this, the capacitance, CLD, added by the liquid droplet does not draw any additional charge from the AMUX bus and hence the effect of capacitance CLD is nullified. Therefore, the increase in raw count when a water droplet falls on the sensor will be very small, as Figure 32. Effect of liquid droplet when the hatch fill around the sensor is connected to the driven-shield shows.

CS = Sensor parasitic capacitance

CSH = Capacitance between the sensor and the hatch fill

CHG = Capacitance between the hatch fill and ground

CLD = Capacitance added by the liquid droplet

Figure 30. Effect of liquid droplet when the Hatch Fill around the sensor is connected to GND shows how a sensor may false trigger in presence of a liquid, if hatch fill is connected to ground. Note however, that the same is not true for all cases. For example, spring sensors, which are inherently more liquid tolerant than sensors etched on PCB surface. As Figure 33. Capacitance added by liquid droplet in spring sensor shows, due to the large airgap between the liquid drop and the hatch fill, the capacitance CLD between the liquid drop and grounded hatch pattern on the PCB would be very low so as not to cause any false triggers. If required, the hatched pattern on the PCB can still be connected to a driven shield electrode to further nullify the effect of CLD and have an improved liquid tolerance.

##### Driven shield signal and shield electrode

The driven-shield signal is a buffered version of the sensor-switching signal, as Figure 34. Driven shield signal shows. The driven-shield signal has the same amplitude, frequency, and phase as that of sensor switching signal. When the hatch fill around the sensor is connected to the driven shield signal, it is referred as shield electrode.

• To implement liquid-tolerant CAPSENSE designs: Shield electrode helps in making CAPSENSE designs liquid-tolerant as explained above
• To improve proximity sensing distance in presence of floating or grounded conductive objects: A shield electrode, when placed between the proximity sensor and a floating or a grounded conductive object, reduces the effect of these objects on the proximity-sensing distance and helps in achieving large proximity-sensing distance. See the “Proximity Sensing” section in the Getting started with CAPSENSE design guide for more details
• To reduce the parasitic capacitance of the sensor: When a CAPSENSE sensor has a long trace, the CP of the sensor will be very high because of the increased coupling of sensor electric field lines from the sensor trace to the surrounding ground. By implementing a shield electrode, the coupling of electric field lines to ground is reduced, which results in reducing the CP of the sensor

See Layout guidelines for shield electrode for layout guidelines of shield electrode.

##### Guard sensor

When a continuous liquid stream is present on the sensor surface, the liquid stream adds a large capacitance (CST) to the CAPSENSE sensor. This capacitance may be several times larger than CLD. Because of this, the effect of the shield electrode is completely masked, and the sensor raw counts will be same as or even higher than a finger touch. In such situations, a guard sensor is useful to prevent sensor false triggers.

A guard sensor is a copper trace that surrounds all the sensors on the PCB, as Figure 35. Measurement with a liquid stream shows. A guard sensor is similar to a button sensor and is used to detect the presence of streaming liquids. When a guard sensor is triggered, the firmware should disable the scanning of all other sensors except the guard sensor to prevent sensor false triggers.

Note: The sensors are not scanned, or the sensor status is ignored when the guard sensor is triggered; therefore, touch cannot be detected when there is a liquid stream on the touch surface.

See Layout guidelines for guard sensor for PCB layout guidelines for implementing a guard sensor.

If there is no space on the PCB for implementing a guard sensor, the guard sensor functionality can be implemented in the firmware. For example, you can use the ON/OFF status of different sensors to detect a liquid stream depending on the use case, such as follows:

• When there is a liquid stream, more than one button sensor will be active at a time. If your design does not require multi-touch sensing, you can detect this and ignore the sensor status of all the button sensors to prevent false triggering
• In a slider, if the slider segments which are turned ON are not adjacent segments, you can reset the slider segments status or ignore the slider centroid value that is calculated
• Likewise, you could create your own custom algorithm to detect the presence of streaming liquids and ignore the sensor status during the time a liquid is present on the touch surface
Note: The sensors are not scanned, or the sensor status is ignored when the guard sensor is triggered; therefore, touch cannot be detected when there is a liquid stream on the touch surface

#### Liquid tolerance for mutual-capacitance sensing

##### Effect of liquid droplets and liquid stream on a mutual-capacitance sensor

Mutual-capacitance buttons often have a grounded hatch fill around the sensors for improved noise immunity. If a liquid droplet falls over the sensor while covering some part of the grounded hatch, the mutual-capacitance decreases similar to the effect of placing a finger on the sensor. This decrease in mutual-capacitance causes an increase in raw count as explained in CAPSENSE CSX sensing method (third- and fourth- generation) in and as shown in the Figure 36. Effect of liquid droplet on CSX sensor when the Hatch Fill around the sensor is connected to ground. The amount of increase in the raw count depends on the size and characteristics of the liquid drop.

However, mutual-capacitance increases if the liquid droplet covers just the Tx and Rx electrode and does not spread over the grounded hatch. This causes a decrease in raw count as shown in Figure 36. Effect of liquid droplet on CSX sensor when the Hatch Fill around the sensor is connected to ground. This decrease in raw count may cause the baseline reset due to Low baseline reset. Once the liquid drop is removed, the raw count would rise while the baseline may remain at the lower value, resulting in a difference signal which may cause the sensor to false trigger.

##### Using self-capacitance sensing for liquid tolerance of mutual-capacitance sensors

CAPSENSE senses the self-capacitance of Tx and Rx nodes of a mutual-capacitance sensor. This ability of scanning the sensor using both CSD and CSX modes could be used to avoid false triggers due to the presence of liquid drops on a mutual capacitance sensor. See the code example PSoC 4 hybrid sensing using CAPSENSE to understand how to sense a mutual-capacitance button with both CSD as well as CSX sensing method.

To achieve liquid tolerance, you need to scan the Rx electrode of the sensor with the CSD sense method. While scanning the Rx electrode as a CSD sensor, ensure that you enable the shield electrode, and connect the Tx pin of the mutual-capacitance sensor to the driven shield signal. You can use the low-level API function CapSense_SetPinState() to connect the Tx pin of the mutual-capacitance sensor to the shield electrode before calling the CapSense_ScanAllWidgets() API function that scans the Rx electrode as a CSD sensor as shown below:

CapSense_SetPinState(CapSense_BUTTON1_WDGT_ID,CapSense_BUTTON1_TX0_ID,CapSense_SHIELD);
CapSense_ScanAllWidgets();

From sections 2.5.1 and 2.5.2 you understood the effect of liquid drop on the CSD and CSX button respectively. By utilizing the difference in their response to the liquid drop, you can create a firmware logic to achieve a liquid-tolerant mutual-capacitance sensor. The effect of presence of the liquid drop on the CSD and CSX scan results is summarized in Figure 37. Effect of water drop on the CSX sensor pattern scanned with CSD and CSX methods.

Where Figure 37. Effect of water drop on the CSX sensor pattern scanned with CSD and CSX methods shows the effect of the water drop on the CSX sensor pattern surrounded by hatch fill when scanned using this method. The regions in Figure 37. Effect of water drop on the CSX sensor pattern scanned with CSD and CSX methods represent the following:

1. Finger touch
2. Liquid droplet on the Tx line and grounded shield hatch
3. Liquid drop present on the Tx and Rx electrodes only
4. Finger touch when a liquid drop is on the Tx and Rx electrodes only
5. Liquid drop removed from the Tx and Rx electrodes

The changes in raw count as shown in Figure 37. Effect of water drop on the CSX sensor pattern scanned with CSD and CSX methods can be used in the firmware to reset the baseline of the CSX sensor to nullify the effect of liquid drops. The button status should be ON state for Region 1, 4, and OFF state in other regions; additionally, the baseline of the CSX button must be re-initialized in Region 3 and Region 5. The baseline of the sensor could be reset by using the CapSense_InitializeWidgetBaseline() API function as shown below:

CapSense_InitializeWidgetBaseline(CapSense_CSX_BUTTON_WDGT_ID);

See the Component datasheet/middleware document or more details on using this API; see Selecting CAPSENSE software parameters to learn about the baseline of the sensor.

#### Effect of liquid properties on liquid-tolerance performance

In certain applications, the CAPSENSE system has to work in the presence of a variety of liquids such as soap water, sea water, and mineral water. In such applications, it is always recommended to tune the CAPSENSE parameters for sensors by considering the worst-case signal due to liquid droplets. To simulate the worst-case conditions, it is recommended that you test the liquid-tolerance performance of the sensors with salty water by dissolving 40 grams of cooking salt (NaCl) in one liter of water. Tests were done using soapy water; the results show that the effect of soapy water is similar to the effect of salty water. Therefore, if the tuning is done to reject salty water, the CAPSENSE system will work even in the presence of soapy water.

In applications such as induction cooktops, there are chances of hot water spilling on to the CAPSENSE touch surface. To determine the impact of the temperature of a liquid droplet on CAPSENSE performance, droplets of water at different temperatures were poured on a sensor and the corresponding change in raw counts was monitored. Experiment shows that the effect of hot liquid droplets is same as that of the liquid at room temperature as Figure 38. Raw count variation versus water temperature shows. This is because the hot liquid droplet cools down immediately to room temperature when it falls on the touch surface. If hot water continuously falls on the sensor and the temperature of the overlay rises because of the hot water, the increase in raw count due to the increase in temperature is compensated by the Baseline update algorithm, thereby preventing any false triggering of the sensors.

3 VDDD is the device power supply for digital section.

## PSoC™ 4 and PSoC™ 6 MCU CAPSENSE™

This chapter explains how CAPSENSE CSD and CSX (Third, Fourth, and Fifth generations) is implemented in the PSoC 4 and PSoC 6 MCU. See Capacitive touch sensing method to understand the basic principles of CAPSENSE. A basic knowledge of the PSoC device architecture is a prerequisite for this chapter. If you are new to PSoC 4, see AN79953 - Getting started with PSoC 4 or AN91267 - Getting started with PSoC 4 Bluetooth® LE; for PSoC 6 MCU, see AN221774 - Getting started with PSoC 6 MCU.

You can skip this chapter if you are using the automatic tuning feature (SmartSense) of the Component. See the CAPSENSE performance tuning chapter for details.

The PSoC 4 family of devices has three different CAPSENSE architectures. explains the differences between the Third, Fifth-Generation CAPSENSE architecture.

### CAPSENSE™ generations in PSoC™ 4 and PSoC™ 6

lists the main differences in the CAPSENSE architecture.

Table 2. Comparison of CAPSENSE architecture for CSD and CSX
Feature Third-generation CAPSENSE Fourth-generation CAPSENSE Fifth-generation CAPSENSE Improvement impact Conditions
SNR 5:1 6.5:1 48:1 Higher SNR implies better sensitivity, that is ability to sense smaller signal.

VDD = 5 V;

No firmware filter;

Cp ~= 33 pF;

Cf = 0.1 pF

Sensing mode Self-cap and Mutual-cap modes Self-cap, Mutual-cap modes and ADC modes Self-cap and Mutual-cap modes
Sensor capacitance parasitic range 5 pF – 45 pF 5 pF – 200 pF 2 pF – 200 pF Greater Cp range implies higher flexibility in PCB layout routing and ability to sense with very short/long sensor traces, and for different PCB materials (for example: FFC and so on).
Typical sense signal needed 100 fF 100 fF

15 fF for CSD-RM

10 fF for CSX-RM

Smaller sense signal required, implying support for thicker overlays, higher proximity range, smaller sensor size and so on.

VDD = 5 V;

No firmware filter;

Cp ~= 33 pF;

SNR = 5:1;

Noise floor (pk-pk)

500 aF for CSD-RM

100 aF for CSX-RM

Higher SNR or lower noise floor implies ability to sense smaller signal.

VDD - 5 V;

Cp ~= 33 pF;

CM = 5 pF

Overlay thickness supported Up to 5 mm Up to 5 mm Upto 18 mm Supports designs with thicker overlay.

10 mm CSD button;

Acrylic overlay;

SNR = 5:1;

Cp ~= 22 pF;

Refresh rate 22 Hz 242 Hz Faster refresh rate enables fast gestures and taps detections on applications such as large trackpad and long sliders or large number of button sensors with single device, and so on.

Acrylic overlay 3 mm thickness;

SNR = 10:1;

Finger Size = 8 mm;
CPU bandwidth requirement Completely CPU driven. CPU is required for initialization and sequencing the sensors. 40% Sequencer 4 takes care of initialization, configuration and scanning of sensors. CPU needed for sequencing through each sensor.

7%

Completely autonomous.

Reduced CPU usage for sensing, frees CPU to perform other peripheral operations and act as a central controller in an application.

Scan clock = 1 MHz;

No of sub-conversions = 70;

Refresh rate = 100 Hz;
Emission control options. PRS PRS, SSC PRS, SSC
Noise immunity Sense Voltage (Vref) 1.2 V 1.2 V-2.8 V. Rail to Rail Higher the sense voltage, higher the noise immunity.
Differential Sensing Mutual-Cap sensing Mutual-Cap sensing Mutual-Cap and Self-Cap sensing Differential sensing cancels out noise induced from external environment through CMOD.
VDD noise impact Yes Yes No VDD noise have minimal affect on fifth generation CAPSENSE operation.
Sense clock frequency Self-Cap 45 kHz – 6 MHz

45 kHz – 6 MHz

45 kHz – 6 MHz

Higher sense clock frequency means faster scan for low Cp sensors. This provides ability to support faster taps or gestures, or for a given refresh rate, ability to implement multiple firmware filters for better immunity.
Mutual-Cap 45 kHz - 300 kHz 45 kHz - 3 MHz 45 kHz – 6 MHz
Multi-channel support No No Yes Provides ‘n’ times increased speed of scanning for the same number of sensors, if ‘n’channels are used.
Shield Cp -- -- 1.2 nF
Device family

PSoC 4100/4200

PSoC 4100 M/4200 M

PSoC 4100 L/4200 L

PSoC 4100 BL/4200 BL

PSoC 4000

PSoC 4000S

PSoC 4100S

PSoC 4100S Plus

PSoC 6

PSoC 4100S Max
4 The hardware state machine is a logic which controls the CAPSENSE block and sensor scanning.

### CAPSENSE™ CSD sensing method (third and fourth generation)

Figure 39. CAPSENSE CSD sensing illustrates the CAPSENSE block that scans CAPSENSE sensors in CSD sensing mode.

As explained in Capacitive touch sensing method, this block works by first converting the sensor capacitance into an equivalent current. An analog multiplexer then selects one of the currents and feeds it into the current-to-digital converter. This current-to-digital converter consists of a sigma-delta converter, which controls the modulation IDAC for a specific period, the total current sourced or sinked by the IDACs is the same as the total current sinked or sourced by the sensor capacitance. The digital count output of the sigma-delta converter is an indicator of the sensor capacitance and is called a raw count. This block can be configured in either IDAC Sourcing mode or IDAC Sinking mode. In the IDAC Sourcing mode, the IDACs source current to AMUXBUS while the GPIO cells sink current from AMUXBUS. In the IDAC Sinking mode, the IDACs sink current from AMUXBUS while the GPIO cells source current to AMUXBUS.

#### GPIO cell capacitance to current converter

In the CAPSENSE CSD system, the GPIO cells are configured as switched-capacitance circuits that convert sensor capacitances into equivalent currents. Figure 40. GPIO cell structure shows a simplified diagram of the GPIO cell structure.

PSoC 4 and PSoC 6 devices consist of two AMUX buses: AMUXBUS A is used for CSD sensing and AMUXBUS B is used for CAPSENSE CSD shielding . The GPIO switched-capacitance circuit has two possible configurations: source current to AMUXBUS A or sink current from AMUXBUS A

#### IDAC sourcing mode

In the IDAC Sourcing mode, the GPIO cell sinks current from the AMUXBUS A through a switched capacitor circuit as Figure 41. GPIO cell sinking current from AMUXBUS A shows.

Two non-overlapping, out-of-phase clocks of frequency FSW control the switches SW1 and SW3 as Figure 42. SW1 and SW3 switch in non-overlapping manner shows. The continuous switching of SW1 and SW3 forms an equivalent resistance RS, as Figure 41. GPIO cell sinking current from AMUXBUS A shows.

If the switches operate at a sufficiently low frequency FSW, such that time TSW/2 is sufficient to fully charge the sensor to VREF and fully discharge it to ground, as Figure 42. SW1 and SW3 switch in non-overlapping manner shows, the value of the equivalent resistance RS is given by Figure 43. Sensor equivalent resistance.

Where,

CS = Sensor capacitance

FSW = Frequency of the sense clock

The sigma-delta converter maintains the voltage of AMUXBUS A at a constant VREF (this process is explained in Sigma-delta converter. Figure 44. Voltage across sensor capacitance shows the resulting voltage waveform across CS.

Figure 45. Average current sinked from AMUXBUS A to GPIO through CAPSENSE sensor (ICS) gives the value of average current taken from AMUXBUS A.

#### IDAC sinking mode

In the IDAC sinking mode, the GPIO cell sources current to the AMUXBUS A through a switched capacitor circuit as Figure 46. GPIO cell sourcing current to AMUXBUS A shows. Figure 47. Voltage across sensor capacitance shows the voltage waveform across the sensor capacitance.

Because this mode charges the AMUXBUS A directly through VDDD, it is more susceptible to power supply noise compared to the IDAC sourcing mode. Hence, it is recommended to use this mode with an LDO or a very stable and quiet VDDD.

Figure 48. Average current sourced to AMUXBUS A from GPIO through CAPSENSE sensor (ICS) provides the value of average current supplied to AMUXBUS A.

#### CAPSENSE™ clock generator

The CAPSENSE clock generator block generates the sense clock FSW, and the modulation clock FMOD, from the high-frequency system resource clock (HFCLK) or peripheral clock (PERI) depending on the PSoC device family as shown in Figure 39. CAPSENSE CSD sensing.

##### Sense Clock

The sense clock, also referred to as the switching clock, drives the non-overlapping clocks to the GPIO cell switched capacitor circuits for the GPIO cell capacitance to charge converter.

Sense clock can be sourced from three options: direct, 8-bit PRS, and 12-bit PRS. Some PSoC 4 and PSoC 6 MCU parts also support additional spread spectrum clock (SSCx) modes. For more details on the supported modes for PSoC device, see the Component datasheet/middleware document.

Direct clock is a constant frequency sense clock source. When you chose this option, the sensor pin switches with a constant frequency clock with frequency as specified in the CAPSENSE component configuration window.

PRS clock implies that the sense clock is driven from a PRS block, which can generate either 8-bit or 12-bit PRS. Use of the PRS clock spreads the sense clock frequency over a wide frequency range by dividing the input clock using a PRS.

SSCx also spreads the sense clock frequency. It provides better noise immunity and reduces radiated electromagnetic emissions.

See Manually tuning hardware parameters for details on the clock source and frequency selection guidelines.

##### Modulator clock

The modulation clock is used by the Sigma-delta converter. This clock determines the sensor scan time based on Equation 8 and Equation 9.

Where,

Resolution = Scan resolution

Sensor Initialization time = Time taken by the sensor to write to the internal registers and initiate a scan.

#### Sigma-delta converter

The sigma-delta converter converts the input current to a corresponding digital count. It consists of a sigma-delta converter and two current sourcing/sinking digital-to-analog converters (IDACs) called modulation IDAC and compensation IDAC as Figure 39. CAPSENSE CSD sensing shows.

The sigma-delta converter uses an external integrating capacitor, called modulator capacitor CMOD, as Figure 39. CAPSENSE CSD sensing shows. Sigma-delta converter controls the modulation IDAC current by switching it ON or OFF corresponding to the small voltage variations across CMOD to maintain the CMOD voltage at VREF. The recommended value of CMOD is listed in .

The sigma-delta converter can operate in either IDAC sourcing mode or IDAC sinking mode.

In both the above-mentioned modes, the sigma delta converter can operate in either single IDAC mode or dual IDAC mode:

• In the single IDAC mode, the modulation IDAC is controlled by the sigma-delta converter; the compensation IDAC is always OFF
• In the dual IDAC mode, the modulation IDAC is controlled by the sigma-delta converter; the compensation IDAC is always ON

In the single IDAC mode, if ‘N’ is the resolution of the sigma-delta converter and IMOD is the value of the modulation IDAC current, the approximate value of raw count in the IDAC Sourcing mode is given by Equation 10.

Similarly, the approximate value of raw count in the IDAC sinking mode is given by Equation 11.

In both cases, the raw count is proportional to sensor capacitance CS. The raw count is then processed by the CAPSENSE CSD Component firmware to detect touches. The hardware parameters such as IMOD, ICOMP, and FSW, and the software parameters, should be tuned to optimum values for reliable touch detection. For an in-depth discussion of the tuning, see CAPSENSE performance tuning.

In the dual IDAC mode, the compensation IDAC is always ON. If ICOMP is the compensation IDAC current, the equation for the raw count in the IDAC sourcing mode is given by Equation 12.

Raw count in the IDAC sinking mode is given by Equation 13.

Note: Raw count values are always positive. It is thus imperative to ensure that ICOMP is less than (VDD-VREF)CS FSW for the IDAC sinking mode and ICOMP is less than CS FSW VREF for the IDAC Sourcing mode. Equation 13 does not hold true if ICOMP > VREF CS FSW and Equation 12 does not hold true if ICOMP > (VDD - VREF) CS FSW; in these cases, raw counts will be zero.

The relation between the parameters shown in the above equation to the CAPSENSE Component parameters is listed in .

Table 3. Relationship between CAPSENSE raw count and CAPSENSE hardware parameters
1 N Scan resolution

Scan resolution is configurable from 6-bit to 16-bit.

See Component datasheet/middleware document for details.

2 VREF N/A

The VREF value is 1.2 V or configurable between 0.6 V to VDDA - 0.6 V depending on the PSoC device family.

See Component datasheet/middleware document for details.

3 FSW Sense clock frequency

Sense clock frequency and sense clock source decide the frequency at which the sensor is switching.

See Sense Clock for details.

Sense clock source
4 IMOD Modulator IDAC

IMOD = Modulation IDAC current

5 ICOMP Compensation IDAC

ICOMP = Compensation IDAC current

6 VDD N/A

This parameter is the device supply voltage.

7 CS N/A

This parameter is the sensor parasitic capacitance.

8 N/A Modulator clock frequency

Modulator clock divider does not impact raw count.

See the Modulator clock section for more details.

#### Analog multiplexer (AMUX)

The sigma delta converter scans one sensor at a time. An analog multiplexer selects one of the GPIO cells and connects it to the input of the sigma delta converter, as Figure 39. CAPSENSE CSD sensing shows. The AMUXBUS A and the GPIO cell switches (see SW3 in Figure 46. GPIO cell sourcing current to AMUXBUS A) forms this analog multiplexer. AMUXBUS A connects to all GPIOs that support CAPSENSE. See the corresponding Device datasheet for a list of port pins that support CAPSENSE. AMUXBUS A also connects the integrating capacitor CMOD to the sigma-delta converter circuit. AMUXBUS B is used for shielding and is kept at VREF when shield is enabled.

#### CAPSENSE™ CSD shielding

PSoC 4 and PSoC 6 MCU CAPSENSE supports shield electrodes for liquid tolerance and proximity sensing. CAPSENSE has a shielding circuit that drives the shield electrode with a replica of the sensor switching signal to nullify the potential difference between sensors and shield electrode. See Driven-shield signal and shield electrode Driven-shield signal and shield and Effect of liquid droplets and liquid stream on a self-capacitance sensor for details on how this is useful for liquid tolerance.

In the sensing circuit, the sigma delta converter keeps the AMUXBUS A at VREF (see Sigma-delta converter). The GPIO cells generate the sensor waveforms by switching the sensor between AMUXBUS A and a supply rail (either VDD or ground, depending on the configuration). The shielding circuit works in a similar way; AMUXBUS B is always kept at VREF. The GPIO cell switches the shield between AMUXBUS B and a supply rail (either VDDD or ground, the same configuration as the sensor). This process generates a replica of the sensor switching waveform on the shield electrode.

For a large shield layer with high parasitic capacitance, an external capacitor (Csh tank capacitor) is used to enhance the drive capacity of the shield electrode driver.

### CAPSENSE™ CSX sensing method (third- and fourth- generation)

Figure 55. CAPSENSE CSX sensing method configuration illustrates the CSX sensing circuit. The implementation uses the following hardware sub-blocks from CSD HW.

• An 8-bit IDAC and the sigma delta converter
• AMUXBUS A
• CAPSENSE clock generator for Tx clock and modulator clock
• VREF and port pins for Tx and Rx electrodes and external caps
• Two external capacitors (CINTA and CINTB) (see for recommended value of these capacitors)
Note: PSoC 4100 does not support the CSX sensing method.

The CSX sensing method measures the mutual-capacitance between the Tx electrode and Rx electrode, as shown in Figure 55. CAPSENSE CSX sensing method configuration. The Tx electrode is excited by a digital waveform (Tx clock), which switches between VDDIO (or VDDD if VDDIO is not available in the given part number) and ground. The Rx electrode is statically connected to AMUXBUS A. The CSX method requires two external integration capacitors, CINTA and CINTB. The value of these capacitors is listed in .

Figure 56. CSX sensing waveforms shows the voltage waveforms on the Tx electrode and CINTA and CINTB capacitors. The sampling – a process of producing a “sample” – is started by the firmware by initializing the voltage on both external capacitors to VREF and performing a series of sub-conversions. A sub-conversion is a capacitance to count conversions performed within a Tx clock cycle. The sum of results of all sub-conversions in a sample is referred to as “raw count”.

During a sub-conversion, both SW1 and SW2 switches are operated in phase with the Tx clock. On the rising edge of the Tx clock, SW1 is closed (SW2 is open during this time) and charge flows from the Tx electrode to the Rx electrode. This charge is integrated onto the CINTA capacitor, which increases the voltage on CINTA. The IDAC is configured in sink mode to discharge the CINTA capacitor back to voltage VREF. On the falling edge of the Tx clock, SW2 is closed (SW1 is open during this time) and the charge flows from the Rx electrode to the Tx electrode. This causes the voltage on CINTB to go below VREF. The IDAC is configured in source mode to bring the voltage on CINTB back to VREF.

The charge transferred between Tx and Rx electrodes in both the cycles is proportional to mutual-capacitance, CM, between the electrodes. The sigma delta converter controls IDAC for charging or discharging the external capacitors and also it measures the charging and discharging time in terms of modulator clock cycles for a sub-conversion. Multiple sub-conversions are performed during the CSX scanning and the result of each sub-conversion is accumulated to produce “raw count” for a sensor.

The modulator clock is used to measure the time taken to charge/discharge external capacitors within a Tx clock cycle. For this reason, modulator clock frequency must be always greater than Tx clock frequency; higher modulator clock frequency leads to better accuracy. For proper operation, the IDAC current should be set such that the CINTA and CINTB capacitors are charged/discharged within one Tx clock cycle. The CAPSENSE Component/middleware provides an option to automatically calibrate the IDAC. It is recommended to enable this option.

Where,

IDAC = IDAC current

CM = Mutual-capacitance between Tx and Rx electrodes

VTX = Amplitude of the Tx signal

FTX = Tx clock frequency

FMod = Modulator clock frequency

NSub = Number of sub-conversions

When you place a finger on the CSX button, the mutual-capacitance between Rx and Tx electrodes decreases, which decreases the raw count. This decrease in raw count from the hardware is inverted by the CAPSENSE Component to make it similar to the raw count change in CSD for a finger touch. The final resulting inverted raw count is given by Figure 58. Formula to determine rawcountComponent.

See CSX sensing method (third- and fourth-generation) for more details of CSX hardware parameters.

### CAPSENSE™ CSD-RM sensing method (fifth-generation)

This section provides an overview of the CSD-RM architecture implemented in the Fifth-Generation CAPSENSE (known as multi sense converter (MSC)) devices. The main features include ratiometric sensing, differential mode of operation without the need of reference voltage, use of capacitor DACs (CDAC) in place of current DACs (IDAC) which improves noise performance.

#### GPIO cell capacitance to charge converter

GPIO cell capacitance to current converter explains the GPIO cell configuration. In the Fifth-Generation architecture, the sensor is either interfaced to the AMUX (as before) or a new control MUX matrix which supports autonomous scanning (limited number of pins supported). The GPIO cells are configured as switched-capacitance circuits that convert sensor capacitances into equivalent charge transfer. Figure 60. GPIO cell structure shows the GPIO cell structure.

Four non-overlapping, out-of-phase clocks of frequency FSW control the switches (SW1, SW2, SW3 and SW4) as Figure 61. Voltage across sensor capacitance shows.

#### Capacitor DACs (CDACs)

IDACs are replaced by CDACs in the Fifth-Generation CAPSENSE architecture. It consists of two CDACs, a reference capacitor DAC and a compensation capacitor DAC. In each sense clock period the sensor capacitance, as mentioned in GPIO cell capacitance to charge converter, transfers charge to bothCMOD in a way that it unbalances the voltage between the CMOD’s. Both capacitor DACs are switched onto CMOD multiple times during a sense clock period to balance the CMOD’s back to their original voltage. Number of cycles required by the reference capacitor DAC to balance is proportional to the self-capacitance of the sensors.

#### CAPSENSE™ clock generator

This block generates the sense clock FSW, and the modulation clock FMOD, from the high-frequency system resource clock (HFCLK) or peripheral clock (PERI) depending on the PSoC device family.

##### Sense clock

CAPSENSE clock generation is similar to that in the older generation as explained in Sense Clock.

##### Modulator clock

The modulation clock is used by the Ratiometric sensing technology. This clock determines the sensor scan time based on Equation 16 and Equation 17.

Where,

Number of subconversions = Total number or sub-conversions in single scan

Subconversion = Capacitance to count conversions performed within a sense clock cycle

Sensor initialization time = Time taken by the sensor to write to the internal registers and initiate a scan

#### Ratiometric sensing technology

It consists of a ratiometric converter and two CDACs, a reference capacitor DAC and a compensation capacitor DAC. In each sense clock period the sensor capacitance, as mentioned in GPIO cell capacitance to charge converter, transfers charge to both CMOD in a way that it unbalances the voltage between the CMOD’s. The Ratiometric converter controls the reference CDAC by switching it ON or OFF corresponding to the small voltage variations across two CMOD’s to maintain the CMOD’s voltage at same level. Number of cycles required by the reference capacitor DAC to balance the voltage between the CMOD’s is proportional to the self-capacitance of the sensors.

The compensation capacitor is used to compensate excess mutual-capacitance from the sensor to increase the sensitivity. The number of times it is switched depends on the amount of charge the user application is trying to compensate (remove) from the sensor mutual-capacitance.

The ratiometric converter can operate in either single CDAC mode or dual CDAC mode.

• In the single CDAC mode, the reference CDAC is controlled by the ratiometric converter; the compensation CDAC is always OFF
• In the dual CDAC mode, the reference CDAC is controlled by the ratiometric converter; the compensation CDAC is always ON. Reference CDAC is capable of compensating up to 95%, results in increased signal as explained in Conversion gain and CAPSENSE signal

In the single CDAC mode, if Cref is the value of the reference CDAC, the approximate value of raw count is given by Equation 18.

In the dual CDAC mode, the compensation CDAC is always ON. If CcompCcomp is the compensation CDAC, the equation for the raw count is given by Equation 19.

Where,

MaxCount = NSub.SnsClkDiv

NSub = Number of sub-conversions

SnsClkDiv = Sense clock divider

CompClkDiv = Compensation CDAC divider

CS = Sensor capacitance

Cref = Reference capacitance

Ccomp = Compensation capacitance

As per Equation 18, the output raw count is proportional to the ratio of sensor capacitance to the reference capacitance, and hence the name Ratiometric Sensing.

Noise improvement is one of the main advantages of Fifth-Generation over previous generation of CAPSENSE technology. The dominant noise sources in the Fourth-Generation are current (IMOD), reference voltage (VREF), clock jitter (FSW) (see Figure 53. Dual IDAC sourcing raw count). These noise sources have been removed for the Fifth-Generation (see Equation 19). The IDAC has been replaced with CDAC. The system has been made fully differential, so it does not need VREF. The CAPSENSE architecture is no longer affected by jitter as the scan result is now based on the edges of the clock rather than the duration of the clock.

#### Analog multiplexer (AMUX) and control matrix (CTRLMUX)

Another feature introduced in the Fifth-Generation is the control matrix (CTRLMUX) as shown in Figure 59. CAPSENSE CSD-RM (fifth-generation). The CTRLMUX enables autonomous scanning and provides immunity to on-chip IO noise. The CTRLMUX allows the CAPSENSE IP to directly handle the sensor inputs5 (in addition to the traditional GPIO mode), and hence supports autonomous scanning of the sensors without the CPU.

5 Supports limited number of inputs. Refer to the Device for more details.

#### CAPSENSE™ CSDRM shielding

PSoC™ 4 CAPSENSE supports shield electrodes for liquid tolerance and proximity sensing. The purpose of the shielding is to remove the parasitic capacitance between sensor and shield electrodes. See Driven-shield signal and shield electrode and Effect of liquid droplets and liquid stream on a self-capacitance sensor for details on how this is useful for liquid tolerance. The Fifth-Generation CAPSENSE architecture supports two shield modes – active and passive shielding.

##### Active shielding

In active shielding mode, shield circuit drives the shield electrode with a replica of the sensor signal using a buffer as shown in Figure 66. Active shield signal. This nullify the potential difference between sensors and shield electrode.

##### Passive shielding

In passive shielding mode there is no buffer used, instead shield is switched between VDDA and GND as shown in Figure 67. Passive shield signal. The switching is controlled in such a way that the net charge between sensor and shield is nullified every two sense clocks.

provides the comparison of features of active shielding vs passive shielding features.

Table 4. Active vs passive shielding
Feature Active shielding Passive shielding Effect
Performance Higher Lower Active shielding is preferred for high performance applications.
Power impact Higher Lower Passive shielding is preferred for low power applications.
5 Supports limited number of inputs. Refer to the Device for more details.

### CAPSENSE™ CSX-RM sensing method (fifth-generation)

Figure 68. CAPSENSE CSX-RM sensing method configuration illustrates the CSX-RM sensing circuit. The implementation uses the following hardware subblocks:

• Two 8-bit capacitor DACs and ratiometric converter
• AMUXBUS and CTRLMUX
• CAPSENSE clock generator for Tx clock and modulator clock
• Port pins for Tx and Rx electrodes and external caps
• Two external capacitors (CMOD1 and C MOD2)

The CSX-RM sensing method measures the mutual-capacitance between the Tx electrode and Rx electrode, as shown in Figure 68. CAPSENSE CSX-RM sensing method configuration. The Tx electrode is activated by a digital waveform (Tx clock), which switches between VDDA and ground. The Rx electrode is statically connected to AMUXBUS A or CTRLMUX. The CSX-RM method requires two external integration capacitors, CMOD1 and CMOD2.

The sampling – a process of producing a “sample” – is started by the firmware by initializing the voltage on both external capacitors (CMOD) to VDDA/2 and performing a series of sub-conversions. A sub-conversion is a capacitance to count conversions performed within a Tx clock cycle. The sum of results of all sub-conversions in a sample is referred to as “raw count”.

On the rising and falling edge of the Tx clock, charge flows from the Tx electrode to the Rx electrode. In such a way that it unbalances the voltage between the external CMOD capacitors. Both capacitor DACs (reference and compensation capacitor DACs) are switched onto CMOD multiple times during a sense clock period to balance the CMOD’s back to their original voltage. Number of cycles required by the reference capacitor DAC to balance is proportional to the mutual-capacitance, Cm, between the electrodes.

The number of times the reference capacitor is switched with respect to the modulator clock is denoted by the Tx clock divider value according to Figure 69. Tx clock divider.

Where,

TxClkDiv = Tx clock divider

FMod = Modulator frequency

FTx = Tx clock frequency

The compensation capacitor is used to compensate excess mutual-capacitance from the sensor to increase the sensitivity. The number of times it is switched depends on the amount of charge the user application is trying to compensate (remove) from the sensor mutual-capacitance. The number of times the compensation capacitor is switched with respect to the modulator clock is denoted by the value of the compensation CDAC divider according to the Equation 21. The CDAC compensation clock divider must be less than or equal to the Tx clock divider.

Where,

CompClkDiv = Compensation CDAC divider

FM MOD = Modulator frequency

Fcomp = Compensation CDAC clock frequency

#### Ratiometric sensing technology

The ratiometric converter gives an equivalent raw count which is proportional to the sensor mutual-capacitance after each scan. The ratiometric converter can operate in either single CDAC mode or dual CDAC mode.

• In the single CDAC mode, the reference CDAC is controlled by the ratiometric converter; the compensation CDAC is always OFF
• In the dual CDAC mode, the reference CDAC is controlled by the ratiometric converter; the compensation CDAC is always ON. Compensation CDAC is capable of compensating up to 95%, results in increased signal as explained in Conversion gain and CAPSENSE signal

In the single CDAC mode, if Cref is the value of the reference CDAC, the approximate value of raw count is given by Equation 22.

In the dual CDAC mode, the compensation CDAC is always ON. If Ccomp is the compensation CDAC, the equation for the raw count is given by Equation 23.

Where,

MaxCount = NSub.TxClkDiv

NSub = Number of sub-conversions

TxClkDiv = Tx clock divider

CompClkDiv = CDAC compensation divider

CM = Mutual-capacitance of the sensor

Cref = Reference capacitance

Ccomp = Compensation capacitance

According to Equation 23, the output raw count is proportional to the ratio of mutual-capacitance of the sensor to the reference capacitance, and hence the name ratiometric sensing.

### Autonomous scanning

In previous generation CAPSENSE technology, after each scan, CPU is interrupted to configure next sensor. Autonomous scanning mode in Fifth-Generation CAPSENSE technology avoids the CPU intervention for scanning every next sensor. This significantly reduces the CPU bandwidth required for scanning widgets with large number of sensors. Autonomous scanning requires features such as CTRLMUX and DMA. As the number of pins supported with CTRLMUX is limited, number of pins supporting autonomous scanning is also limited. See Configuring autonomous scan section for more details.

### Usage of multiple channels

The PSoC 4100S Max device supports two Fifth-Generation CAPSENSE Blocks – MSC0 and MSC1. Each block has the same functionality and performance as explained in the CAPSENSE CSD-RM sensing method (fifth-generation) and CAPSENSE CSX-RM sensing method (fifth-generation) sections. Each instance can be considered as a channel and multiple instances imply multiple channels. Multi-channel behavior can be supported by multiple instances in single chip and/or having multiple chips. The operation of the channels is synchronized and operate in lockstep when scanning the sensors hooked in to the channels. Lockstep guarantees clock synchronization and avoid any cross-channel noise due to un-synchronized sense clocks.

See Multi-channel scanning section for more details.

4 The hardware state machine is a logic which controls the CAPSENSE block and sensor scanning.
5 Supports limited number of inputs. Refer to the Device for more details.

## CAPSENSE™ design and development tools

This chapter introduces the available software tools, such as PSoC Creator and ModusToolbox, to develop your CAPSENSE application. For more details, see the user manual of the respective IDE. shows the supported devices and the CAPSENSE component/middleware version in PSoC Creator and ModusToolbox.

Table 5. Tools and supported devices
Devices Software tool CAPSENSE library
PSoC 4000S, PSoC 4100S, PSoC 4100S Plus, PSoC 4100S Plus 256K, PSoC 4500S ModusToolbox, PSoC Creator CAPSENSE middleware, CAPSENSE component
PSoC 4100S Max, All PSoC 6 devices ModusToolbox CAPSENSE middleware
All other PSoC 4 devices PSoC Creator CAPSENSE component

### PSoC™ Creator

PSoC Creator is a state-of-the-art, easy-to-use IDE. It offers a unique combination of hardware configuration and software development based on classical schematic entry. You can develop applications in a drag-and-drop design environment using a library of Components. For details, see the PSoC Creator home page.

#### CAPSENSE™ component

PSoC Creator provides a CAPSENSE component, which is used to create a capacitive touch system in PSoC by simply configuring this Component. The CAPSENSE component also provides an application programming interface (API) to simplify firmware development. Some PSoC 4 Bluetooth® LE and PSoC 6 MCU devices also support a CAPSENSE Gesture Component (see the corresponding Device datasheet to see if your device supports this Component).

Each CAPSENSE component has an associated datasheet that explains details about the Component. To open the Component datasheet, right-click the Component and select Open Datasheet.

The CAPSENSE component also has a Tuner GUI, called the Tuner GUI, to help with the tuning process.

The CapSense_ADC6 component is only applicable for the PSoC 4S-Series, PSoC 4100S Plus, PSoC 4100PS, and PSoC 6 MCU devices. This component should be used when both CAPSENSE and ADC operations are required. This component allows using the CAPSENSE block for ADC operation and touch functionality in a time-multiplexed manner.

6 CapSense_ADC is not supported in devices with Fifth-Generation CAPSENSE block.

#### Tuner GUI

Tuner helper is included with the CAPSENSE component and assists in tuning CAPSENSE parameters and monitoring sensor data such as raw count, baseline, and difference count. Refer the Component datasheet/middleware document for the detailed procedure on how to use Tuner GUI.

#### Example projects

You can use the CAPSENSE example projects provided in PSoC Creator to learn schematic entry and firmware development. To find a CAPSENSE example project, go to the PSoC Creator start Page, click Find Code Example …, and select the appropriate architecture, as Figure 74. PSoC Creator example project shows. You can also filter for a project by writing partial or complete project name in the Filter by field.

6 CapSense_ADC is not supported in devices with Fifth-Generation CAPSENSE block.

### ModusToolbox™

ModusToolbox software suite is used for the development of PSoC 6 and PSoC 47 based CAPSENSE applications. You can download ModusToolbox from here. Before you start working with this software, It is recommended that you go through the Quick start guide and user guide. If you have ModusToolbox IDE installed in your system, you can create a CAPSENSE application for the devices supported in ModusToolbox.

#### CAPSENSE™ middleware

ModusToolbox provides a CAPSENSE middleware, which can be used to create a capacitive touch system in PSoC by simply configuring parameters in the CAPSENSE configuration tool. The middleware also provides an application programming interface (APIs) to simplify firmware development. See the CAPSENSE middleware library for more details.

#### CAPSENSE™ configurator

The CAPSENSE configurator tool in ModusToolbox is similar to that in PSoC Creator which is used to configure the CAPSENSE hardware and software parameters. For more details on configuring CAPSENSE in ModusToolbox, see the ModusToolbox CAPSENSE configurator guide and CAPSENSE middleware library. Figure 75. CAPSENSE configurator tool in ModusToolbox shows how to open the CAPSENSE configuration tool in ModusToolbox™. Alternatively, it can also be opened from the Quick panel in the ModusToolbox. For simplicity of documentation, this design guide shows selecting the CAPSENSE™ parameter in PSoC Creator CAPSENSE component.

This CSDADC middleware8 should be used when both the CAPSENSE and ADC operations are required. This middleware allows using the CAPSENSE hardware block for ADC operation and touch functionality in a time-multiplexed manner. It could be used for all three sensing modes that is, CSD, ADC, and CSX. See the CSDADC middleware library documentation for more details.

8 CapSense_ADC is not supported in devices with Fifth-Generation CAPSENSE block.

#### CSDIDAC middleware

The CSDIDAC middleware allows you to use the CAPSENSE IDAC in a standalone mode. You can use this middleware if you are not using CAPSENSE middleware or if you are using only one IDAC for CAPSENSE. See the CSDADC middleware library documentation.

#### Example projects

To quickly start the CAPSENSE system design, start with the example projects provided in ModusToolbox. You can find a CAPSENSE example project by navigating to File > New > ModusToolbox Application. Choose the appropriate Board Support Package with a device. Figure 76. Creating CAPSENSE CSD Button example project in ModusToolbox shows creating a CAPSENSE CSD Button example starter code in ModusToolbox from the list of available code examples.

7 See for supported PSoC 4 devices in ModusToolbox.
8 CapSense_ADC is not supported in devices with Fifth-Generation CAPSENSE block.

### Hardware kits

lists the development kits that support evaluation of PSoC 4 and PSoC 6 CAPSENSE.

Table 6. PSoC 4 and PSoC 6 CAPSENSE development kits
Development kit Supported CAPSENSE features

PSoC 4000 pioneer kit (CY8CKIT-040)

A 5x6 CAPSENSE touchpad and a wire proximity sensor

PSoC 4 S-series pioneer kit

Two self- or mutual-capacitive sensing buttons

A 7×7 self- or mutual-capacitive sensing touchpad

PSoC 4 S-series prototyping kit (CY8CKIT-145)

Three self- or mutual-capacitive sensing buttons

A five-segment self- or mutual-capacitive sensing linear slider

PSoC 4100S Plus prototyping kit (CY8CKIT-149)

Three self- or mutual-capacitive sensing buttons

A six-segment self- or mutual-capacitive sensing linear slider

PSoC 4100S Max pioneer kit (CY8CKIT041S-Max)

Two self- or mutual-capacitive sensing buttons

An eight-segment self- or mutual-capacitive sensing linear slider

A 10x16 self- or mutual-capacitive sensing touchpad

A proximity sensor loop

PSoC 4 pioneer kit (CY8CKIT042)

A five-segment linear slider

PSoC 4 Bluetooth® LE pioneer Kit (CY8CKIT-042-BLE)

A five-segment linear slider and a wire proximity sensor

PSoC 4200-M pioneer kit (CY8CKIT-044)

A five-element gesture detection and two proximity wire sensors

PSoC 4200-L pioneer kit (CY8CKIT-046)

A five-element gesture detection, two proximity wire sensors, and an eight-element radial slider

PSoC 4100PS prototyping kit (CY8CKIT-147)

No onboard CAPSENSE sensors. The kit can be used to connect external sensors to any I/O pin.

CAPSENSE proximity shield

A four-element gesture detection and one proximity loop sensor

CAPSENSE liquid level sensing shield (CY8CKIT-022)

A two-element flexible PCB and 12-element flexible PCB

PSoC 4 processor module (CY8CKIT038), with PSoC development kit (CY8CKIT001)

A five-segment linear slider and two buttons

CAPSENSE expansion board kit

(CY8CKIT-031), to be used with CY8CKIT038 and CY8CKIT-001

A 10-segment slider, five buttons and a 4 x 4 matrix button with LED indication.

MiniProg3 program and debug kit

CAPSENSE performance tuning in CY8CKIT-038

PSoC 6 Wi-Fi BT pioneer kit

(CY8CKIT-062-WiFi-BT pioneer kit) and PSoC 6 Bluetooth® LE pioneer kit (CY8CKIT062-BLE pioneer kit)

A 5-segment CAPSENSE slider, two CAPSENSE buttons, one CAPSENSE proximity sensing header, a proximity sensor.

PSoC 6 Wi-Fi BT prototyping kit (CY8CPROTO-063-4343W)

A 5-segment CAPSENSE slider and two mutual-cap CAPSENSE buttons

6 CapSense_ADC is not supported in devices with Fifth-Generation CAPSENSE block.
7 See for supported PSoC 4 devices in ModusToolbox.
8 CapSense_ADC is not supported in devices with Fifth-Generation CAPSENSE block.

## CAPSENSE™ performance tuning

After you have completed the sensor layout (see PCB layout guidelines), the next step is to implement the firmware and tune the CAPSENSE parameters for the sensor to achieve optimum performance. The CAPSENSE sensing method is a combination of hardware and firmware techniques. Therefore, it has several hardware and firmware parameters required for proper operation. These parameters should be tuned to optimum values for reliable touch detection and fast response. Most of the capacitive touch solutions in the market must be manually tuned. A unique feature called SmartSense (also known as Auto-tuning) is available for PSoC 4 and PSoC 6 CAPSENSE. SmartSense is a firmware algorithm that automatically sets all parameters to optimum values.

### Selecting between SmartSense and manual tuning

SmartSense auto-tuning reduces design cycle time and provides stable performance across PCB variations, but requires additional RAM and CPU resources, as indicated in the Component datasheet/middleware document or ModusToolbox CAPSENSE configurator guide, to allow runtime tuning of CAPSENSE parameters. SmartSense is recommended mainly for conventional CAPSENSE applications involving simple button and slider widgets, and is currently supported only for Self-capacitance sensing and not Mutual-capacitance sensing.

On the other hand, manual tuning requires effort to tune optimum CAPSENSE parameters, but allows strict control over characteristics of capacitive sensing system, such as response time and power consumption. It also allows use of CAPSENSE beyond the conventional button and slider applications such as proximity and liquid-level-sensing.

SmartSense is the recommended tuning method for all the conventional CAPSENSE applications. You should use SmartSense auto-tuning if your design meets the following requirements:

• The design is for conventional user-interface application like buttons, sliders, and touchpad
• The parasitic capacitance (CP) of the sensors is within SmartSense-supported range as mentioned in the “SmartSense operating conditions” section in Component datasheet/middleware document or ModusToolbox CAPSENSE configurator guide
• The sensor scan time chosen by SmartSense meets the response time/power requirements of the end system
• SmartSense auto-tuning meets the RAM/flash requirements of the design

For all other applications, use Manual tuning. In such cases, you can also use SmartSense as an initial step to find the optimum hardware parameters such as Sense Clock frequency, and then change the tuning mode to manual tuning for further tuning of the CapSense parameters. See Using SmartSense to determine hardware parameters.

Note: Manual tuning requires I2C or UART communication with a host PC.

### SmartSense

#### Overview

The CAPSENSE algorithm is a combination of hardware and firmware blocks inside PSoC. Therefore, it has several hardware and firmware parameters required for proper operation. These parameters need to be tuned to optimum values for reliable touch detection and fast response.

SmartSense is a CAPSENSE tuning method that automatically sets sensing parameters for optimal performance, based on user-specified finger capacitance values, and continuously compensates for system, manufacturing, and environmental changes.

Note: SmartSense currently supports widgets with CSD (Self-cap) Sensing mode only. CSX (Mutual-cap) widgets must be tuned manually.

Some advantages of SmartSense, as opposed to manual tuning are:

• Reduced design cycle time: The design flow for capacitive touch applications involves tuning all of the sensors. This step can be time consuming if there are many sensors in your design. In addition, you must repeat the tuning when there is a change in the design, PCB layout, or mechanical design. Auto-tuning solves these problems by setting all of the parameters automatically. Figure 77. Design flow with and without SmartSense shows the design flow for a typical CAPSENSE application with and without SmartSense
• Performance is independent of PCB variations: The parasitic capacitance, CP, of individual sensors can vary due to process variations in PCB manufacturing, or vendor-to-vendor variation in a multi-sourced supply chain. If there is significant variation in CP across product batches, the CAPSENSE parameters must be re-tuned for each batch. SmartSense sets parameters for each device automatically, hence taking care of variations in CP
• Ease of use: SmartSense is faster and easier to use because only a basic knowledge of CAPSENSEis needed

Note that SmartSense can be used in multiple ways:

1. SmartSense (Full auto-tune) – This is the quickest way to tune. This method calibrates CAPSENSE hardware and software parameters automatically at runtime. This is the recommended method for most designs
2. SmartSense (Hardware parameters only) – This method auto-tunes all hardware parameters of CAPSENSE, but allows to set user-defined threshold values (see ). This method consumes less flash/RAM resources than SmartSense (Full Auto-Tune). Also, this method avoids the extra processing needed for automatic threshold calculation and hence allows lower power consumption for a given scan rate. Use this method for low-power or noisy designs or in cases with constrained memory requirements
3. SmartSense for initial tuning – You may also use SmartSense for initial tuning, to quickly find the best settings for a CAPSENSE board and then change to manual tuning. This method is useful for cases with strict requirements on response time or power consumption. This is a quick method to find the best settings, instead of starting manual tuning from scratch. Refer to the section Using SmartSense to determine hardware parameters for more details
4. Table 7. CAPSENSE parameters auto-tuned in SmartSense
Parameter Full auto-tune mode Hardware parameters only mode
Scan resolution Calculated once on CAPSENSE initialization.
Compensation IDAC
Modulator IDAC
Sense clock frequency
Modulator clock frequency
Finger threshold Calculated once on CAPSENSE initialization based on the selected finger capacitance and updated after each sensor scan. Manual selection (see ).
Noise threshold
Hysteresis
Negative noise threshold
Low baseline reset

#### SmartSense full auto-tune

In SmartSense Full Auto-tune mode, the only parameter that needs to be tuned by the user is the Finger Capacitance parameter. The Finger Capacitance parameter (CF) indicates the minimum value of finger capacitance that should be detected as a valid touch by the CAPSENSE Component. Whenever the actual CF that is added when the finger touches the button sensor is greater than the value specified for the Finger Capacitance parameter in the Component configuration window, the sensor status will change to ‘1’; however, if the actual CF added by the finger touch is less than the value specified in the Component configuration window, the sensor status will remain ‘0’. The way of tuning the finger capacitance is different for button and slider widgets.

Note: Even for SmartSense auto-tuning, the CAPSENSE Component allows manual configuration of some general parameters like enable/disable of compensation IDAC, filters, shield such as liquid-tolerance-related parameters and modulator clock. These can be left at their default values for most cases or configured based on the respective sections in this guide.
##### Tuning button widgets

This section explains how to choose the Finger capacitance value for the Button widget. You may perform only a coarse tuning of the Finger capacitance parameter for a working design, or you may choose to fine-tune the Finger capacitance value. Coarse-tuning will satisfy the requirements of most designs, but fine-tuning will allow you to choose the most efficient CAPSENSE parameters (that is, minimum sensor scan time) using SmartSense.

If you do not know the value of CF (CF can be estimated based on Figure 6. Finger capacitance), set the Finger capacitance as follows:

1. Start by specifying the highest value for finger capacitance (from the available options in the list) and check the SNR and button status when the button is touched. Use the Tuner GUI to find the SNR
2. Decrease the finger capacitance parameter value until the button status changes to ‘1’ on touch and SNR>5. Figure 78. Using SmartSense auto-tuning based CAPSENSE project in PSoC Creator shows the detailed steps to find the right value for the Finger capacitance parameter in your design

Enable filters if the SNR of one or more sensors is less than 5:1 when the set finger capacitance is already at the least finger capacitance supported in the Component. You can also enable filters if externally induced noise is causing a decrease in SNR. See to choose the right filter in this case. There are various types of filters available in the CAPSENSE Component such as Median Filter, IIR filter, and Average Filter; you can enable more than one filter to reduce the noise in the raw count according to the requirement.

If you choose to use an IIR filter, begin by selecting a filter with a higher value of the filter coefficient and keep decreasing it until you achieve an SNR greater than or equal to 5:1. Using filters will affect the response time. You must properly select the filter coefficient such that the response time and SNR requirement are satisfied.

If the SNR is still less than 5:1 even when the smallest allowed value of finger capacitance and proper filter is chosen, see PCB layout , Manual tuning, or Tuning debug FAQs for more details on debugging the issue.

Table 8. Raw data noise filters in CAPSENSE component
Filter Description Mathematical description Application
Median Nonlinear filter that takes the three most recent samples and computes the median value.

Eliminates noise spikes from motors and switching power supplies

Average Finite impulse response filter (no feedback) with equally weighted coefficients. It takes the four most recent samples and computes their average.

Eliminates periodic noise (for example, from power supplies)

First Order IIR

Infinite impulse response filter (feedback) with a step response similar to an RC low pass filter, thereby passing the low-frequency signals (finger touch responses).

K value is fixed to 256.

N is the IIR filter raw count coefficient.

A lower N value results in lower noise, but slows down the response.

Eliminates high frequency noise.

##### Tuning slider widgets

For sliders, set finger capacitance to the highest value initially. Slide your finger on the slider. If at any position on the slider, at least one slider segment status is ON and has an SNR >5:1, and at least two slider segments report a “difference count” that is, a “sensor signal” value greater than 0, use this finger capacitance value. Otherwise, decrease the finger capacitance value until the above condition holds true. Figure 79. Setting finger capacitance value for ssliders shows how to tune the finger capacitance for slider widget.

If these conditions are not met even after setting minimum allowed Finger Capacitance, use Manual tuning or revise the hardware according to Slider design considerations or see Tuning debug FAQs. Figure 79. Setting finger capacitance value for ssliders explains the process of setting finger capacitance value for sliders.

Note: It is recommended to use the compensation IDAC because it allows a higher variation in the parasitic capacitance of the slider segment with respect to the slider segment that has the maximum CP.

* To review slider design, see the Slider design section in the Design considerations chapter.

** To do manual tuning, see the Manual tuning section in the CAPSENSE performance tuning chapter.

#### SmartSense hardware parameters-only mode

See for the recommended values for thresholds when the CSD tuning method is SmartSense (Hardware parameters only).

### Manual tuning

#### Overview

SmartSense technology allows a device to calibrate itself for optimal performance and complete the entire tuning process automatically. This technology will meet the needs of most designs, but in cases where SmartSense does not work or there are specific SNR or power requirements, the CAPSENSE parameters can be adjusted to meet system requirements. This can be achieved by manual tuning.

Some advantages of manual tuning, as opposed to SmartSense auto-tuning are:

• Strict control over parameter settings: SmartSense sets all the parameters automatically. However, there may be situations where you need to have strict control over the parameters. For example, use manual tuning if you need to strictly control the time PSoC takes to scan a group of sensors or strictly control the sense clock frequency of each sensor (this can be done to reduce EMI in systems)
• Supports higher parasitic capacitances: If the parasitic capacitance is higher than the value supported by SmartSense, you should use manual tuning. See the Component datasheet/middleware document for more details on the supported range of parasitic capacitance by SmartSense

The manual tuning process can be summarized in the following three steps and is shown in Figure 80. Manual tuning process overview.

Set initial values of Selecting CAPSENSE hardware parameters using SmartSense (see Using SmartSense to determine hardware parameters) or determine the values manually.

Tune CAPSENSE component hardware parameters to ensure that Signal-to-noise is greater than 5:1 with a signal of at least 50 counts while meeting the system timing requirements.

Set optimum values of Selecting CAPSENSE software parameters.

The following sections describe the fundamentals of manual tuning and the above three steps in detail. Knowledge of the CAPSENSE architecture in PSoC is a prerequisite for these sections. See Capacitive touch sensing method and CAPSENSE generations in PSoC 4 and PSoC 6. The main difference in CAPSENSE architecture across different generations are listed in .

Depending upon the sensing method selected, the manual tuning procedure will differ. See CSD sensing method (third- and fourth-generation), CSX sensing method (third- and fourth-generation) chapter for their respective manual tuning procedures. You can skip these sections if you are not planning to use manual tuning in your design. Figure 80. Manual tuning process overview shows a general manual tuning procedure.

* To review the hardware design, see the Sensor construction and PCB layout guidelines sections in the Design considerations chapter.

#### CSD sensing method (third- and fourth-generation)

This section explains the basics of manual tuning using CSD sensing method. It also explains the hardware and software parameters that influence CSD sensing method and procedure of manual tuning for button, slider, touchpad and proximity widgets.

##### Basics

###### Conversion gain and CAPSENSE™ signal

Conversion gain will influence how much signal the system sees for a finger touch on the sensor. If there is more gain, the signal is higher, and a higher signal means a higher achievable Signal-to-noise ratio (SNR).

Note: An increased gain may result in an increase in both signal and noise. However, if required, you can use firmware filters to decrease noise. For details on available firmware filters, see .
###### Conversion gain in single IDAC mode

In the single IDAC mode, the raw count is directly proportional to the sensor capacitance.

Where,

CS = sensor capacitance

CS = CP if there is no finger present on sensor

CS = (CP + CF) when there is a finger present on the sensor

GCSD = Capacitance to digital conversion gain of CAPSENSE CSD

The approximate value of this conversion gain using the IDAC sourcing mode, according to Figure 51. Single IDAC sourcing raw count and Figure 81. Raw count relationship to sensor capacitance is:

Where,

VREF = Comparator reference voltage. Refer .

FSW = Sense clock frequency

IMOD = Modulator IDAC current

N = Resolution of the sigma to delta converter.

The tunable parameters of the conversion gain are VREF, FSW, IMOD, and N. Figure 84. Raw count versus sensor capacitance illustrates a plot of raw count versus sensor capacitance.

The change in raw counts when a finger is placed on the sensor is called CAPSENSE signal. Figure 85. Signal values for different conversion gains shows how the value of the signal changes with respect to the conversion gain.

Figure 85. Signal values for different conversion gains shows three plots corresponding to three conversion gain values GCSD3 ,GCSD2 ,and GCSD1 . An increase in the conversion gain results in higher signal value. However, this increase in the conversion gain also moves the raw count corresponding to CP (that is, Baseline) towards the maximum value of raw count (2N-1). For very high gain values, the raw count saturates as the plot of GCSD3 shows. Therefore, you should tune the conversion gain to get a good signal value while avoiding saturation of raw count. Tune the CSD parameters such that when there is no finger on the sensor, that is when CS = CP, the raw count = 85% of (2N-1) as Figure 86. Recommended tuning shows. This ensures maximum gain, with enough margin for the raw count to grow because of environmental changes, and not saturate on finger touches.

###### Conversion gain in dual IDAC mode

The equation for raw count in the dual IDAC mode, according to Figure 81. Raw count relationship to sensor capacitance and Figure 53. Dual IDAC sourcing raw count is:

Where,

ICOMP = Compensation IDAC current

GCSD is given by Figure 50. Hardware scan time for sourcing IDAC mode and Figure 83. Capacitance to digital converter gain (sinking IDAC mode) for sinking IDAC mode.

In both single IDAC and dual IDAC mode, tune the CSD parameters, so that when there is no finger on the sensor,that is when CS = , CP the raw count = 85% of (2N-1), as Figure 88. Recommended tuning in dual IDAC mode shows, to ensure high conversion gain, to avoid Flat-spots, and to avoid raw count saturation due to environmental changes.

As Figure 88. Recommended tuning in dual IDAC mode shows, the 85% requirement restricts to a fixed gain in single-IDAC mode, while in dual-IDAC mode, gain can be increased by moving the CS axis intercept to the right (by increasing ICOMP) and correspondingly decreasing the modulator IDAC (IMOD) to still achieve raw count = 85% of (2N-1) for CS = CP. Using dual IDAC mode this way brings the following changes to the Raw Count versus CP graph:

1. Use of compensation IDAC introduces a non-zero intercept on the CS axis as given in .

The value of IMOD in the dual IDAC mode is half compared to the value of IMOD in the single IDAC mode (all other parameters remaining the same), so the gain GCSD in the dual IDAC mode is double the gain in the single IDAC mode according to dual IDAC mode. Thus, the signal in the dual IDAC mode is double the signal in the single IDAC mode for a given resolution N.

While manually tuning a sensor, keep dual IDAC mode and Figure 71. CSX-RM single CDAC raw count as well as the following points in mind:

1. Higher gain leads to increased sensitivity and better overall system performance. However, do not set the gain such that raw counts saturate, as the plot of gain GCSD3 shows in Figure 85. Signal values for different conversion gains. It is recommended to set the gain in such a way that the raw count corresponding to CP is 85 percent of the maximum raw count for both the single IDAC and dual IDAC mode. The sense clock frequency (FSW) should be set carefully; higher the frequency, higher the gain, but the frequency needs to be low enough to fully charge and discharge the sensor as Figure 71. CSX-RM single CDAC raw count indicates
2. Enabling the Compensation IDAC plays a huge role in increasing the gain; it will double the gain if set as recommended above. Always enable the Compensation IDAC when it is not being used for general-purpose applications
3. Lower the modulation IDAC current, higher the gain. Adjust your IDAC to achieve the highest gain, but make sure that the raw counts corresponding to CP have enough margin for environmental changes such as temperature shifts, as indicated in Figure 86. Recommended tuning and Figure 88. Recommended tuning in dual IDAC mode
4. Increasing the number of bits of resolution used for scanning increases gain. An increase in resolution by one bit will double the gain of the system, but also double the scan time according to Figure 49. Sensor scan time. A balance of scan time and gain needs to be achieved using resolution
###### Flat-spots

Ideally, raw counts should have a linear relationship with sensor capacitance as Figure 84. Raw count versus sensor capacitance and Figure 88. Recommended tuning in dual IDAC mode show. However, in practice, sigma delta modulators have non-sensitivity zones, also called flat-spots or dead-zones – for a range of sensor capacitance values, the sigma delta modulator may produce the same raw count value as Figure 90. Flat-spots in raw counts versus sensor capacitance when direct clock is used shows. This range is known as a dead-zone or a flat-spot.

In the case of CAPSENSE CSD, these flat spots occur near 25, 50, and 75 percent of the maximum raw count value (that is, near 25%, 50%, and 75% of 2N-1, where N = Scan resolution). These flat spots are prominent when direct clock is used as Sense Clock source. Flat-spots do not occur if PRS is used as the Sense Clock source (see also section Using SmartSense to determine hardware parameters.

For almost all systems, we recommend using PRS as the Sense Clock source because it limits the impact of flat spots and also provides EMI/EMC benefits as indicated in Sense Clock. If your system requires a direct clock, ensure that you use auto-calibration or avoid this raw count range when using manual calibration.

###### Flat-Spots Reduction Techniques

1. Calibrate rawcount to 85%

In the case of CAPSENSE CSD, these flat-spots occur near 25, 50, and 75 percent of the maximum raw count value (that is, near 25%, 50%, and 75% of 2N-1, where ‘N’ is the Scan resolution). Setting calibration to 85% decrease the width of flat-spots significantly.

2. Use PRS clock

These flat-spots are prominent when direct clock is used as Sense Clock source. Flat-spots do not occur if PRS is used as the Sense Clock source (see also section Using SmartSense to determine hardware parameters .For almost all systems, we recommend using PRS as the Sense Clock source because it limits the impact of flat-spots and also provides EMI/EMC benefits as indicated in Sense clock source Sense clock . If your system requires a direct clock, ensure that you use auto-calibration or avoid this raw count range when using manual calibration.

##### Selecting CAPSENSE™ hardware parameters

CAPSENSE hardware parameters govern the conversion gain and CAPSENSE signal. lists the CAPSENSE hardware parameters that apply to CSD sensing method. The following subsection gives guidance on how to adjust these parameters to achieve optimal performance for CAPSENSE CSD system.

For simplicity of documentation, this design guide shows selecting the CAPSENSE parameters in PSoC Creator. You can use the same procedure to set the parameters in ModusToolbox. However, in ModusToolbox, you set the Sense clock and Modulator clock using divider values while in the PSoC Creator you specify the frequency value directly in the configurator. For more details on configuring CAPSENSE, see the Component datasheet/middleware document.

Table 9. CAPSENSE component hardware parameters
Sl. No. CAPSENSE parameter in PSoC Creator CAPSENSE parameter in ModusToolbox
1 Sense cock frequency Sense clock divider
2 Sense clock source Sense clock source
3 Modulator clock frequency Modulator clock divider
4 Modulator IDAC Modulator IDAC
5 Compensation IDAC Compensation IDAC
6 Scan resolution Scan resolution
###### Using SmartSense to determine hardware parameters

Parameters listed in are CAPSENSE hardware parameters. Tuning these parameters manually for optimal value is a time-consuming task. You can use SmartSense to determine these hardware parameters and take it as an initial value for manual tuning. You can fine-tune these values to further optimize the scan time, SNR, power consumption, or improving EMI/EMC capability of the CAPSENSE system.

Set the tuning mode to SmartSense and configure default values for parameters other than finger capacitance. See the SmartSense section for the tuning procedure and use the Tuner GUI to read back all the hardware parameters set by SmartSense. See the Component datasheet/middleware document for more details on how to use the Tuner GUI.

Figure 91. Read-back hardware parameter values in Tuner GUI shows the best hardware parameter values in the Tuner GUI that are tuned by SmartSense for a specific hardware to sense a minimum finger capacitance of 0.1 pF.

###### Sense clock parameters

There are two parameters that are related to Sense clock: Sense clock source and Sense clock frequency.

###### Sense clock source

Select “Auto” to let the Component automatically choose the best Sense clock source from Direct, PRSx, and SSCx for each widget. If not selecting Auto, select the clock source based on the following:

• Use pseudo random sequence (PRSx) modes to remove flat-spots
• Use spread spectrum clock (SSCx) modes for reducing EMI/EMC noise at a particular frequency. This feature is available in PSoC 4 S-Series, PSoC 4100S Plus, PSoC 4100PS, and PSoC 6 family of devices. In this case, the frequency of the sense clock is spread over a predetermined range
• Use Direct clock for absolute capacitance measurement

When selecting PRSx as the sense clock source, ensure that the sequence completes within one conversion cycle; not letting the sequence complete may cause high noise in raw count. that is, TPRS<<TSCAN.

For PRS clock, use the following equations to calculate one PRS sequence completion cycle and scan time.

See the Component datasheet/middleware document for more details on the rules and recommendations for SSCx selection.

###### Sense clock frequency

The sense clock frequency should be selected so that the sensor will charge and discharge completely in each sense clock period as Figure 44. Voltage across sensor capacitance shows.

This requires that the maximum sense clock frequency be chosen per Equation 31.

Here, CP is the sensor parasitic capacitance, and RSeriesTotal is the total series-resistance, including the 500 Ω resistance of the internal switches, the recommended external series resistance of 560 Ω (connected on PCB trace connecting sensor pad to the device pin), and trace resistance if using highly resistive materials (example ITO or conductive ink);that is, a total of 1.06 kΩ plus the trace resistance.

The value for CP can be estimated using the CSD Built-in-Self-test API; GetSensorCapacitance(). See the Component datasheet/middleware document for details.

Figure 82. Capacitance to digital converter gain shows that it is best to use the maximum clock frequency to have a good gain; however, you should ensure that the sensor capacitor fully charges and discharges as shown in Figure 44. Voltage across sensor capacitance.

Generally, the CP of the shield electrode will be higher compared to sensor CP. For good liquid tolerance, the shield signal should satisfy the condition mentioned in Shield electrode tuning theory. If it is not satisfied, reduce the sense clock frequency further to satisfy the condition.

###### Modulator clock frequency

The modulator clock governs the conversion time for capacitance-to-digital conversion, also called the “sensor scan time” (see Figure 49. Sensor scan time).

A lower modulator clock frequency implies the following:

Longer conversion time (see Figure 71. CSX-RM single CDAC raw count and Figure 69. Tx clock divider)

• Lower peak-to-peak noise on raw count because of longer integration time of the sigma-delta converter
• Wider Flat-spots

Select the highest frequency for the shortest conversion time and narrower flat spots for most cases. Use slower modulator clock to reduce peak-to-peak noise in raw counts if required.

###### Modulation and compensation IDACs

CSD supports two IDACs: Modulation IDAC and Compensation IDAC that charge CMOD as Figure 39. CAPSENSE CSD sensing shows. These govern the for capacitance-to-digital conversion. The CapSense Component allows the following configurations of the IDACs:

• Enabling or disabling of Compensation IDAC
• Enabling or disabling of Auto-calibration for the IDACs
• DAC code selection for Modulator and Compensation IDACs if auto-calibration is disabled
###### Compensation IDAC

Enabling the compensation IDAC is called “dual IDAC” mode, and results in increased signal as explained in . Enable the compensation IDAC for most cases. Disable the compensation IDAC only if you want to free the IDAC for other general-purpose analog functions.

###### Auto-calibration

This feature enables the firmware to automatically calibrate the IDAC to achieve the required calibration target of 85%. It is recommended to enable auto-calibration for most cases. Enabling this feature will result in the following:

• Fixed raw count calibration to 85% of maximum raw count even with part-to-part CP variation
• Avoids Flat-spots
• Automatically selects the optimum gain

If your design environment includes large temperature variation, you may find that the 85% IDAC calibration level is too high, and that the raw counts saturate easily over large changes in temperature, leading to lower SNR. If this is the case, you can adjust the calibration level lower by using CapSense_CSDCalibrateWidget() in your firmware.

For proper functioning of CAPSENSE under diverse environmental conditions, it is recommended to avoid very low or high IDAC codes. For a 7-bit IDAC, it is recommended to use IDAC codes between 18-110 from the possible 0 to 127 range. You can use CAPSENSE tuner to confirm that the auto-calibrated IDAC values fall in this recommended range. If the IDAC values are out of the recommended range, based on Figure 81. Raw count relationship to sensor capacitance, Figure 82. Capacitance to digital converter gain andFigure 87. Dual IDAC mode raw counts, you may change the VRef or FSW to get the IDAC code in proper range.

Disable IDAC auto-calibration if a change in CP needs to be detected by measuring the raw count level at reset, for example:

• Detecting large variations in sensor CP across boards or layout problems
• Detecting finger touch at reset
• Advanced CAPSENSE methods like liquid-level sensing, for example, to have different raw count level for different liquid levels at reset
###### Selecting DAC codes

This is not the recommended approach. However, this could be used only If you want to disable auto-calibration for any reason. To get the IDAC code, you may first configure CAPSENSE Component with auto-calibration enabled and all other hardware parameters the same as required for final tuning and read back the calibrated IDAC values using Tuner GUI. Then, re-configure the CAPSENSE Component to disable auto-calibration and use the obtained IDAC codes as fixed DAC codes read-back from the Tuner GUI.

###### Scan resolution

It governs the sensor scan time per Equation 29 and the conversion gain per Figure 81. Raw count relationship to sensor capacitance, Equation 25, and Equation 27. Scan resolution needs to be selected to maintain a balance between the signal and scan time.

Higher scan resolution implies the following:

• Longer scan time per Equation 29
• Higher SNR on raw counts (increase in resolution increases the signal at a disproportionate rate to noise)

In general, it is recommended to tune the resolution to achieve as high SNR as possible; however if the system is constrained on power consumption and/or response time, set the lowest resolution to achieve at-least 5:1 SNR in the end system.

Note: You should tune the scan resolution for less than 10:1 SNR only if you have scan time or power number constraints.
###### Tuning shield electrode

The shield related parameters need to be additionally configured or tuned differently when you enable the Shield electrode in the CSD sensing method for liquid tolerance or reducing the Cp of the sensor.

###### Shield electrode tuning theory

Ideally, the shield waveform should be exactly the same as that of the sensor as explained in Driven shield signal and shield electrode. However, in practical applications, the shield waveform may have a higher settling time and an overshoot error. Observe the sensor and shield waveform in the oscilloscope; an example waveform is shown in Driven shield signal and shield electrode. The shield waveform should settle to the sensor voltage within 90% of ON time of the sense clock waveform and the overshoot error of the shield signal with respect to VREF should be less than 10%.

If these conditions are not satisfied, you will observe a change in raw count of the sensors when touching the shield hatch; in addition, if inactive sensors are connected to shield as mentioned in Inactive sensor connection, touching one sensor can cause change in raw count on other sensors, which indicates that there is cross talk if the shield electrode is not tuned properly.

In SmartSense, the sense clock frequency is automatically set. Check if these conditions are satisfied. If not satisfied, switch to Manual tuning and set the Sense clock frequency manually so that these conditions are satisfied. You can also tune the Shield SW resistance parameter to reduce the overshoot error.

###### Enable shield tank capacitor

Enabling a shield tank capacitor increases the drive strength of the shield thus allowing the shield signal to settle to the sensor voltage faster as required. It is recommended to use the shield tank capacitor for PSoC 4A-S and PSoC 6 MCU family of devices. For PSoC 4A, PSoC 4A-L, and PSoC 4A-M family of devices, the shield tank capacitor does not prove very advantageous because it doubles the shield series resistance. It is recommended to keep this option disabled for these device families.

###### Shield electrode delay

For proper operation of the shield electrode, the shield signal should match the sensor signal in phase. Due to the difference in trace lengths of the sensor and shield electrodes, the shield waveform may arrive earlier to the sensor waveform. You can use an oscilloscope to view both sensor and shield signals to verify this condition. If they are not aligned, use this option to add delay to the shield signal to align the two signals. Available delays vary depending on the device selected.

###### Shield SW resistance

This parameter controls the shield signal rise and fall times to reduce EMI. This parameter is valid only for PSoC 4 S-Series, PSoC 4100S Plus, PSoC 4100PS, and PSoC 6 MCU family of devices. The default value of shield switch resistance is Medium. shows the effect of the Shield SW resistance value. You should select this value based on the application requirement; in addition, ensure that it satisfies the conditions in Shield electrode tuning theory.

Table 10. Shield SW resistance selection guidelines
Lower switch resistance Higher switch resistance

Large overshoot error

Higher electromagnetic emission

Faster settling time that is, higher maximum sense clock frequency

Smaller overshoot error

Lower electromagnetic emission

Slower settling time that is, lower maximum sense clock frequency

###### Number of shield electrodes

This parameter specifies the number of shield electrodes required in the design. Most designs work with one dedicated shield electrode; however, some designs require multiple dedicated shield electrodes for ease of PCB layout routing or to minimize the PCB real estate used for the shield layer. See Layout guidelines for shield electrode.

###### Inactive sensor connection

When the shield electrode is enabled for liquid-tolerant designs, or if you want to use shield to reduce the sensor parasitic capacitance, this option should be specified as “Shield”; otherwise, select “Ground”.

However, there is a risk of higher radiated emission due to inactive sensors getting connected to Shield. In such situations, use the CAPSENSE API to manually control inactive sensor connections. Instead of connecting all unused sensors to the shield, connect only the opposing inactive sensors or inactive sensors closer to the sensor being scanned to shield for reducing the radiated emission.

##### Selecting CAPSENSE™ software parameters

CAPSENSE software parameters govern the sensor status based on the raw count of a sensor. provides a list of CAPSENSE software parameters. These parameters apply to both CSD and CSX sensing methods. This section defines these parameters with the help of Baseline, and provides guidance on how to adjust these parameters for optimal performance of your design. shows the recommended values for the software threshold parameter and they are applicable for most of the designs. However, if there are any external noise present in the end system, you must modify these thresholds accordingly to avoid any sensor false trigger.

Table 11. CAPSENSE component widget threshold parameters
Sl. No. CAPSENSE component parameter name in PSoC Creator/ModusToolbox
1. Finger threshold
2. Noise threshold
3. Hysteresis
4. ON debounce
5. Sensor auto-reset
6. Low baseline reset
7. Negative noise threshold
Table 12. Recommended values for the threshold parameters
Sl. No. CAPSENSE threshold parameter Recommended value
1. Finger threshold 80 percent of signal
2. Noise threshold 40 percent of signal
3. Hysteresis 10 percent of signal
4. ON debounce 3
5. Low baseline reset 30
6. Negative noise threshold 40 percent of signal
###### Baseline

After tuning the CAPSENSE Component for a given CP, the raw count value of a sensor may vary gradually due to changes in the environment such as temperature and humidity. Therefore, the CAPSENSE Component creates a new count value known as baseline by low-pass filtering the raw counts. Baseline keeps track of, and compensates for, the gradual changes in raw count. The baseline is less sensitive to sudden changes in the raw count caused by a touch. Therefore, the baseline value provides a reference level for computing signal.

Figure 97. Raw count, baseline, and signal shows the concept of raw count, baseline, and signal.

###### Baseline update algorithm

To properly tune the CAPSENSE software, that is, the threshold parameters, it is important to understand how baseline is calculated and how the threshold parameters affect the baseline update.

Baseline is a low-pass-filtered version of raw counts. As Figure 98. Baseline update algorithm shows, baseline is updated by low-pass-filtering raw counts if the current raw count is within a range of () to (Baseline + Noise threshold). If the current raw count is higher than baseline by a value greater than noise threshold, baseline remains at a constant value equal to prior baseline value.

If the current raw count is below baseline minus negative noise threshold, baseline again remains constant at a value equal to prior baseline value for Low baseline reset number of sensor scans. If the raw count continuously remains lower than baseline minus noise threshold for low baseline reset number of scans, the baseline is reset to the current raw count value and starts getting updated again, as Figure 99. Low baseline reset shows.

###### Finger threshold

The finger threshold parameter is used along with the hysteresis parameter to determine the sensor state, as Figure 100. Sensor state shows.

Note: Signal in the above equation refers to the difference: raw count – baseline, when the sensor is touched, as Figure 97. Raw count, baseline, and signal shows.

It is recommended to set finger threshold to 80 percent of the signal. This setting allows enough margin to reliably detect sensor ON/OFF status over signal variations across multiple PCBs.

###### Hysteresis

The hysteresis parameter is used along with the finger threshold parameter to determine the sensor state, as Figure 100. Sensor state and Figure 101. Hysteresis show. Hysteresis provides immunity against noisy transitions of sensor state. The hysteresis parameter setting must be lower than the finger threshold parameter setting. It is recommended to set hysteresis to 10 percent of the signal.

###### Noise threshold

For single-sensor widgets, such as buttons and proximity sensors, the noise threshold parameter sets the raw count limit above which the baseline is not updated, as Figure 98. Baseline update algorithm shows. In other words, the baseline remains constant as long as the raw count is above baseline + noise threshold. This prevents the baseline from following raw counts during a finger touch.

The noise threshold value should always be lower than the finger threshold – hysteresis. It is recommended to set noise threshold to 40 percent of the signal.

If the noise threshold is set to a low value, the baseline will remain constant if raw counts suddenly increase by a small amount, say because of small shifts in power supply or shifts in ground voltage because of high GPIO sink current and so on.

On the other hand, if the noise threshold is set to a value close to finger threshold – hysteresis, the baseline may keep updating even when the sensor is touched. This will lead to reduced signal
Note: (signal = raw count – baseline) and the sensor state may not be reported as ON.
###### Negative noise threshold

The negative noise threshold parameter sets the raw count limit below which the baseline is not updated for the number of samples specified by the low baseline reset parameter as Figure 99. Low baseline reset shows.

Negative noise threshold ensures that the baseline does not fall low because of any high amplitude repeated negative noise spikes on raw count caused by different noise sources such as electrostatic discharge (ESD) events.

It is recommended to set the negative noise threshold parameter value to be equal to the noise threshold parameter value.

###### Low baseline reset

This parameter is used along with the negative noise threshold parameter. It counts the number of abnormally low raw counts required to reset the baseline as Figure 99. Low baseline reset shows.

If a finger is placed on the sensor during device startup, the baseline is initialized to the high raw count value at startup. When the finger is removed, raw counts fall to a lower value. In this case, the baseline should track the low raw counts. The Low Baseline Reset parameter helps to handle this event. It resets the baseline to the low raw count value when the number of low samples reaches the low baseline reset number.
Note: In this case, when the finger is removed from the sensor, the sensor will not respond to finger touches for a low baseline reset time given by Figure 102. Low baseline reset time.

The low baseline reset parameter should be set to meet following conditions:

• Low baseline reset time is greater than the time for which negative noise (due to noise sources such as ESD events) is expected to last
• Low baseline reset time is lower than the time in which a sensor is expected to start responding again after the finger kept on sensor during device startup is removed from the sensor

The low baseline reset parameter is generally set to a value of 30.

###### Debounce

This parameter selects the number of consecutive CAPSENSE scans during which a sensor must be active to generate an ON state from the component. Debounce ensures that high-frequency, high-amplitude noise does not cause false detection.

The Debounce parameter impacts the response time of a CAPSENSE system. The time it takes for a sensor to report ON after the raw counts value have increased above finger threshold + hysteresis because of finger presence, is given by Figure 104. Relationship between debounce and sensor response time.

The Debounce parameter is generally set to a value of ‘3’ for reliable sensor status detection. It can be raised or lowered based on the noise aspects of the end user system.

###### Sensor auto reset

Enabling the Sensor Auto Reset parameter causes the baseline to always update regardless of whether the signal is above or below the noise threshold.

When auto reset is disabled, the baseline only updates if the current raw count is within a range of (Baseline – Negative Noise Threshold) to (Baseline + Noise Threshold) as Figure 98. Baseline update algorithm shows and the Baseline update algorithm describes. However, when Auto Reset is enabled, baseline is always updated if the current raw count is higher than (Baseline – Negative Noise Threshold) as Figure 105. Baseline update with sensor auto reset enabled shows.

Because the baseline is always updated when sensor auto reset is enabled, this setting limits the maximum time duration for which the sensor will be reported as pressed. However, enabling this parameter prevents the sensors from permanently turning on if the raw count suddenly rises without anything touching the sensor. This sudden rise can be caused by a large power supply voltage fluctuation, a high-energy RF noise source, or a very quick temperature change.

Enable this option if you have a problem with sensors permanently turning on when the raw count suddenly rises without anything touching the sensor.

###### Multi-frequency scan

Enabling multi-frequency scan, the CAPSENSE component performs a sensor scan with three different sense clock frequencies and obtains corresponding difference count. The median of the sensor difference-count is selected for further processing. Use this feature for robust operation in the presence of external noise at a certain sensor scan frequency. This option is not available in SmartSense Full Autotune mode. See the code example CE227719 CAPSENSE with multi-frequency scan.

##### Button widget tuning

Figure 106. CSD button widget tuning flowchart illustrates an overview of the CSD button tuning procedure.

Attention: For fifth-generation CAPSENSE, change number of sub-conversions (NSub) instead of resolution.

To review the hardware design, see the Sensor construction and PCB layout guidelines sections in the Design considerations chapter. Also, see the Tuning debug FAQs section for guidelines on advanced debug.

As explained in Selecting between SmartSense and manual tuning, Manual tuning requires effort to tune optimum CAPSENSE parameters, but allows strict control over characteristics of capacitive sensing system, such as response time and power consumption. The button is tuned for reliable touch detection to avoid false triggers in noisy environment.

The CE230926 PSoC 4: CAPSENSE CSD button tuning explains tuning of self-capacitance based button widgets in the Eclipse IDE for ModusToolbox using the CAPSENSE Tuner GUI. For details on the Component and all related parameters, see the Component datasheet.

##### Slider widget tuning

A slider has many segments, each of which is connected to the CAPSENSE input pins of the PSoC device. Unlike the simple on/off operation of a button widget sensor, slider widget sensors work together to track the location of a finger or other conductive object. Because of this, the slider layout design should ensure that the CP of all the segments in a slider remain as close as possible. Keeping similar CP values between sensors will help minimize the tuning effort and ensure an even response across the entire slider. See Slider design for details on slider layout design guidelines to avoid nonlinearity in the centroid, ensure that the signal from all the slider segments is equal, as Figure 107. Response of centroid versus finger location when signals of all slider elements are equal shows, when a finger is placed at the center of the slider segment. If the signal of the slider segments is different, then the centroid will be nonlinear, as Figure 108. Response of centroid versus finger location when the signal of all slider elements are different shows.

Note: In PSoC Creator and in ModusToolbox, a centroid of 0xFFFF and 0x0000 is reported respectively when a finger is not detected on the slider, or when none of the slider segments report a difference count value greater than the Finger Threshold parameter.
Note: Signal = Raw Count – Baseline

A linear response for the reported finger position (that is, the Centroid position) versus the actual finger position on a slider requires that the slider design is such that whenever a finger is placed anywhere between the middle of the segment SLDn and middle of segment SLDn-1, other than the exact middle of slider segments, exactly two sensors report a valid signal 9. If a finger is placed at the exact middle of any slider segment, the adjacent sensors should report a difference count = noise threshold. These conditions are required since the centroid position calculation is based on the closest segment to the finger and two neighboring segments as shown in Figure 109. Centroid algorithm used by CAPSENSE component in PSoC .

Where,

Resolution = API resolution set in the CAPSENSE Component Customizer

n = Number of sensor elements in the CAPSENSE Component Customizer

x = Index of element which gives maximum signal

si = Different counts (with subtracted noise threshold value) of the slider segment

Figure 110. CSD slider widget tuning flowchart shows an overview of the CSD slider tuning procedure.

Attention: For fifth-generation CAPSENSE, change number of sub-conversions (NSub) instead of resolution.

The upper crossover point (UCP) and lower crossover point (LCP) are obtained as shown inFigure 111. Difference count (delta) vs finger position. Refer to CE229521 – PSoC 4 CAPSENSE CSD Slider tuning which demonstrates how to manually tune a self-capacitance based Slider widget on PSoC Creator and CE230493 – PSoC 4: CAPSENSE CSD Slider tuning on Eclipse IDE for ModusToolbox.

9 Here, a valid signal means that the difference count of the given slider segment is greater than or equal to the noise threshold value.

A self-capacitance-based touchpad is essentially two sliders implemented in the horizontal and vertical directions. Hence, it is also tuned in a similar way as that of a slider, to obtain an even response across the trackpad/touchpad. To gain true multi-touch performance, it is recommended to use mutual-capacitance based touchpad. The centroid algorithm obtains the signals (diff-counts) from all the segments and calculates the x and y position co-ordinates.

The CSD Touchpad reuses Slider’s centroid algorithm that is applied individually to row and column sensors treated as simple sliders. Hence, the centroid position calculation formula for CSD Touchpad is same as Figure 109. Centroid algorithm used by CAPSENSE component in PSoC .

###### CSD finger detection criteria

The touch in a CSD Touchpad is reported to the host when the following Finger detection criteria is satisfied:

Where,

Z_Peak = Maximum Signal when the finger is present at the centre of the sensor

Z3_sum = Sum of Signals of segment with maximum signal and two neighboring segments

Z3_Filt_Scale = (0.8 * Z3_Sum)/Finger Threshold

The Z3_Filt_Scale value ensures that the detected object is of the correct proportions.

Z3_sum (of both row and column) condition is checked to see if the absolute mass of the finger is large enough to be recognized as a finger. The Z3_sum condition may prevent noise-induced false touches.

Figure 113. CSD touchpad widget tuning flowchart shows an overview of the CSD touchpad tuning procedure.

Attention: For fifth-generation CAPSENSE, change number of sub-conversions (N­Sub) instead of resolution.

LTI measures the peak diff-count when a finger touch is centered between four sensors. The LTI signal count is the average of the four peak sensors. This gives the least valid touch signal.

9 Here, a valid signal means that the difference count of the given slider segment is greater than or equal to the noise threshold value.

#### CSX sensing method (third- and fourth-generation)

This chapter explains the basics of manual tuning using the CSX sensing method. It also explains the hardware parameters that influence a manual tuning procedure.

##### Basics

###### Conversion gain and CAPSENSE signal

In a mutual-capacitance sensing system, the Rawcountcounter is directly proportional to the mutual-capacitance between the Tx and Rx electrodes, as Figure 114. Raw count relationship to sensor capacitance shows.

Where,

GCSX = Capacitance to digital conversion gain of CAPSENSE CSX

CM = Mutual-capacitance between the Tx and Rx electrodes.

Figure 119. Raw count vs Sensor mutual-capacitance shows the relationship between raw count and mutual capacitance of the CSX sensor. The tunable parameters of the conversion gain in Figure 115. Capacitance to digital converter gain are FTX , NMOD , FMOD and IDAC.

The approximate value of this conversion gain is:

Where,

VTX = Voltage at the Tx node of the sensor as shown in Figure 117. Voltage at Tx node of the CSX sensor

The value of VTX is always VDDIO or VDDD (if VDDIO is not available) if the Tx clock frequency can completely charge and discharge the Tx electrode. FTX is the Tx clock frequency, IDAC is the current drawn for charging and discharging the CINT capacitors, and Nsub is the number of sub-conversions.

Note: The raw count observed from the Component is given by Figure 118. RawcountComponent. See CAPSENSE CSX sensing method (third- and fourth- generation) for more details on Rawcountcomponent.
##### Selecting CAPSENSE™ hardware parameters

CAPSENSE hardware parameters govern the conversion gain and. lists the CAPSENSE hardware parameters that apply to the CSX sensing method. also shows the mapping of each parameter in the PSoCCreator CAPSENSE component to the one in the ModusToolbox middleware. For simplicity of documentation, this design guide shows selecting the CAPSENSE parameter using the CAPSENSE configurator in PSoC Creator. The same procedure could be followed in configuring CAPSENSE in ModusToolbox. However, in ModusToolbox, you set the Tx clock and Modulator clock using divider values. On the other hand, in PSoC Creator, you specify the frequency value directly in the configurator. See Component datasheet/middleware document.

Table 13. CAPSENSE signal component hardware parameters
Sl # CAPSENSE parameter in PSoC Creator CAPSENSE parameter in ModusToolbox
1 Modulator clock frequency Modulator clock divider
2 Tx clock source Tx clock source
3 Tx clock frequency Tx clock divider
4 IDAC IDAC
5 Number of sub-conversions Number of sub-conversions
###### Tx clock parameters

There are two parameters that are related to the Tx clock: Sense clock source and Sense clock frequency.

###### Tx clock source

Select “Auto” to let the Component automatically choose the best Tx clock source between Direct and Spread spectrum clock (SSCx) for each widget. If not selecting Auto, select the clock source based on the following:

• Direct – Clock signal with a fixed clock frequency. Use this option for most cases
• Spread spectrum clock (SSCx) – If you chose this option, the Tx clock signal frequency is dynamically spread over a predetermined range. Use this option for reduced EMI interference and avoiding Flat-spots

However, when selecting SSCx clock, you need to select the Tx clock frequency, Modulator clock frequency, and number of sub conversion such that the conditions mentioned in Component datasheet/ModusToolbox CAPSENSE configurator guide for SSCx clock source selection are satisfied.

###### Tx clock frequency

The Tx clock frequency determines the duration of each sub-conversion as explained in the CAPSENSE CSX sensing method (third- and fourth- generation) Chapter. The Tx clock signal must completely charge and discharge the sensor parasitic capacitance; it can be verified by checking the signal in an oscilloscope, or it can be set using the Figure 120. Condition for selecting Tx clock frequency. In addition, you should ensure that the auto-calibrated IDAC code lies in the mid-range (for example, 30-90) for the selected . If the auto-calibrated IDAC code lies out of the recommended range, tune such that it IDAC falls in the recommended range and satisfies Figure 120. Condition for selecting Tx clock frequency.

To minimize the scan time, as Figure 121. Scan time of CSX sensor shows, it is recommended to use the maximum Tx clock frequency available in the component drop-down list that satisfies the criteria.

Where, NSub = Number of sub-conversions.

Additionally, if you are using the SSCx clock source, ensure that you select the Tx clock frequency that meets the conditions mentioned in Component datasheet/middleware document/ModusToolbox CAPSENSE configurator guide in addition to these conditions.

The maximum value of FTX depends on the selected device. For the PSoC 4 S-Series, PSoC 4100S Plus, PSoC 4100PS, and PSoC 6 MCU family of devices, the maximum FTX is 3000 kHz and for other devices it is 300 kHz.

###### Modulator clock frequency

It is best to choose the highest allowed clock frequency for the given device because a higher modulator clock frequency leads to a higher sensitivity/signal, increased accuracy, and lower noise for a given CM to digital count conversion as Figure 93. PRS sequence period and Figure 94. Sense clock maximum frequency indicate. Also, a higher value of Fmod/Ftx ensures lower width of Flat-spots in CM to raw count conversion.

###### IDAC

It is recommended to enable IDAC auto-calibration. It is best to avoid very high and very low IDAC codes. The recommended IDAC code range is between 30-90. If the IDAC values are away from the recommended range, tune the Tx clock frequency to adjust the IDAC level. If the IDAC is failing to calibrate properly, it may be due to low CM in the design. Refer to the section I am observing a low CM for my CSX button for mitigating impact of low CM in the design.

###### Number of sub-conversions

The number of sub-conversions decides the sensitivity of the sensor and sensor scan time. From Figure 57. Raw count relationship for mutual-capacitance sensing for a fixed modulator clock and Tx clock, increasing the number of sub-conversions (NSub) increases the signal and SNR. However, increasing the number of sub-conversions also increases the scan time of the sensor per Figure 122. CSX scan time.

Initially, set the value to a low number (for example, 20), and use the Tuner GUI to find the SNR of the sensor. If the SNR is not > 5:1 with the selected NSub, try to increase the NSub in steps such that the SNR requirement is met.

##### Selecting CAPSENSE™ software parameters

CAPSENSE software parameters for mutual-capacitance are the same as that for self-capacitance; therefore, these parameters could be selected as mentioned in the section Selecting CAPSENSE software parametersSelecting CAPSENSE software parameters.

##### Button widget tuning

Figure 123. CSX button widget tuning example illustrates an overview of the CSX button tuning procedure.

* To review the hardware design, see the Sensor construction and PCB layout guidelines sections in the Design considerations chapter. Also, see the Tuning debug FAQs section for guidelines on advanced debug

The CE230660 PSoC 4: CAPSENSE CSX button tuning explains tuning of mutual-capacitance based button widgets in the Eclipse IDE for ModusToolbox and CE228931 – PSoC 4 CAPSENSE CSX button tuning in PSoC Creator using the CAPSENSE tuner. For details on the Component and all related parameters, see the Component datasheet.

Mutual-capacitance based touchpad widget supports up to three simultaneous finger touches. A slightly different Centroid algorithm compared to CSD touchpad is applied in a CSX touchpad widget. A 3x3 algorithm is used for calculating the X and Y position using Centroid algorithm as shown in Figure 124. Calculating X-position using centroid algorithm in CSX touchpad and Figure 125. Calculating Y-position using centroid algorithm in CSX touchpad respectively.

Where,

ResolutionX = Maximum X-axis position

nx = Number of sensor elements in the X-direction

x = Index of element which gives maximum signal

Sx+1 = Sum of three neighbor elements at the left from maximum (x)

Sx-1 = Sum of three neighbor elements at the right from maximum (x)

S3x3 = Total sum of 3x3 difference array

Where,

ResolutionY = Maximum Y-axis position

ny = Number of sensor elements in the Y-direction

y = Index of element which gives maximum signal

Sy+1 = Sum of three neighbor elements at the top from maximum (y)

Sy-1 = Sum of three neighbor elements at the bottom from maximum (y)

###### CSX finger detection criteria

The touch in a CSX touchpad is reported to the host when the following Finger detection criteria is satisfied:

1. Z_Peak > Finger threshold ± Hysteresis
2. Z9_Sum condition
• Z9_Sum > ((Finger threshold + Hysteresis) * Z9_Filt_Scale) (At panel core)
• Z9_Sum > ((Finger threshold + Hysteresis) * Z9_Filt_Scale/2) (At panel edge)
• Z9_Sum > ((Finger threshold + Hysteresis) * Z9_Filt_Scale/4) (At panel corner)
3. Z8_sum condition
• Z8_sum > Z_peak * Z8_Filt_Scale (At panel core)
• Z8_sum > Z_peak * Z8_Filt_Scale/2 (At panel edge)
• Z8_sum > Z_peak * Z8_Filt_Scale/4 (At panel corner)

Where,

Z_peak = Maximum signal obtained

Z9_sum = Total sum of 3x3 difference array

Z8_sum = Z9_Sum – Z_peak

Z9_Filt_Scale = (0.8 * Z9_Sum)/Finger threshold

Z8_Filt_Scale = (0.8 * Z8_Sum)/Finger threshold

These values ensure that the detected object is of the correct proportions.

• Z8_sum condition is checked to see if the relative mass of the finger is large enough to be recognized as a finger. This is done to discard very high noise in a segment, when the neighbouring sensors have no signal detected
• Z9_sum condition is checked to see if the absolute mass of the finger is large enough to be recognized as a finger. Similar to the Z8 condition, the Z9 condition may prevent noise-induced false touches

Figure 127. CSX touchpad widget tuning flowchart illustrates an overview of the CSX touchpad tuning procedure.

LTI measures the peak diff-count when a finger touch is centered between the four sensors. The LTI signal count is the average of the four peak sensors. This gives the least valid touch signal.

#### CSD-RM sensing method (fifth-generation)

This chapter explains the basics of manual tuning using CSD-RM sensing method (Fifth-Generation). It also explains the hardware and software parameters that influence the CSD-RM sensing method and the procedure of manual tuning for button, slider, touchpad and proximity widgets.

##### Basics

###### Conversion gain and CAPSENSE™ signal

Conversion gain will influence how much signal the system sees for a finger touch on the sensor. If there is more gain, the signal is higher, and a higher signal means a higher achievable Signal-to-noise ratio (SNR).
Note: An increased gain may result in an increase in both signal and noise. However, if required, you can use firmware filters to decrease noise. For details on available firmware filters, see .
###### Conversion gain in single CDAC

In the single CDAC mode, the raw count is directly proportional to the sensor capacitance.

Where,

CS = Sensor capacitance

CS = CP if there is no finger present on sensor

CS = (CP + CF) when there is a finger present on the sensor

GCSD = Capacitance to digital conversion gain of CAPSENSE CSD. The approximate value of this conversion gain according to Figure 64. CSD-RM single CDAC raw count and Figure 128. Raw count relationship to sensor capacitance is shown using Figure 129. Capacitance to digital converter gain.

Where,

The equation for raw count in the single CDAC mode, according to Figure 129. Capacitance to digital converter gain and Figure 128. Raw count relationship to sensor capacitance is shown in Figure 130. Single CDAC mode raw counts.

Where,

NSub = Number of sub-conversions

SnsClkDiv = sense clock divider

CS = Sensor capacitance

Cref = Reference capacitance

RefCDACCode = Reference CDAC value

The tunable parameters of the conversion gain are Cref, SnsClkDiv, and NSub. Figure 131. Raw count versus sensor capacitance shows a plot of raw count versus sensor capacitance.

The change in raw counts when a finger is placed on the sensor is called CAPSENSE signal. Figure 132. Signal values for different conversion gains shows how the value of the signal changes with respect to the conversion gain.

Figure 132. Signal values for different conversion gains shows three plots corresponding to three conversion gain values GCSD3, GCSD2, and GCSD1. An increase in the conversion gain results in higher signal value. However, this increase in the conversion gain also moves the raw count corresponding to CP (that is, Baseline) towards the maximum value of raw count (Maxcount). For very high gain values, the raw count saturates as the plot of GCSD3 shows. Therefore, tune the conversion gain to get a good signal value while avoiding saturation of raw count. Tune the CSD-RM parameters such that when there is no finger on the sensor, that is when CS = CP, the raw count = 85% of Maxcount as Figure 133. Recommended tuning shows. This ensures maximum gain, with enough margin for the raw count to grow because of environmental changes, and not saturate on finger touches.

###### Conversion gain in dual CDAC mode

The equation for raw count in the dual CDAC mode, according to Figure 65. CSD-RM dual CDAC raw count and Figure 128. Raw count relationship to sensor capacitance is shown in Figure 134. Dual CDAC mode raw counts.

Where,

Maxcount = NSub * SnsClkDiv

SnsClkDiv = Sense clock divider

NSub = Number of sub-conversions

Cref = Reference capacitance

Ccomp = Compensation capacitance

CompCLKDiv = CDAC compensation divider

CS = Sensor capacitance

Cref = RefCDACCode * Clsb

Ccomp=CompCDACCode * Clsb

RefCDACCode = Reference CDAC value

CompCDACCode = Compensation CDAC value

Clsb = 8.86fF

GCSD is given by Figure 129. Capacitance to digital converter gain.

In both single CDAC and dual CDAC mode, tune the CSD-RM parameters, so that when there is no finger on the sensor, that is when CS = CP, the raw count = 85% of Maxcount, as Figure 135. Recommended tuning in dual CDAC mode shows, to ensure high conversion gain, to avoid Flat-spots, and to avoid raw count saturation due to environmental changes.

As Figure 135. Recommended tuning in dual CDAC mode shows, the 85% requirement restricts to a fixed gain in single-CDAC mode, while in dual-CDAC mode, gain can be increased by moving the CS axis intercept to the right (by increasing CompClkDIV) and correspondingly decreasing the modulator CDAC switching (SnsClkDIV) to still achieve raw count = 85% of Maxcount for CS = CP. Using dual CDAC mode this way brings the following changes to the Raw Count versus CP graph:
• Use of compensation CDAC introduces a non-zero intercept on the CS axis as shown in Figure 136. CS axis intercept with regards to Ccomp
• The value of Cref in the dual CDAC mode is half compared to the value of Cref in the single CDAC mode (all other parameters remaining the same), so the gain GCSD in the dual CDAC mode is double the gain in the single CDAC mode according to Figure 82. Capacitance to digital converter gain. Thus, the signal in the dual CDAC mode is double the signal in the single CDAC mode for a given number of sub-conversions (Nsub).

While manually tuning a sensor, refer Figure 82. Capacitance to digital converter gain, Figure 87. Dual IDAC mode raw counts and the following points:

1. Higher gain leads to increased sensitivity and better overall system performance. However, do not set the gain such that raw counts saturate, as the plot of gain GCSD3 shows in Figure 85. Signal values for different conversion gains. It is recommended to set the gain in such a way that the raw count corresponding to CP is 85 percent of the maximum raw count for both the single CDAC and dual CDAC mode
2. The sense clock frequency (FSW) should be set carefully; higher the frequency, higher the CS sampling rate which allows for more FSW periods and better noise averaging, but the frequency needs to be low enough to fully charge and discharge the sensor as Figure 94. Sense clock maximum frequency indicates
3. Enabling the compensation CDAC (baseline compensation) plays a huge role In increasing the gain; it will double the gain if set as recommended in Conversion gain in dual CDAC mode. Always enable Compensation CDAC, make sure the calibrated Cref is in valid range when enabling Compensation CDAC
4. Lower the reference CDAC, higher the gain. Adjust your CDAC to achieve the highest gain, but make sure that the raw counts corresponding to CP have enough margin for environmental changes such as temperature shifts, as indicated in Figure 86. Recommended tuning and Figure 88. Recommended tuning in dual IDAC mode
5. Increasing the number of sub-conversions used for scanning increases gain. An increase in number of sub-conversions also increases the scan time according to Figure 49. Sensor scan time. A balance of scan time and gain need to be achieved using number of sub-conversions (Nsub)
###### Flat-spots

Ideally, raw counts should have a linear relationship with sensor capacitance as Figure 84. Raw count versus sensor capacitance and Figure 88. Recommended tuning in dual IDAC mode show. However, in practice, RM converter has non-sensitivity zones, also called flat-spots or dead-zones – for a range of sensor capacitance values, the RM converter may produce the same raw count value as Figure 138. Flat-spots in raw counts versus sensor capacitance when direct clock is used shows. This range is known as a dead-zone or a flat-spot.

Figure 137. Flat-spots width shows the flat-spots relation to different CAPSENSE hardware parameters.

Where,

CS = Sensor capacitance

CMOD = Modulator capacitor

FSW = Frequency of the sense clock

FMOD = Modulator clock frequency

Bal% = Rawcount calibration percentage

###### Flat-spots reduction techniques

1. Set rawcount calibration to 85%

As per Figure 137. Flat-spots width, flat-spots width is inversely proportional to calibration level. Setting calibration to 85% decrease the width of flat-spots significantly.

2. Enable dithering

An additional Dither CDAC is available in Fifth-Generation CAPSENSE architecture, which adds white noise that moves the conversion point around the flat-spots region.

3. Enable PRS clock

These flat-spots are prominent when direct clock is used as Sense Clock source. Flat-spots are reduced if PRS is used as the sense clock source (see also section Using SmartSense to determine hardware parameters). PRS clock can results in a slight reduction of signal or sensitivity at higher rawcount calibration. Recommended to set the rawcount calibration to 65% when PRS is used as clock source.

4. Use larger CMOD

The flat-spots width is inversely proportional to the CMOD used. Fifth-Generation architecture supports CMOD upto 10 nF and typical value is 2.2 nF. And increasing CMOD have the adverse effect of increasing the noise, initialization time and minimum signal required to detect.

5. Increase sense clock divider

Increasing sense clock divider decreases flat-spots width but increases the scan time. If the flat-spot is detected, increase the Sense clock divider such that the scan time requirement is met.

lists different the flat-spots reduction techniques in recommended priority and other considerations.

Table 14. Flat-spots reduction techniques
1 Set rawcount calibration to 85%. High Improves sensitivity -
2 Enable dithering High - -
3 Enable PRS clock Low Improves EMI/EMC radiation and susceptibility

Needs to set rawcount calibration to 65%.

Decreases sensitivity.

4 Increase CMOD Low - Increases noise
5 Increase sense clock divider Low - Increases scan time
##### Selecting CAPSENSE™ hardware parameters

CAPSENSE hardware parameters govern the conversion gain and CAPSENSE signal. lists the CAPSENSE hardware parameters that apply to CSD-RM sensing method. The following subsections provide guidance on how to adjust these parameters to achieve optimal performance for CAPSENSE CSD-RM system.

Table 15. CAPSENSE component hardware parameters
S. No CAPSENSE parameter in ModusToolBox
1 Scan mode
2 Scan connection method
3 Number of Init sub-conversions
4 Sense clock divider
5 Sense clock source
6 Modulator clock divider
7 Reference CDAC value
8 CDAC compensation divider
9 Compensation CDAC value
10 Number of sub-conversions
11 Enable CDAC dither

5.3.4.2.1 and 5.3.4.2.2 show selecting the CAPSENSE parameters in Eclipse IDE for ModusToolbox. For more details on configuring CAPSENSE, see the Component datasheet/middleware document.

###### Using SmartSense to determine hardware parameters

lists the CAPSENSE hardware parameters. Tuning these parameters manually for optimal value is a time-consuming task. You can use SmartSense to determine these hardware parameters and take it as an initial value for manual tuning. You can fine-tune these values to further optimize the scan time, SNR, power consumption, or improving EMI/EMC capability of the CAPSENSE system. Set the tuning mode to SmartSense and configure default values for parameters other than finger capacitance, Sense clock source and CDAC dither. Set these as per the application requirement.

See the SmartSense section for the tuning procedure and use the Tuner GUI to read back all the hardware parameters set by SmartSense. See the CAPSENSE tuner guide for more details on how to use the Tuner GUI.

Figure 139. Read-back hardware parameter values in tuner GUI shows the best hardware parameter values in the Tuner GUI that are tuned by SmartSense for a specific hardware to sense a minimum finger capacitance of 0.1 pF.

###### Scan mode

Scan mode can be set as CS-DMA or Interrupt Driven mode. For autonomous scanning select DMA mode and for legacy interrupt based scanning select Interrupt Driven mode.

###### Sensor connection method

Autonomous scanning is only available in CTRLMUX method, but the numbers of supported pins are limited in this method (see the Device datasheet for supported pins). Additionally provides better immunity to on-chip IO noise. Choose AMUXBUS method to support more number of pins in Interrupt Driven mode.

###### Modulator clock frequency

The modulator clock governs the conversion time for capacitance-to-digital conversion, also called the “sensor scan time” (see Figure 49. Sensor scan time).

A lower modulator clock frequency implies the following:

Select the highest frequency for the shortest conversion time and narrower flat-spots for most cases. Use slower modulator clock to reduce peak-to-peak noise in raw counts if required.

Based on the required Modulator clock frequency (FMOD), calculate the modulator clock divider using Figure 140. Modulator clock divider.

Where,

FClock = Clock frequency connected to CAPSENSE block

###### Initialization sub-conversions

As part of initialization, CMOD1 and CMOD2 needs to be charged at required voltage (VDDA/2). There are three phases in initialization – CMOD initialization, CMOD short and initialization sub-conversions. During CMOD initialization phase CMOD1 is pulled to GND and CMOD2 is pulled to VDDA. During CMOD short phase both capacitors are tied together so the charge is shared to produce a voltage close to VDDA/2 on both. After the 2 phases the scanning is started but rawcount is discarded for number of init sub-conversions.

Number of init sub-conversions should be selected based on Figure 141. Number of init sub-conversions.

Where,

CMOD = Modulator capacitor

VOS = Comparator offset voltage (3 mV)

CS = Sensor capacitance

Base% = Baseline compensation percentage

Bal% = Rawcount calibration percentage

SnsClkDiv = sense clock divider

Cref = Reference capacitance

Cref = RefCDACCode * Clsb

RefCDACCode = Reference CDAC value

Clsb = 8.86 fF

###### Sense clock parameters

There are two parameters that are related to Sense clock: Sense clock source and Sense clock divider.

###### Sense clock source

Select “Auto” to let the Component automatically choose the best Sense clock source from Direct, PRSx, and SSCx for each widget. If not selecting Auto, select the clock source based on the following:

• Use SSCx (spread spectrum clock) modes for reducing EMI/EMC noise at a particular frequency. This feature is available in PSoC 4S-Series, PSoC 4100S Plus, PSoC 4100PS, PSoC 4100S Max and PSoC 6 family of devices. In this case, the frequency of the sense clock is spread over a predetermined range
• Use Direct clock for absolute capacitance measurement
• Use PRSx (pseudo random sequence) modes to remove flat-spots and improve EMI/EMC radiation and susceptibility. In 5th Generation CAPSENSE, PRS clock results in a slight reduction in signal/sensitivity at higher rawcount calibration percent, hence 65% rawcount calibration is recommended when PRS clock is used

When selecting SSCx, you need to select the Sense clock frequency, Modulator clock frequency, and number of sub-conversion such that the conditions mentioned in ModusToolbox CAPSENSE configurator guide for SSCx clock source selection are satisfied.

###### Sense clock divider

The sense clock divider should be selected so that the sensor will charge and discharge completely in each sense clock period as Figure 61. Voltage across sensor capacitance shows.
Note: For Fifth-Generation CSD-RM charging and discharging happens twice in a single clock period.

This requires that the maximum sense clock frequency be chosen per Figure 142. Sense clock maximum frequency.

Where,

Cp = Sensor parasitic capacitance

RSeriesTotal = Total series-resistance, including the Rinternal resistance of the internal switches, the recommended external series resistance of 560 Ω (connected on PCB trace connecting sensor pad to the device pin), and trace resistance if using highly resistive materials (example ITO or conductive ink).

Rinternal = Internal resistance, this varies based on scan and shield modes, see table .

Table 16. Internal resistance for sensor
Scan mode Rinternal
CTRLMUX 525 Ω
AMUXBUS 425 Ω

The value for CP can be estimated using the CSD Built-in-Self-test APIs. See the Component datasheet/middleware document for details.

To minimize the scan time, as Figure 144. Sensor scan time shows, it is recommended to use the maximum sense clock frequency (FSW) satisfies the criteria as per Figure 142. Sense clock maximum frequency.

Where,

NSub = Number of sub-conversions

Based on required sense clock frequency (FSW), the sense clock divider be chosen per Figure 145. Sense clock divider.

Figure 129. Capacitance to digital converter gain shows that it is best to use the maximum clock frequency to have a good gain ; however, you should ensure that the sensor capacitor fully charges and discharges as shown in Figure 61. Voltage across sensor capacitance. And keep in mind that higher clock frequency increases current consumption as there are more charging and discharging.

Generally, the CP of the shield electrode will be higher compared to sensor CP. For good liquid tolerance, the shield signal should satisfy the condition mentioned in Tuning shield electrode chapter . If it is not satisfied, reduce the sense clock frequency further to satisfy the condition.

###### Number of sub-conversions

The number of sub-conversions decides the sensitivity of the sensor and sensor scan time. From Figure 65. CSD-RM dual CDAC raw count for a fixed modulator clock and Sense clock, increasing the number of sub-conversions (NSub) increases the signal and SNR. However, increasing the number of sub-conversions also increases the scan time of the sensor per Figure 146. CSD-RM scan time.

Initially, set the value to a low number, and use the Tuner GUI to find the SNR of the sensor. If the SNR is not > 5:1 with the selected , try to increase the in steps such that the SNR requirement is met.

###### Capacitive DACs

Fifth-Generation CAPSENSE supports two CDACs: Reference CDAC (Cref) and Compensation CDAC (Ccomp) that balance CMOD’s as Figure 59. CAPSENSE CSD-RM (fifth-generation) shows. These govern the Conversion gain and CAPSENSE signal Conversion gain and CAPSENSE for capacitance-to-digital conversion. The CAPSENSE Component allows the following configurations of the CDACs:

• Enabling or disabling of Compensation CDACs
• Enabling or disabling of Auto-calibration for the CDACs
• Compensation CDAC divider, DAC code selection for Reference and Compensation CDACs if auto-calibration is disabled
###### Reference CDAC (Cref)

The reference CDAC is used to compensate the charge transfered by the sensor self-capacitance (CS) from CMOD. The number of times it is switched depends on the self-capacitance of sensor. In case of finger placed over the sensor, additional reference CDAC switching is required to compensate.

Cref should satisfy below critieria:

• For Compensation Disabled:

• For Compensation Enabled:

Where,

Cref = Reference capacitance = RefCDACCode * Clsb

RefCDACCode = Reference CDAC value

Clsb = 8.86 fF

###### Compensation CDAC (Ccomp)

Enabling the compensation CDAC is called “dual CDAC” mode, and results in increased signal as explained in Conversion gain and CAPSENSE signal. Enable the compensation CDAC for most cases.

The compensation capacitor is used to compensate excess self-capacitance from the sensor to increase the sensitivity. The number of times it is switched depends on the amount of charge the user application is trying to