[PIC] CapSense touch-switch baseline strategy

53 views
Skip to first unread message

PICdude

unread,
Jun 13, 2010, 12:52:47 PM6/13/10
to pic...@mit.edu
I'm experimenting with CapSense on an enhanced 16F device, and have
somewhat incorporated it into an application (just 1 switch) which has
a 3-digit LED display, and I'm dumping the CapSense output to the
display. At this point, I can see the output change as a finger gets
close, and I'm using this to tinker with the pad size and various
parameters to get a good signal change.

For a production app though, I expect that tolerances, temperature and
other environmental variations, would vary the detection threshold
from one product to another. First thought to correct this is to
detect the baseline value on startup and use that from then on, but I
expect there may be drift over time...???

The eraser-head "mouse" on my laptop obviously has some strategy for
auto-zeroing itself due to drift (any constant value for ~5 secs must
be zero), so I can steal some ideas from that. But then again, the
eraser head has incorrectly thought my finger leaning on it was zero
(and it happens quite often).

Are there any other strategies for this? I do expect some parameters
in any strategy will depend on expected usage (how long a user may
hold down a switch etc), but looking for general strategy concepts at
this point.

Cheers,
-Neil


--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist

Scott

unread,
Jun 13, 2010, 3:00:43 PM6/13/10
to Microcontroller discussion list - Public.
> I'm experimenting with CapSense on an enhanced 16F device, and have
> somewhat incorporated it into an application (just 1 switch) which has
> a 3-digit LED display, and I'm dumping the CapSense output to the
> display.  At this point, I can see the output change as a finger gets
> close, and I'm using this to tinker with the pad size and various
> parameters to get a good signal change.
>
> For a production app though, I expect that tolerances, temperature and
> other environmental variations, would vary the detection threshold
> from one product to another.  First thought to correct this is to
> detect the baseline value on startup and use that from then on, but I
> expect there may be drift over time...???
>
> The eraser-head "mouse" on my laptop obviously has some strategy for
> auto-zeroing itself due to drift (any constant value for ~5 secs must
> be zero), so I can steal some ideas from that.  But then again, the
> eraser head has incorrectly thought my finger leaning on it was zero
> (and it happens quite often).
>
> Are there any other strategies for this?  I do expect some parameters
> in any strategy will depend on expected usage (how long a user may
> hold down a switch etc), but looking for general strategy concepts at
> this point.
>
> Cheers,
> -Neil
>

Hey Neil,

Touch sensors/screens are what I do for a living, but I use the
Cypress PSoC instead of PIC.
Changes in temp, EMI, etc. will cause the signal to drift over time.
Check out the Cypress documentation on their Capsense CSD
(http://www.cypress.com/?rID=3122), look in the Appendices for good
baseline behavior.

Quick summary: use at least a 1 cycle debounce to suppress any errant
noise spikes. Cypress snaps the baseline down to the raw signal level
after X cycles (usually after about a second, this solves the finger
on button at startup issue). For a raw signal that is rising (e.g. a
touch), they use what they call a "bucket" method. They add some
proportion of the difference between the raw and the baseline to this
bucket. When the bucket overflows (or reaches some maximum threshold),
the baseline is then incremented. They simply shift right one to
divide the diff by two (if the diff is larger than 255, they simply
add 127 to the bucket). This gives a logarithmic behavior to the
baseline. The speed that the baseline rises can be controlled via the
maximum threshold of the bucket. The only issue this has is that if a
finger is on the sensor for a long period of time, it will deactivate.
However, this solves a "stuck key" condition.

If you have more questions, ask!

-Scott

PICdude

unread,
Jun 13, 2010, 5:58:41 PM6/13/10
to pic...@mit.edu
Good stuff, thanks. I'm going to go through this in a bit when I'm
done with this meeting, and I'm sure I'll have questions for you then.

Cheers,
-Neil.

cdb

unread,
Jun 13, 2010, 6:18:26 PM6/13/10
to Microcontroller discussion list - Public.

:: First thought to correct this is to


:::: detect the baseline value on startup and use that from then on,
:::: but I
:::: expect there may be drift over time...???

If you download the firmware for the Pic24 Starter Kit (which has a 4
button touch panel) this has some code that might be helpful.

WARNING:
Much of the Microchip code doesn't make sense, it refers to variables that
I've never been able to find - and won't compile if taken and put directly
into a new project - but does compile if left in the original workspace.

I imagine my baseline heating profile code would work for setting up a
baseline cap sensing value - with the minor alteration of reading the
capsense register rather than an external temperature sensor.

It does lurk somewhere here in posts about two years ago- I can scribble it
down again if you want.

Colin
--
cdb, co...@btech-online.co.uk on 14/06/2010

Web presence: www.btech-online.co.uk

Hosted by: www.1and1.co.uk/?k_id=7988359

Bob Axtell

unread,
Jun 19, 2010, 5:13:03 PM6/19/10
to Microcontroller discussion list - Public.

One strategy I have used before is to catch the baseline (finger out of
physical range) and maintain a running average. If you can store 8 values,
do that, dropping off the oldest value and using the newest. Then the
average of the 8 values is kept as the baseline. This should include ALL
variables, including Rvsalues, heat, cold, etc.

--Bob

Reply all
Reply to author
Forward
0 new messages