Sie sind auf Seite 1von 49

Introduction to mTouch™

Capacitive Touch Sensing

© 2007 Microchip Technology Incorporated. All Rights Reserved. Introduction to mTouch™ Capacitive Touch Sensing Slide 1

Hello, my name is Marc McComb, Technical Training Engineer in the Security


Microcontroller and Technology Division here at Microchip. Thank you for viewing
this webseminar detailing Microchip’s mTouch Capacitive Touch Sensing
Technology.

1
Agenda

z What is mTouch™ Capacitive Touch


Sensing

z Main components:
− Touch Sensor
− Relaxation Oscillator Circuit
− Frequency Measurement
− Software

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 2

During this webseminar we will discuss a number of topics including what exactly is
mTouch Capacitive Touch Sensing. We will go on to describe sensor construction
as well as a detailed discussion on the various components of the sensor’s interface
circuitry to a PIC Microcontroller. So let’s get started…

2
What is mTouch™ Capacitive
Touch Sensing?

z Alternative to traditional push-button user


interfaces
z No mechanical movement
z Completely sealed
z Modern-looking design

z Royalty-Free license!

z Microchip provides a multitude of resources to


ease the design process
© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 3

What exactly is mTouch? Well, mTouch is an alternative to traditional mechanical


pushbuttons with some distinct advantages. The system is completely sealed, has
no mechanical components that will wear with time and provides a modern looking
design. Most importantly, Microchip offers a royalty-free license along with a
multitude of resources to aid in the development of your own mTouch applications.

3
Overview of mTouch™ Capacitive
Touch Sensing

PICmicro® MCU

+
_ S Q Software
+
TIMER0
R Q
_

TIMER1
Capacitive
Touch
Sensor

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 4

So how exactly do we implement mTouch Capacitive Touch Sensing? If we look at


a simplified block diagram of an mTouch system, we can identify some main
components.

4
Relaxation Oscillator Circuit

PICmicro® MCU

+
_ S Q Software
+
TIMER0
R Q
_

TIMER1
Capacitive
Touch
Sensor

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 5

First, we have the touch sensor itself. As the Capacitive Touch Sensing name
implies, this sensor will produce a varying capacitance that will interact with a
relaxation oscillator circuit. When the capacitance from the sensor changes, for
example when touched by a finger, the oscillator’s frequency will change.

5
Frequency Measurement

PICmicro® MCU

+
_ S Q Software
+
TIMER0
R Q
_

TIMER1
Capacitive
Touch
Sensor

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 6

In order to interpret this change in oscillator frequency, a frequency measurement


component is required in our system. This component will interface hardware and
software to accurately determine if and when a sensor has been touched.

6
Touch Sensors

© 2007 Microchip Technology Incorporated. All Rights Reserved. Introduction to mTouch™ Capacitive Touch Sensing Slide 7

So let’s take a closer look at each component of our mTouch system. First…Touch
Sensor construction.

7
Capacitance

A
ε 0εr A
C= d

d
ε0 Permittivity of Free Space (8.854 Pico-Farad/meter)

εr Relative Dielectric Constant (unit-less)

A Area of Plates (meters)

C Capacitance (Farads)

d Distance between plates (meters)

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 8

Recalling the equation for capacitance, we can see that there are a number of
variables that could change the capacitance produced by our touch sensors. As we
will see, the most important variables that we will be concerned with is Area and
distance. From this equation we can see that the greater the Area, the greater the
capacitance. As the distance becomes larger, the capacitance drops. Keep this in
mind as we proceed through this presentation. So…how do we build a sensor?

8
Touch Sensor Construction

z Fiberglass (FR- 4) Printed Circuit Board (PCB)


− laminate made from woven glass fiber impregnated with epoxy
resin

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 9

We begin with a simple printed circuit board. Constructed of FR-4, a composite of


laminated woven glass fiber and epoxy, the PCB will enable us to produce a natural
capacitance for our application.

9
Touch Sensor Construction

