Hardware Sensor Configuration

Last modified by Microchip on 2023/11/09 08:55

The sensor configuration configures the Capacitive Voltage Divider (CVD) waveform, which is used to acquire the relative capacitance value of the sensor, and also the number of oversampling for each sensor. The differential CVD waveform is shown in Figure 1.

Capacitive Voltage Divider Waveform

Figure 1

There are two ADC samples being acquired. Each sample needs three phases: sensor pre-charge, sensor acquisition, and analog-to-digital conversion.

For more information about the CVD acquisition method, see Application Note "AN1478 mTouch™ Sensing Solution Acquisition Methods Capacitive Voltage Divider".

Back to top

Common Sensor Configuration

There is a common configuration section to set up all the sensors, as shown in Figure 2.

The Common Sensor Configuration view in the mTouch setup GUI

Figure 2

Some devices, including PIC16LF1554/9 and PIC16LF1566/7, have the feature to combine multiple channels internally to create a lumped sensor.

Back to top

Individual Sensor Configuration

Each sensor has its own configuration section to set up the sensor name, Pre-charge Time, Acquisition Time, and Oversampling value. The common configuration is assigned to each sensor by default. If the sensor has different physical conditions (parasitic capacitance, size of the sensor, etc..), you can enable the individual configuration for that sensor. To customize the settings for an individual sensor, select the sensor in the left hand panel of the GUI. That will bring up a panel that will allow you to customize the settings for that particular sensor as shown in Figure 3.

Individual sensor configuration view in mTouch setup GUI

Figure 3

Back to top

Sensor Creation

The sensor can be created and assigned to a specific pin using the pin manager grid view or package view as other MCC modules.

Sensor creation - lump sensor

Figure 4

For devices that can connect multiple channels internally, the lumped sensor is very useful for low power scan purposes, as it can scan multiple physical sensors as one big sensor in one shot instead of scanning them sequentially. Once you click the create button, a popup window will be shown in the accompanying image. It lists all the currently selected sensors for the two ADCs. You will be able to combine the sensors on the same ADC and note that AN0, AN1, and AN2 are shared between two ADCs, but cannot combine.

Lump Sensor dialog


Back to top

Sensor Sampling Configuration

Idle Sensor Pin State

The system scans one sensor at a time. The un-scanning sensor pins will be grounded (output low), which provides the lowest emission. For certain devices, it also has the capability of driving the un-scanning sensor pins as a driven shield waveform, which will provide the best moisture/water tolerance.

Back to top

Dedicated Driven Shield

This is a read-only text filed, indicating the dedicated driven shield pin that is selected in the pin manager grid view.

Back to top


This defines the number of ADC samples taken for each iteration of measurement. Higher oversampling settings mean more samples for each measurement, which removes the impact of non-harmonic noise, yet with higher oversampling settings each touch measurement takes longer, which affects response time.

Back to top

Sensor Waveform Configuration

Waveform Timing Unit

This is the time unit for the pre-charge and acquisition option below and will be device and system clock dependent.

Back to top

Pre-charge Time

This value determines the amount of time provided to charge the external sensor and the internal Sample&Hold capacitor of the ADC. If the value is too small, the sensor will not be as sensitive as it could be or even have inverted behavior when touching the sensor.

Back to top

Acquisition Time

This value determines the amount of time provided for the external sensor and internal hold capacitor to charge/average their voltages. This value is related to the RC time constant of the sensor and its series resistor. If the value is too small, so that the sensor charge is not fully settled before conversion, the sensor will not be as sensitive as it could be. If the value is too large, the noise immunity of the system will not be as robust as it could be because this time is also the time window for acquiring noise.

Back to top

Waveform Timing Graph

Clicking the button will open up a new window. The contents of this new window provide an estimate calculation of the scan waveform timing information in a graph, this helps to estimate the response time of the system. An example is shown in the accompanying image:

Waveform Timing Graph


Back to top

Additional Sample Capacitance

The value determines how much additional internal capacitance will be added to the Sample&Hold capacitor. This is used to improve the match between internal and external capacitance for better sensing performance. The general rule of thumb is to settle the voltage after acquisition time close to half of the VDD as much as possible. This option is only available on parts that have hardware CVD module.

Back to top


To ease the tuning process for the CVD waveform, the library supports auto-calibration for acquisition time and additional internal capacitance. The auto-calibration will perform for each sensor after power-up, timeout and negative capacitance detected events. This option is only available on parts that have hardware CVD module.

Back to top

Scan Rate Control

The capacitive sensors need to be scanned periodically, there are two options to control the scan rate: Free Running Mode, Timer 1 Scheduling Mode, and Timer 2 Scheduling Mode.

  • Free Running Mode: The sensor scan and post-processing will happen when the mTouch_Service_Mainloop( ) gets called, the timing is not precisely controlled, and will be determined by how often the application code calls the mTouch_Service_Mainloop( ).
  • Timer 1 Scheduling Mode: In this mode, Timer 1 will be added to the project automatically and will be used to schedule the scan rate in milliseconds. By default, Timer 1 has been configured to use LFINTOSC, which can operate during MCU Power Down mode. Any manual change to Timer 1 will affect the scan rate. The scheduling logic is implemented inside mTouch_Service_Mainloop( ) function, so there will be no change in the way of using the mTouch_Service_Mainloop( ). However, the mTouch_Service_Mainloop( ) needs to be called in a shorter time interval than the scheduled scan time. Otherwise, the scan rate will still be determined by how often the application code calls the mTouch_Service_Mainloop( ).
  • Timer 2 Scheduling Mode: This mode is similar to the Timer 1 Scheduling mode, but it has less firmware overhead. This is not available on all devices.

Back to top