Author Topic: ~fF Capacitance measurement with mTouch 16f707 touch button!  (Read 720 times)

0 Members and 1 Guest are viewing this topic.

Offline electronicsbasecomTopic starter

  • Beginner
  • *
  • Posts: 3
  • Helpful? 0
~fF Capacitance measurement with mTouch 16f707 touch button!
« on: March 24, 2012, 04:54:25 PM »
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.

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: ~fF Capacitance measurement with mTouch 16f707 touch button!
« Reply #1 on: March 24, 2012, 08:56:33 PM »
please comment because i was thrilled when i saw possibilities of this Microchip mTouch CSM module.
Besides the fact that I have a few Microchip boards with touch pads (without going totally overboard writing about it), I think the mTouch is a waste of time for making touch buttons and one of their developments that really isn't worthy of their time - and it is just really old wine on new bottles (plain old, not even vintage)

the "mTouch enabled" controllers (quite a lot exists) can use it for smart stuff when you look beyond touch panels and such - too bad they don't focus on that.

I'm just surprised that they only made it a few years ago - we made cheap and cheerfull touch buttons and keyboards from around 1980 (The original IBM PC keyboards use capacitive keys, with a mechanical "klonk" for tactile feedback, but purely capacitive readout of the keys and an article on that could be made in about a fourth of your post ;)  but then... You just showed us that you can copy-paste (from Microchips AN1171, which anyone could download, so a link to that would have more than sufficed) and it's obvious that you have started a campaign to spam all the forums that you can find, just for the purpose of luring people to your web space (at least some of it copy pasted from other sites (expect letters from their lawyers) and seriously flawed info in some places).
Whatever happened to originality and integrity?

No need to tell people you're not affiliated to Microchip - we know they wouldn't allow (nor need) such spamming in their name.

Google really is a tell tale when a pathetic hit-spammer lets loose.
Regards,
Sren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline electronicsbasecomTopic starter

  • Beginner
  • *
  • Posts: 3
  • Helpful? 0
Re: ~fF Capacitance measurement with mTouch 16f707 touch button!
« Reply #2 on: April 23, 2012, 04:37:37 PM »
ok i had to answer to your post..
You have right for your opinion but i do not agree with you. When you ask young engineer how to measure small capacity changes on some sensor (water presence sensor for example) many of them will not know where to start. If you have worked with CSM module you would know that although it is not new wheel that they invented it is still working great. This text is effort to spread some knowledge across internet and i am sure many will benefit from it.

Any effort to share something useful, and this is 100% useful info i wrote here, should be appreciated and not criticized.

And for quick start i have shared all codes and haven't kept it for my self..

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: ~fF Capacitance measurement with mTouch 16f707 touch button!
« Reply #3 on: April 24, 2012, 09:39:25 AM »
ok i had to answer to your post..
You have right for your opinion but i do not agree with you. When you ask young engineer how to measure small capacity changes on some sensor (water presence sensor for example) many of them will not know where to start.
That goes for just about any technique, but that's not the point here.


If you have worked with CSM module you would know that although it is not new wheel that they invented it is still working great.
They're OK, but that's not the point either.


This text is effort to spread some knowledge across internet and i am sure many will benefit from it.

Any effort to share something useful, and this is 100% useful info i wrote here, should be appreciated and not criticized.

And for quick start i have shared all codes and haven't kept it for my self..
This is the point!
You make a very lengthy post by copy/pasting (stealing) from an app.note and then you want us to put you on a piedestal for Microchips work ::)

Usefulness depends on what you need - a car is useful if you want to drive somewhere, but if you need to open a can... Not as much.
Many people will probably benefit from the app.note, but if they're kept to your limited excerpt of it, they'll be limited compared to the original work.

Had you kept to some original stuff you'd done or simply linked to the app.note  telling what it was about and such, I wouldn't mind at all, but you portray stolen info as your original work and want to harvest glory for it - get real.

New engineers need to research stuff anyway, as they learn nothing by being spoon fed.
And still, the technique is very old.
Regards,
Sren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

 


Get Your Ad Here