z Copper (Cu) pads (thickness exaggerated)

CP
© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 10

A copper pad is next introduced. The shape of this pad is not very important.
Therefore, we have the freedom to shape the sensor aesthetically to suit a
particular design. However, the area of the pad is very important. The larger the
pad, the better the sensitivity and a sensor touch will be more easily detected by the
rest of the system. As you can see in the slide above, a natural parasitic
capacitance to grounds elsewhere in the system has been introduced here which I
have labeled Pad Capacitance or Cp

10
Touch Sensor Construction

z Glass or Plexiglas®
− 2 to 5mm thick

CP
© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 11

Next, a touch surface is applied in the form of either Window glass or Plexiglas.
Other materials could be used as long as the dielectric constant of the material is
evaluated for functionality. Typically it is best to design a thin touch surface.
Remember back to the capacitance equation, as distance increases, the
capacitance will effectively decrease. Therefore, using a surface that is very thin
produces a more sensitive system.

11
How does it work?

z Introduction of finger produces a parallel


capacitance
CF

CP
© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 12

A finger touch will add a second capacitance in parallel with the pad’s capacitance.
The iron in an individual’s blood creates strings of capacitors between every surface
of their body. So, when someone creates a capacitance by moving his or her hand
into close proximity of another conductor, it creates a capacitance essentially
coupled to ground.

12
Equivalent Circuit

CP

Sensor Capacitance (CS) = CP

CP CF

Sensor Capacitance (CS) = CP + CF

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 13

Looking at equivalent circuits, we have the capacitance from the pad alone and then
a parallel combination of pad capacitance and the finger capacitance which add
together to form a total sensor capacitance labeled Cs. We should mention here
that the capacitance introduced by the finger is known to be very small in the area
of 5-15pF. Therefore, we will want to ensure that the capacitance created by our
pad is small as well to ensure that a touch is sensed. Further information on
physical design guidelines can be found in application note number AN1102
referenced at the end of this webseminar.

13
Relaxation Oscillator Circuit

© 2007 Microchip Technology Incorporated. All Rights Reserved. Introduction to mTouch™ Capacitive Touch Sensing Slide 14

So, we now know how to create a sensor that varies capacitance with the touch
from a finger. But how do we use this information to detect a sensor touch. This
leads us to our next component in the system, the relaxation oscillator.

14
RC Circuit

VCS
R
+
CS VCS
_
τ=R*C S τ time

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 15

The RC time constant for a charging capacitor is calculated by multiplying the


system’s resistance by its capacitance as shown above. Remembering that the RC
time constant represented by the Greek letter Tau, is the time it takes to charge a
capacitor to about 63% of its supply voltage and five times this time constant is the
time to charge the capacitor to within 1% of the supply. The sensor capacitance
alone with no finger introduced will create a steeper charging time as shown above.

15
RC Circuit

VCS
R
+
CS VCS
_
τ=R*C S τ time

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 16

If a finger is introduced, the capacitance of the system increases thereby increasing


the RC time constant resulting in a longer charging period. Let’s add a few more
components to our RC circuit.

16
Oscillator Circuit
PICmicro® MCU

CVREF
≈ 2/3 VDD
VDD +
_ C1
S Q
3KΩ
1/4VDD + R Q
_ C2
0.1µF 1KΩ
VCS

120KΩ

CS

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 17

The RC circuit discussed in the previous slide is interfaced with the dual comparator
module with SR Latch found on newer PIC Microcontrollers. The Voltage across the
Sensor capacitor labeled Vcs is used as the inverting input to both comparators.

17
Oscillator Circuit
PICmicro® MCU

CVREF
≈ 2/3 VDD
INVERTED
VDD +
_ C1
S Q
3KΩ
1/4VDD + R Q
_ C2
0.1µF 1KΩ
VCS

120KΩ

CS

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 18

Comparator 1 uses the internal reference voltage available on newer PIC


