Recently I started to work with mTouch CSM module. It sounded like extremely interesting and high performance hardware to work with. It sounded right!
there are countless applications for use of this hardware. Touch pad, proximity sensors, readout of capacitive sensors,extreme precision capacitance measurement, ultra small capacitance change detection, soil moisture, skin moisture measurement are just some of them.. But then I started to search for examples and I was surprised because there wasn't any!!!! At least not ones that was helpfull.. That is why I made this complete guide for capacitive sensing using excellent Microchip CSM module inside some of them microcontrollers.
The CSM simplifies the amount of hardware and software setup needed for capacitive sensing applications. Only the sensing pads on the Printed Circuit Board (PCB) need to be added. The capacitive sensing modules allow for an interaction with an end user without a mechanical interface.
Here is block schematic of SCM module
The capacitive sensing oscillator consists of a constant current source and a constant current sink, to produce a triangle waveform. On picture below you can see typical waveform recorded ad one of the touch pads while measured with Microchip CSM module.
To explain it simply upper current source feeds current into analog pin capacitance until voltage reaches Ref+. Then upper current source shuts down and lower current source engages. He sinks current from analog pin capacitance until voltage reaches Ref- and it all goes in circle. This is why we call it oscillator. Since it is constant current voltage is changing linearly which we can see on picture above.
The oscillator is designed to drive a capacitive load (single PCB pad) and at the same time, be a clock source to one of the timers. Cap Sense Oscillator A can be input of Timer1 and TimerA depending on configuration we make. I personally prefer Timer1 since it is 16 bit timer and it is easier to count bigger number of oscillations with it.
It has three different current settings as defined by appropriate registers. The different current settings for the oscillator serve two purposes:
• Maximize the number of counts in a timer for a fixed time base.
• Maximize the count differential in the timer during a change in frequency.
Current settings are divided into two groups. Low range that use internal reference voltages. This means you cannot change upper and lower voltage threshold in CSM oscillator. For touch screen purposes and when you do not need to know amount of capacitance you are reading this is ok. High range If you want to use this module as extra precise small capacitance meter that can measure capacitance order or ~fF (that is FEMTOFARAD!! ~10 E-15) then it is easier to do calculations when you can set precise voltage thresholds. Current source range group is selected by setting CPSxRM configuration bit
First group of Current source currents is called
Low range and values available are
- 0.1 µA 1.2 µA and 18 µA
High range currents are:
- 9 µA 30 µA and 100 µA
Selection between the voltage references is controlled by the CPSxRM bit of the CPSxCON0 register
When using high range currents beside usual setup you must enable and properly configure FVR (Fixed voltage reference) and integrated peripheral DAC Digital-to-analog convertor that is also placed inside this chip. As you can see it is easier to use low range currents but I prefer to use high current range because it gives you better control and readout stability when measuring capacity. The capacitive sensing oscillator will continue to run as long as the module is enabled, independent of the part being in Sleep. In order for the software to determine if a frequency change has occurred, the part must be awake. However, the part does not have to be awake when the timer resource is acquiring counts. When you configure all settings and you have your CSM module running you still need to measure CSM oscillator frequency. To measure the frequency of the capacitive sensing oscillator, a fixed time base is required. Any timer resource or software loop can be used to establish the fixed time base. It is up to the end user to determine the method in which the fixed time base is generated.
The fixed time base cannot be generated by the timer resource that the capacitive sensing oscillator is clocking. For our example Timer1 is dedicated to CSM module and therefore cannot be used for fixed time base measurement.
Let us make checklist of things you need to do to measure capacitance of CPSA module pin. In this example we will use Timer1 for counting CPSA module CSM oscillator.
For measuring its frequency we will use fixed time base created by Timer3. We will make check list for using high range current with Ref- voltage from DAC module which is more complex.
1. Turn Module on with CPSAON configuration bit
2. Choose current range used with CPSARM configuration bit
3. Choose current value with CPSARNG0 and CPSARNG1 bits
4. Select channel (microcontroller pin) that is being measured with CPSACON1 configuration register
5. Dedicate Timer1 to CSM module for counting oscillations by setting TMRCS0 and TMRCS1 bits
6. Configure Timer1 as normal timer operation. Only difference is that now its clock comes from CSM module instead of system clock. Set its Interrupt, prescaler, Disable External Clock Input Synchronization and Gate operation, Turn it on...
7. Enable FVR module and set its gain amplifier settings for the reference voltage of DAC.
8. Enable DAC, Set its reference voltage to FVR and make its output value. Notice this value will be used as Ref- Voltage in CSM oscillator. In this case positive voltage reference in this oscillator REF+ will be FVR value.
9. Enable some of remaining timers to measure fixed time period in which you will read how many oscillations from CSM oscillator Timer1 has counted. For example enable Timer3 to work and enable its interrupt.
10. You are ready to go, just on every interrupt of Timer3 get value of Timer1 (dedicated to CSM module) and reset it back to zero.
If you are wondering how to make hardware implementation of Touch button to read capacity from it, it is very simple. Since this module is very sensitive any shape and size will do. Best is to make it size of top of human finger (2cmx2cm). You experiment and you will see what get you best results.
Here is picture of one such pad connects via thin trace directly to microcontroller pin.
Now you have enough understanding of Microchip mTouch CSM module to start working with it.
I also made project and tested CSM function in practise. My ruff calculations are that when i aproach with finger to capacitive pad on pcb i change capacity for about 25fF!! and it is not problem to detect with this module.
Readout stability and amount of controll you have over its operation is just superb
P.S. no i am not working for Microchip
i just like it how this module works
havent worked with other capacitive sensing moduled but this one is grat because it is integrated in microcontroller it self..
It would be too long to explain all in details here but if you are interested to work with it or you have questions P.M. me or see this full guide with more details at http://www.electronics-base.com/index.php/featured-components/62-measurement/155-complete-guide-through-mtouch-capacitive-sensing-by-using-csm-module-inside-microchip-pic16f707-microcontroller
and for you to start working with mTouch i privided full C source code and project for download with full detailed explanations and video presentation of its work at http://www.electronics-base.com/index.php/projects/complete-projects/154-capacitive-touch-button-readout-using-microchip-mtouch-csm-module-on-pic16f707-example
please comment because i was thrilled when i saw possibilities of this Microchip mTouch CSM module.