4620 and captured the TIMER1 gating signal you see in
Screenshot 3. According to Screenshot 3 and my old eyes,
the pulses from our XC2C64A/PIC18LF4620 relaxation
oscillator are counted by TIMER1 in gate intervals of 4.2
ms. For those of you that just can’t do without the math,
our CleverScope observation is pretty danged close.
Here’s the math behind Screenshot 3:

Our CleverScope display number is actual scan time
as it takes the CPU overhead (branching to the interrupt
service routine, storing status, returning from the interrupt,
restoring status, etc.) into account.

Note that I also added an LED at I/O pin RB0 to
provide a visual indication of when the tin touch pad
is being touched. Here’s the code that supports the
touch LED:

I realize that using an entire byte as a bit
flag is inefficient (char btn_pressed;). However,
we have microcontroller resources to spare
and it’s the capacitive touch sensing concepts
we are in search of at this moment. We’ll get
more elegant with our touch sensing code
when the time comes. So, let’s look at the
code that does all of the work:

■ SCREENSHOT 4. The btn_average value is
an “untouched” average count accumulated
after 200 iterations.