Microcontrollers set to approximately 2/3 of the supply voltage. Comparator 2 will
need an external reference. Therefore, we use a simple voltage divider to produce a
voltage of ¼ the supply voltage on the Comparator’s non-inverting input. The 0.1µF
capacitor is added to reject high frequency noise from the power supply and ensure
a stable lower limit voltage.

18
Oscillator Circuit
PICmicro® MCU

CVREF C1IN - > C1IN+ (2/3 VDD) ÆC1OUT = 0


≈ 2/3 VDD
INVERTED
VDD +
_ C1
S Q
3KΩ
1/4VDD + R Q
_ C2
0.1µF 1KΩ

120KΩ

CS
C2IN - > C2IN+ (1/4VDD) ÆC2OUT = 1

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 19

We are using the comparator to create a window of operation. If the voltage across
Cs drops below ¼ Vdd, the output of comparator 2 will go HIGH. Looking closely at
comparator 1 notice that the output’s polarity is inverted. Therefore, if the voltage
across Cs rises above 2/3 Vdd, the comparator 1 output will go LOW. Both
comparator 1 and comparator 2 outputs enter into the SR Flip-Flop’s Set and Reset
inputs respectively. Let’s explain how this will work.

19
Oscillator Circuit
PICmicro® MCU
S R Q Q OPERATION
Outputs hold last known
CVREF 0 0 values (HOLD)
≈ 2/3 VDD
0 1 0 1 RESET

VDD + 1 0 1 0 SET
_ C1
3KΩ
S Q 1 1 0 1 RESET

1/4VDD + R Q
_ C2
0.1µF 1KΩ

120KΩ

CS

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 20

In the slide above, note the SR Latch’s truth table. If the Set input is driven HIGH,
the pin connected to the Q bar output of the latch will be driven LOW. If the Reset
input is driven HIGH, the pin connected to the Q bar output will be driven HIGH.
Looking at the condition where both S and R inputs are HIGH, we notice that the
operation of the Latch will be in Reset mode since this Latch is Reset dominant.
More importantly is the condition where both inputs are driven LOW. What happens
in this condition is that the outputs of the Latch will hold the last know output values.
As you will see, this will become important in the operation of our relaxation
oscillator design.

Let’s step through the operation of this oscillator…

20
Oscillator Operation
PICmicro® MCU VCS
CVREF CHARGING
≈ 2/3 VDD

+ 0 2/3 VDD
_ C1
S Q
1
1/4VDD
1/4VDD + 1 R Q
_ C2

POWER UP time
S R Q Q OPERATION
Outputs hold last known
120KΩ 0 0 values (HOLD)

+ 0 1 0 1 RESET

CS _ VCS 1 0 1 0 SET

1 1 0 1 RESET

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 21

In this slide, the graph on the right represents the voltage across the sensor
capacitor. We will indicate changes in the SR Latch state by highlighting the
appropriate row in the SR Latch truth table in green. Starting at the very beginning
of operation, device power-up, the voltage across the sensor capacitor is 0.
Therefore, comparator 2 output goes HIGH while the inverted output of comparator
2 goes low since both inverting inputs are less than the non-inverting input threshold
voltages. This places the SR Latch into Reset driving the Q bar output to 1 which in
turn charges the sensor capacitor.

21
Oscillator Operation
PICmicro® MCU VCS
CVREF CHARGING
≈ 2/3 VDD

+ 0 2/3 VDD
_ C1
S Q
1
1/4VDD 1/4VDD
1/4VDD + 0 R Q
_ C2

time
S R Q Q OPERATION
Outputs hold last known
120KΩ 0 0 values (HOLD)

+ 0 1 0 1 RESET

CS _ VCS 1 0 1 0 SET

1 1 0 1 RESET

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 22

As the voltage across the sensor cap increases it eventually surpasses the 1/4Vdd
threshold, the non-inverting input voltage to Comparator 2. This causes the output
of Comparator 2 to go to 0. Referring to the SR latch truth table, this condition holds
the last known output value on the Q bar output at 1 and the sense capacitor
continues to charge.

