That code is still kind of experimental, so we don't have any tutorials for it yet.
The main document for understanding QTouch is this one:
http://www.atmel.com/Images/Atmel-42195 ... -Guide.pdf
From a quick scan of the code, it looks like it's using the self-capacitance method of touch sensing: Connect a fixed voltage to the pad then swap the connection to high-impedance (basically charging the pad like a capacitor and then disconnecting the voltage source), then wait to see how long it takes for the voltage to drain through a resistor whose value is known. That decay rate is highly predictable, and when everything else is constant, will be inversely proportional to the value of the capacitor.
Water has a high dielectric constant (it makes good capacitors), so anything putting something that contains water (like human skin) near the touch pad increases the pad's capacitance. It will take longer for the pad to discharge through the resistor that way, and the microcontroller can measure the difference.
The first parameter of the library's .begin() function is the input pin connected to the sensor. The second line tells the code how much to oversample the input.
Oversampling is a process of taking several measurements, finding the average, and reporting that instead of the actual readings. It's way of reducing noise, but also improves the accuracy of the measurement. The average value of noise is zero (if it wasn't, it would be a source of free energy), so the more readings you add together, the closer the noise error in the measurements approaches zero.
There's another side-effect of adding noise to measurements though: it dithers the sensor output around the real input value. If I have a window comparator that only measures "below 1v" and "above 2v", and feed it a signal at 1.1v plus a couple of volts of noise, I can expect to see about ten "below 1v" outputs for every one "above 2v" output. The noise pushes the signals above and below the thresholds, but vanishes if I take the average of a large enough sample. Statistically, getting a 10:1 improvement in resolution like that would take about 64 readings to make the noise error small enough to ignore.
Oversampling takes longer though, so there's always a tradeoff between how much you can do and how long the signal will remain stable.
The next parameter to .begin() is the value of the resistor that will discharge the touch pad. The system needs that to calculate timing.
The last parameter is the frequency mode, which also takes a bit of explaining.
For systems that take repeated measurements, there's one kind of noise that doesn't average to zero: noise that occurs at the same frequency as the sampling rate. There are all sorts of videos that show the effect of a camera being in sync with the thing it's recording.. this one is especially nice:
https://www.youtube.com/watch?v=uENITui5_jU
For capacitive sensors, things like induced signal from flourescent lighs can create noise, and if the lamp frequency is just slightly off of your sampling frequency, the touch system will think it looks like a series of touches.
(if you have an oscilloscope, hold the tip of a probe between your fingers and put your hand within a foot or so of a flourescent light)
One way to prevent that is to change the sampling frequency. You can shift it up and down in a predictable pattern, hop from one frequency to another, or add some random jitter. Atmel's QTouch library supports all those options, but 'NONE' (fixed frequency readings) is the simplest.
To use the output from the sensors, keep a running average of the readings like so:
Code: Select all
level = (( N * level ) + latest_reading ) / ( N + 1 );
and find the value for N that gives you the best tradeoff between quick touch detection and limited noise.