Software Library Support - Capacitive Touch Example Codes

There are several techniques for capacitive touch detection, the most common being Capacitive Voltage Division (CVD). For CVD, a Charge Time Measurement Unit (CTMU) is not needed and any ANx pin and analog-to-digital converter (ADC) channel that can connect to it will suffice. CVD sets up a square charging wave and measures the decay result, then averages some number of decay results and compares that to some threshold.

A very simple and clear example of CVD is one that we did not write, but it is written for our devices. See the following link for more information: > Code Examples > Sample Program No. 9: 'Use of the capacitive touch'.
You'll find a project called 'Touch.X' which you should be able to modify pretty easily to your 16-bit device and pin. That code is also quite easy to understand.

It's true that a wire is all that's needed in most cases, but usually, a pad is provided. A rule of thumb is about the size of a dime or a 15 mm square. A larger pad can be used but may be harder to balance sensitivity vs. noise. Application Note AN2098 explains the CVD theory pretty clearly.

If you still want to use CTMU, you should review Application Note AN1250. Basically, CTMU is more precise, so it can be used in ways that CVD cannot. For a simple button, it's usually not needed.

If you're thinking about metal-over-cap, see Application Note AN1626. For a comparison of methods, see Application Note AN1334.

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.