22
Oscillator Operation
PICmicro® MCU VCS
CVREF CHARGING
≈ 2/3 VDD

+ 0 2/3 VDD
_ C1
S Q
1
1/4VDD
1/4VDD + 0 R Q
_ C2

time
S R Q Q OPERATION
Outputs hold last known
120KΩ 0 0 values (HOLD)

+ 0 1 0 1 RESET

CS _ VCS 1 0 1 0 SET

1 1 0 1 RESET

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 23

23
Oscillator Operation
PICmicro® MCU VCS
CVREF START DISCHARGING
≈ 2/3 VDD

+ 1 2/3 VDD
_ C1
S Q
0 2/3VDD
1/4VDD
1/4VDD + 0 R Q
_ C2

time
S R Q Q OPERATION
Outputs hold last known
120KΩ 0 0 values (HOLD)

+ 0 1 0 1 RESET

CS _ VCS 1 0 1 0 SET

1 1 0 1 RESET

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 24

Once the voltage across the sensor capacitor exceeds the internal voltage
reference on the non-inverting input of comparator 1, the inverted comparator output
connected to the Set input goes to 1 driving the Q bar output of the SR latch to 0.
The sensor capacitor then starts to discharge.

24
Oscillator Operation
PICmicro® MCU VCS
CVREF DISCHARGING
≈ 2/3 VDD

+ 0 2/3 VDD
_ C1
S Q
0
1/4VDD
1/4VDD + 0 R Q
_ C2

time
S R Q Q OPERATION
Outputs hold last known
120KΩ 0 0 values (HOLD)

+ 0 1 0 1 RESET

CS _ VCS 1 0 1 0 SET

1 1 0 1 RESET

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 25

Once below the 2/3 Vdd threshold, the output of comparator 1 goes to 0. This
places the SR latch into the hold state allowing the sensor capacitor to continue
discharging.

25
Oscillator Operation
PICmicro® MCU VCS
START CHARGING
CVREF
≈ 2/3 VDD

+ 0 2/3 VDD
_ C1
S Q
1 1/4VDD
1/4VDD
1/4VDD + 1 R Q
_ C2

time
S R Q Q OPERATION
Outputs hold last known
120KΩ 0 0 values (HOLD)

+ 0 1 0 1 RESET

CS _ VCS 1 0 1 0 SET

1 1 0 1 RESET

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 26

The voltage across the sensor capacitor eventually drops below the 1/4Vdd
threshold causing the comparator 2 output to go to 1 driving the SR latch Q bar
output HIGH. This, once again, begins charging the sensor capacitor.

26
Oscillator Operation
PICmicro® MCU VCS
CVREF CHARGING
≈ 2/3 VDD

+ 0 2/3 VDD
_ C1
S Q
1
1/4VDD
1/4VDD + 0 R Q
_ C2

time
S R Q Q OPERATION
Outputs hold last known
120KΩ 0 0 values (HOLD)

+ 0 1 0 1 RESET

CS _ VCS 1 0 1 0 SET

1 1 0 1 RESET

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 27

This charging and discharging process repeats as long as there is power to the
system.

27
Oscillator Operation
PICmicro® MCU VCS
CVREF START DISCHARGING
≈ 2/3 VDD

+ 1 2/3 VDD
_ C1
S Q
0 2/3VDD
1/4VDD
1/4VDD + 0 R Q
_ C2

time
S R Q Q OPERATION
Outputs hold last known
120KΩ 0 0 values (HOLD)

+ 0 1 0 1 RESET

CS _ VCS 1 0 1 0 SET

1 1 0 1 RESET

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 28

28
Oscillator Operation
PICmicro® MCU VCS
CVREF DISCHARGING
≈ 2/3 VDD
2/3 VDD
+ 1
_ C1
S Q
0
1/4VDD + 0 R Q 1/4VDD
_ C2

time
S R Q Q OPERATION
Outputs hold last known
120KΩ 0 0 values (HOLD)

