CPTBadAss: heh yeah it's not immediately obvious how it all works. It took me a little while to figure it all out from the IBM patent (I copied their technique) as it's not the normal way you do capacitive sensing (like with touchscreens or soil moisture sensors or the touch buttons on a fancy Samsung TV)...
The basic principle is as follows.
Each key is a tiny capacitor. When it's unpressed, the capacitance is about 4pF, and when you press the key the capacitance drops to 0.4pF. The problem is of course sensing the difference between those two values---and measuring capacitance isn't as straightforward some other things.
There's a variety of methods used to measure capacitance but a lot of them are quite slow, and we need to scan a whole bunch of keys in a short period of time. So we use a more uncommon technique that is possible because we only want to sense if a key is more than, say, 2pF, or less than it---we don't need to know the exact value.
Capacitors have an interesting effect of "differentiating" the voltage input to them. If you keep the input to a capacitor at the same level, it will output zero current. If you raise the input voltage, it will output current proportional to the
rate of change of the input voltage. If you drop the input voltage, it will "output negative current" if that makes sense. So if you switch the output of a microcontroller ON into the input of capacitor, the capacitor sees a very quick rise of input voltage (and then stops changing while the output stays switched on) and will output a positive spike. When we switch the output back off, the capacitor sees a very quick drop of input voltage and outputs a negative spike (of current, but this gets converted back into voltage for other reasons). By the same token if you raised the voltage very slowly, you'd see a small positive output from the capacitor as long as the voltage keeps rising. Stop raising the voltage, and the output drops back to zero. Start lowering the voltage slowly and you'll see a small steady negative output... you get the point.
The important thing here is that those spikes are proportional to how big the capacitor is. So, if we keep sending our key capacitor pulses by switching our microcontroller output on and off, the spikes are bigger when a key is unpressed, and smaller when a key is pressed.
Now we have a change in voltage when a key is pressed instead of a change in capacitance, and that's much easier to measure.
We could use an analogue-to-digital converter to get the amount of voltage into our microcontroller (many microcontrollers have them built-in), but they're slow and our spike is tiny and only exists for a fraction of a second.
So we use a comparator. A comparator has two inputs, a "+" input and a "-" input, and one output. When the "+" input is at a higher voltage than the "-" input, the output of the comparator is switched on. When the "-" input is lower than the "+" input, the output is switched off.
We get a comparator then and hook up the "+" input to the other end of the key's capacitor. The "-" input is hooked up to a fixed voltage that is set halfway between the voltage spikes from an up key and a down key. (This voltage can come from anywhere, initially I just used a variable resistor set with a screwdriver to change the voltage for tuning, but I use a digital-to-analogue converter on this board so I can change the value from my code).
What this means is now we can switch on the output of our microcontroller, the capacitor emits a voltage spike, the comparator then compares the spike to see if it's lower or higher than the threshold value, and will turn its output on or off accordingly. The output of the comparator is hooked up to an input on our microcontroller and we can then see if the key is pressed or not.
That's all there is to it really. The only complicated parts come in that there's many, many capacitors hooked up in a matrix (23 columns and 4 rows), so we use 4 comparators to read the 4 rows, and pulse each column in turn and read the 4 comparators at once to see the result. In this way it's very similar to a "normal" keyboard controller with "normal" keyswitches.
Hopefully that makes sense and isn't too long-haired.
These links show the principle of capacitive differentiation (and integration):
http://www.physics.ucla.edu/demoweb/demomanual/electricity_and_magnetism/ac_circuits/rc_integration_and_differentiation.htmlhttp://www.tpub.com/neets/book9/37k.htm