mTouch® Button/Proximity Sensor Configuration

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

The Button or Proximity Sensor is an abstraction layer over the physical sensor which decouples the signal acquisition module and the decoding module. The benefit of this abstraction is that, regardless of what acquisition method is being used for the sensor, the Button or Proximity Sensor decoding works the same way.

Common Button/Proximity Sensor Configuration

Similar to the sensor configuration, the Button/Proximity Sensor also has a common section. The common Button settings area consists of 10 sub-areas:

  • Create New Button
  • Interface Method
  • Press Timeout
  • Negative Capacitance Recovery
  • Baseline Filtering
  • Reading
  • Debounce
  • Suspend / Disable
  • Reburst
  • Hysteresis

Common Settings panel for Buttons in mTouch GUI

The common Proximity Sensor has two extra sections: deviation integrator and median filter.

Common Settings for proximity sensors

Back to top

Create New Button/Proximity Sensor

The 'Create New Button/Proximity Sensor' tab in the Common Settings area allows for the creation of an additional button/proximity sensor for the mTouch® sensing solution project. When a new button/proximity sensor is created, the default name is Button#/Proximity#, where # is the lowest number not currently used.

Back to top

Interface Method

The mTouch Sensing Solutions library allows your application code to obtain button/proximity sensor status in two ways: through a callback function or through polling. There are examples of how to use these two methods in the "Step by Step Example" section.

Back to top

Press/Activation Timeout

Press/Activation Timeout is a mechanism used to release a stuck proximity sensor. If a button/proximity sensor is pressed or activated for a number of consecutive counts, the button’s or proximity sensor's state will be reset. Each button/proximity sensor has its own time-out counter to track the press time. The underlying press time-out counter will increment each time the MTOUCH_Service_Mainloop() call is performed. The counts parameter acts as a threshold to each button’s or proximity sensor's press time-out counter. Upon the time-out’s counter exceeding the counts value, the button/proximity sensor state will be reset.

Back to top

Baseline Filtering

The baseline of a touch button/proximity sensor is the output of a conditionally low-pass filter and the input of this low pass filter is the button’s or proximity sensor's raw reading. This allows the baseline to track and react to environmental changes such as temperature and humidity. Upon a button entering a pressed state, the baseline will stop updating until released.

The filter gain parameter determines the baseline filtering strength. The larger the value, the stronger the filter gets, and the more slowly the baseline follows the button reading value.

The update parameter determines how often the system will update the button’s or proximity sensor's baseline. The larger the value, the less often the system updates the baseline.

Back to top

Negative Capacitance Recovery

Enabling this feature allows the quick recovery of a button’s or proximity's baseline if negative capacitance is detected. The negative capacitance means the baseline value is greater than the reading for a button. The consecutive decodes parameter specifies the number of consecutive decoding cycles (MTOUCH_Service_Mainloop() call) with negative capacitance that the program has to detect before resetting the button/proximity state.

Back to top

Reading Filter

To minimize the impact of impulse noise, the sensor output goes through a low-pass filter. The output of the filter is the reading of the button/proximity sensor. A higher filter level setting provides an improved signal-to-noise ratio (SNR) under noisy conditions while increasing the total time for measurement, possibly resulting in increased power consumption and response time.

Back to top

Deviation Integration Filter

To help the sensitivity of the proximity sensor, a deviation integrator is used. A larger gain value results in more sensitivity.

Back to top

Median Filter

To gain a greater SNR for the proximity sensor, a median filter can be used after the reading filter. The value of the median filter window decides how much historical data will be stored. Similar to the reading filter, a higher value provides more noise immunity but longer response time.

Back to top


To prevent multiple detect events for a single touch action, a debounce algorithm is used. The algorithm works in a similar manner to debounce on a mechanical pushbutton. The Count parameter defines the number of consecutive touches that exceed the detect threshold. Once the consecutive touch count is exceeded the touch is reported as valid. If any single touch does not exceed the touch threshold while the debounce algorithm is running then the consecutive touch count is reset to and the debounce algorithm will restart. The debounce algorithm is applied to both touch/press debounce and release debounce for buttons/proximity sensors.