+ 0 1 0 1 RESET

CS _ VCS 1 0 1 0 SET

1 1 0 1 RESET

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 29

We have implemented the RC circuit containing the sensor capacitor into a very
good relaxation oscillator. As the capacitance changes in the circuit, so will the RC
time constant, changing the frequency of oscillation.

29
Frequency Measurement

© 2007 Microchip Technology Incorporated. All Rights Reserved. Introduction to mTouch™ Capacitive Touch Sensing Slide 30

So let’s look at how we will determine a sensor touch based off of this frequency
change using a frequency measurement circuit.

30
Frequency Measurement
PICmicro® MCU
CVREF
≈ 2/3 VDD
VC2OUT pin
VDD +
_C1
S Q
3KΩ C2OUT pin
1/4VDD
+ R Q HIGH
1KΩ
_ C2
0.1µF LOW

time

T0CKI pin
TIMER1

120KΩ

CS

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 31

We should first note that the output from the SR latch on pin C2OUT is actually a
square wave.

31
Frequency Measurement
PICmicro® MCU
CVREF
≈ 2/3 VDD
VC2OUT pin
VDD +
_C1
S Q
3KΩ C2OUT pin
1/4VDD
+ R Q HIGH
1KΩ
_ C2
0.1µF LOW

time
TMR1+1 TMR1+1 TMR1+1 TMR1+1

T0CKI pin
TIMER1 TMR1H TMR1L

120KΩ
16-bits = 0Æ (216 – 1) = 0 Æ 65535
CS

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 32

Connecting the SR latch output on C2OUT to the Timer1 input pin (T1CKI), we
could use this square wave as the Timer1 clock source. Configuring TMR1 register
to increment on every positive edge of the square wave allows us to count the
number of clock pulses. However, this isn’t enough to determine the frequency of
the square wave. To do this will need to have a fixed period clock source to gate the
16-bit TMR1 value to.

32
Frequency Measurement
TMR0 interrupt provides a
PICmicro® MCU fixed time base for measurement
CVREF
≈ 2/3 VDD
TMR1H:TMR1L Increment Frequency
VDD +
_C1
S Q
3KΩ C2OUT pin
1/4VDD
+ R Q
_ C2 time
0.1µF 1KΩ

TMR0 TMR0 TMR0


0Æ255 0Æ255 0Æ255
TIMER0
T0CKI pin time
TIMER1

TMR0 TMR0
120KΩ
overflow overflow

CS

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 33

For this we use the Timer0 module. Here the PIC MCU is configured to generate an
interrupt when the TMR0 register overflows. Therefore, the interrupts will occur at a
fixed rate. We could detect a change in square wave frequency by observing a
change in the TMR1 registers’ values on each TMR0 interrupt.

33
Frequency Measurement
VDD TMR0 interrupt provides a
PICmicro® MCU fixed time base for measurement
3KΩ
1/4VDD
TMR1H:TMR1L Increment Frequency
1KΩ C2OUT
1000pF

C12INx T1CKI

time

TMR0
0Æ255

time

CP
TMR0
overflow

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 34

Capacitance created by the pad alone results in a corresponding square wave


frequency. On a TMR0 interrupt, we read the current count value in the TMR1
registers and store it for later reference.

34
Frequency Measurement
VDD TMR0 interrupt provides a
PICmicro® MCU fixed time base for measurement
3KΩ
1/4VDD
TMR1H:TMR1L Increment Frequency
0.1µF 1KΩ C2OUT

C12INx T1CKI

time

TMR0
0Æ255

CF
time

CP
TMR0
overflow

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 35

Once a finger touch is introduced, the sensor capacitance increases. This increases
the RC time constant effectively decreasing the frequency of our square wave
output.

35
Frequency Measurement
VDD TMR0 interrupt provides a
PICmicro® MCU fixed time base for measurement
3KΩ
1/4VDD
TMR1H:TMR1L Increment Frequency
0.1µF 1KΩ C2OUT

