I'm using the demo touch shield w/ 5 pads and 5 LEDs.
In order to detect a touch event, I continuously read the touchpad (based on the "capt_basic_continuous" demo from the LPCExpresso SDK). I average over 5 readouts for "current" values, and over 300 for "baseline" values. I then subtract "current" from "baseline" to get relative potential, usually within 0/-1 (idle) to +30 (firm touch).
Once I detect at least one pad going above a predefined threshold (around +10), the one with the highest relative value is registered as being touched. I then stop correcting the baseline until all pads fall below the threshold value, which is my criteria for "back to idle" at - which point I deregister the touch and resume updating baseline values.
For instance, at idle I may see raw values of 644/643, 619/618, 636/636, 651/650, 590/590 - which correspond to -1, -1, 0, -1, 0. On touch, these may rise to e.g. +24, +7, +11, +6, +2 - indicating that pad 0 is being touched. Once finger is removed, these go back to about the same average values (idle).
This works well for short-time runs. It accounts for the slow drift I see in the baseline over time.
However, over longer runs (hours) something happens to the board that I don't understand - if I touch a pad after not touching it for a while (hours), suddenly the readouts change drastically and alter the baseline long-term without giving me a chance to adjust, leading to a "stuck" touchpad.
For example, I'm seeing a readout of say 643 current / 643 baseline on pad 0. The normal behaviour when I touch pad 0 is that it falls to about 620 current, which leads to a diff value of +23 on detection on that pad.
But after a few hours and no touch events, this behaviour changes and when I touch e.g. pad 0, suddenly I see values of -6, +37, +29, +30, +24. The software still manages to catch that I touched pad 0... but once I release it, I then have: -39, +29, +19, +20, +15 - 4/5 of which are now above the predefined threshold of +10.
This indicates that the baseline has shifted quite dramatically when I touched the touchpad, and since 4/5 pads now register as "touching" - I no longer have the chance to readjust. Thus, the keypad is stuck in "being touched" mode, as it will no longer register "idle" (since the new idle is a huge distance away).
What am I doing wrong? What hardware behaviour/phenomenon am I not accounting for? Am I reading too fast? Too slow? Too few samples?
I'm currently using a clock divider of 7 (should be about 2.14 MHz), with a poll count of 9.