Graph showing a touch event and how having the Debounce Count set to 10 avoids reporting the glitches.

Back to top

Suspend / Disable

Individual buttons and proximity sensors can now be suspended or disabled by application code.

  • Use MTOUCH_Button_Disable() / MTOUCH_Proximity_Disable() to disable a button / proximity sensor. A disabled button/proximity sensor will stop its sensor scanning and baseline updating.
  • Use MTOUCH_Button_Suspend() / MTOUCH_Proximity_Suspend() to suspend a button/proximity sensor. A suspended button/proximity sensor will stop its sensor scanning but will scan periodically for baseline updating.
  • Use MTOUCH_Button_Resume() / MTOUCH_Proximity_Resume() to reactivate a disabled/suspended button / proximity sensor. The button/proximity sensor will continue with the existing sensor configuration.

Back to top


Reburst is used to improve the system response time while resolving detect state for both buttons and proximity sensors. When a sensor threshold is exceeded, multiple measurements are taken on that sensor to resolve the detect status. Sensors that are not part of the AKSGroup or may be disabled to reduce the processing time. Three modes for Reburst are used:

  • Reburst All : No sensor suspension takes place, all sensors reburst to determine detect status.
  • Reburst Unresolved : Reburst sensors only part of same AKS Group, all others suspended (reduced processing).
  • Reburst None : standard acquisition only.

Back to top


Hysteresis provides a band gap for detect thresholds when moving between detect and no detect states. It is expressed as a percentage of the detect threshold. Once a sensor goes into detect, the threshold level is reduced (by the hysteresis % value). This prevents sensor dither in and out of detect if the signal level is close to original threshold level.

Graph showing how Hysteresis threshold avoids detection dithering when touch signal is close to the original detection threshold

Back to top

Individual Button/Proximity Sensor Configuration

The individual Button/Proximity Sensor Configuration allows you to set name, threshold, deviation scaling and AKS group for each individual button/sensor. The Delete Item button is used to remove the button/proximity sensor from the project.

Image showing individual button settings pane with delete button to remove sensor from project

Back to top


This input field allows you to modify the name of the selected button/proximity sensor. This name can be used in the code to reference this button/proximity sensor.

Back to top


This selection box allows you to select a hardware sensor to be associated with this button. A hardware sensor can be associated with multiple buttons/proximity sensors. For example, if you want to achieve proximity detection and touch detection on the same physical sensor, this sensor can be associated with a button and a proximity sensor.

Back to top


The signal deviation is defined as the difference between a button’s reading and the baseline value. The threshold input field allows you to determine the press threshold value for signal deviation before the button will be in the pressed state. The release threshold is 50% of the press threshold so that there is a hysteresis to release the button.

Graph showing sensor signal deviation over the threshold indicating a "touch" event

Back to top

Deviation Scaling

The signal deviation will be scaled down from a signed 16-bit integer to a signed 8-bit. If the deviation after scaling down is greater than 127, then the value will be clipped to 127 (0x7F). The deviation scaling parameter controls how many bits will shift to the right. The smaller the value is, the more sensitive the button will get. The goal is to shift the scaled-down deviation to be a value between 64 and 127 when the button is pressed, in order to get the full dynamic range.

Image showing how deviation scaling increases sensitivity

Back to top

AKS Group

AKS® stands for Adjacent Key Suppression. In designs where the sensors are placed close together or configured for high sensitivity, multiple buttons might report a detection simultaneously. To allow applications to determine the intended single touch, the mTouch library makes it possible to configure multiple buttons/proximity sensors in an AKS group. When a group of buttons/proximity sensors is in the same AKS group, only the first strongest button/proximity sensor will report detection. The button/proximity sensor continues to report detection until its deviation or delta falls below its detection threshold. As long as this sensor is in the pressed state, no other button/proximity sensors in the same AKS group will report detection even if another button/proximity sensor's deviation becomes stronger in the same AKS group.

Back to top

Individual Hysteresis

The common hysteresis levels can be replaced for each button/proximity sensor by activating the individual hysteresis checkbox. Then a hysteresis level can be selected from the dropdown menu. Other sensors will be assigned the common hysteresis level unless they are also modified.

Back to top