C12INx T1CKI

time

TMR0 TMR0
0Æ255 0Æ255

CF
time

CP
TMR0 TMR0
overflow overflow

Frequency change of 1 Æ 5%
© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 36

Therefore, on the next TMR0 interrupt, when we read the contents of the TMR1
registers, we should get a smaller value than the previous interrupt. Using a
software algorithm to compare both values, we can identify a sensor touch. In the
above diagram, the frequency difference is exaggerated in the interest of
highlighting these changes. In reality, we can expect a frequency change of
between 1 and 5%.

36
Frequency Measurement
VDD TMR0 interrupt provides a
PICmicro® MCU fixed time base for measurement
3KΩ
1/4VDD
TMR1H:TMR1L Increment Frequency
1KΩ C2OUT
1000pF

C12INx T1CKI

time

TMR0 TMR0 TMR0


0Æ255 0Æ255 0Æ255

time

CP
TMR0 TMR0
overflow overflow

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 37

Once, the finger is removed, sensor capacitance is again reduced. This decreases
the RC time constant and increases the frequency of the square wave.

37
Frequency Measurement
VDD TMR0 interrupt provides a
PICmicro® MCU fixed time base for measurement
3KΩ
1/4VDD
TMR1H:TMR1L Increment Frequency
1KΩ C2OUT
1000pF

C12INx T1CKI

time

TMR0 TMR0 TMR0


0Æ255 0Æ255 0Æ255

time

CP
TMR0 TMR0
overflow overflow

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 38

The next TMR0 interrupt reads the value of the TMR1 registers, recognizes that it is
greater than the previous result confirming that the sensor is released.

38
Software Algorithm to Detect a
Sensor touch

© 2007 Microchip Technology Incorporated. All Rights Reserved. Introduction to mTouch™ Capacitive Touch Sensing Slide 39

The hardware section of our system is essentially completed. We will now move on
to the software component.

39
Detecting a Sensor touch
TMR0 interrupt provides a
fixed time base for measurement
Using 2 Variables and 1
TMR1H:TMR1L Increment Frequency
Constant:
•variable average
• running average of previous 16 time
samples of TMR1H:TMR1L

•variable raw TMR0


0Æ255
TMR0
0Æ255
TMR0
0Æ255
• current value of TMR1H:TMR1L
time
•constant trip
• value of difference below
average that indicates a sensor
touch

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 40

To accurately detect a change in frequency of the relaxation oscillator, two variables


and one constant are used. The average variable: keeps a running average of 16
previous samples from the TMR1 registers. This running average is used to
eliminate noise created by changes in temperature, voltage and environment. The
raw variable: holds the current value in TMR1 registers, and the predetermined trip
constant: is the minimum difference between the raw data and the average value.

40
Detecting a Sensor Touch
TMR0 interrupt provides a
fixed time base for measurement
TMR0 Overflow

TMR1H:TMR1L Increment Frequency

NO is
raw < (average – trip) time
???????
TMR0 TMR0 TMR0
YES 0Æ255 0Æ255 0Æ255

NO SENSOR
SENSOR TOUCH
TOUCH time

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 41

Implementing this in a software routine, on a TMR0 interrupt, the current data is


read into the raw variable, if the average value less the trip value is greater than the
raw value, a sensor touch has occurred and the software responds accordingly.
Otherwise, the sensor is determined to be untouched.

41
Detecting a Sensor Touch
TMR0 interrupt provides a
fixed time base for measurement
TMR0 Overflow

TMR1H:TMR1L Increment Frequency

NO is
raw < (average – trip) time
???????
TMR0 TMR0 TMR0
YES 0Æ255 0Æ255 0Æ255

NO SENSOR
SENSOR TOUCH
TOUCH time

average =
average
16
* 15 + raw
16
CLEAR
TMR1H:TMR1L
END

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 42

If a sensor touch has not occurred, the current value in TMR1 registers is averaged
into the 16-point running average. The TMR1 registers are always cleared at the
end of every TMR0 interrupt routine and the CPU returns to whatever it was doing
prior to the interrupt. This completes the basic system.

42
Moving Beyond the Basics

© 2007 Microchip Technology Incorporated. All Rights Reserved. Introduction to mTouch™ Capacitive Touch Sensing Slide 43

This is the fundamentals of a basic capacitive touch system. Let’s take a look at
some resources available from Microchip that will help you to move beyond the
basics.

43
Beyond the Basics

z Multiple sensors PICmicro® MCU


− using programmable CVREF
≈ 2/3 VDD
comparator inputs
+
_C1 S Q

+ R Q
_ C2

TIMER0

TIMER1

Multiple Sensors External


Reference

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 44

We can further enhance this design by using features available on newer PIC
Microcontrollers. For example, multiple sensors can be easily used in our design by
using the programmable input selection of inverted inputs to both comparators.
Notice in this example that both comparators are able to share the same input pin at
one time.

44
Beyond the Basics

z mTouch™ Software Development Kit


(SDK)
− Intuitive analysis of
capacitive system

− Windows application
that communicates
with system

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 45

The mTouch Software Development Tool is provided as a free download at


www.microchip.com providing an intuitive means of analyzing a capacitive system.
This tool features the ability to communicate with your system via the PICKit Serial
Analyzer using the I2C protocol. Application critical information such as Trip
threshold and acceptable hysteresis signaling a sensor touch can easily determined
by visualizing sensor behavior.

45
Summary

z mTouch™
− Non-mechanical
− Aesthetically diverse solution

z Provided royalty free from Microchip


Technology
− Supporting resources
− Application Notes
− Source Code
− Software Development Kit
− Online Design Center

© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 46

The mTouch Capacitive Touch Sensing is a robust solution to traditional sensors


that significantly reduces failure due to worn mechanical parts. Furthermore, some
liberty can be taken with shape of the touch pads adding some aesthetic diversity to
your design. Free licensing is provided by Microchip while making available a
number of supporting resources such as application notes, source code, the
mTouch Software Development Kit and an online design center.

46
Summary

z Typical mTouch™ Capacitive Touch Sensing


system:
PICmicro® MCU

Software
TIMER0

DUAL COMPARATORS
WITH SR LATCH TIMER1
Capacitive
Touch
Sensor

RELAXATION OSCILLATOR FREQUENCY MEASUREMENT


© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 47

The Capacitive Touch Sensing system shown in this webseminar utilizes a


relaxation oscillator circuit in which the touch sensor’s capacitance is used to affect
the frequency.

Frequency measurement incorporates the Timer1 and Timer0 modules in


conjunction with software. Timer1 provides a 16-bit value based on the frequency of
the oscillator while Timer0 interrupts provide a fixed, gated period over which to
read these values.

This particular design offers a number of advantages including minimal software


impact on the design, fewer external components and an averaging software
algorithm that tends to reduce the impact of noise on the system.

47
For More Information

z AN1101: Introduction to Capacitive Sensing

z AN1102: Layout and Physical Design


Guidelines for Capacitive Sensing

z AN1103: Software Handling for Capacitive


Sensing

z AN1104: Capacitive Multi-Button


Configurations

z mTouch™ Design Center at


www.microchip.com/mTouch
© 2007 Microchip Technology Incorporated. All Rights Reserved. introduction to mTouch™ Capacitive Touch Sensing Slide 48

For more information on mTouch Capacitive Touch Sensing, please refer to the
application notes listed above. Future mTouch webseminar topics will include
layout/design techniques, software algorithms and multi-button configurations. You
may also be interested in visiting the mTouch Design Center at
www.microchip.com/mTouch. Here you will find links to the most current information
and resources for this technology.

48
Thank You!!

© 2007 Microchip Technology Incorporated. All Rights Reserved. Introduction to mTouch™ Capacitive Touch Sensing Slide 49

My name is Marc McComb and I thank you for viewing this webseminar.

49