Microchip CTMU For Capacitive Touch Applications: General Features of The Ctmu
Microchip CTMU For Capacitive Touch Applications: General Features of The Ctmu
CTMUCON
(CTMUCONH and CTMUCONL for PIC18F)
CTMUICON
Current Source
External Edge
Trigger Pins
Pulse
Timer1 Generation
(PIC24F only) Logic Pulse Output
OC1
(PIC24F only) Pin
ECCP1/ECCP2
A/D Converter Comparator 2 Input
(PIC18F only)
Comparator 2
Output
Current Source
Sensor 0
Discharg
Trigger
e
CTMU
C A/D
A/D Converter
A/D MUX
//CTMUICON
CTMUICON = 0x300; //55uA
CTMUICON.ITRIM = 0; //Nominal - No Adjustment
AD1PCFGL = 0x0000;
AD1CON1 = 0x0000;
AD1CHS = 0x0000; //select the analog channel 0
AD1CSSL=0x0000;
AD1CON1bits.FORM = 0x0; //Unsigned fractional format
AD1CON3 = 0x0000; //bits.ADRC=0;
AD1CON2 = 0x0000;
AD1CON1bits.ADON = 1; //Turn On A/D
CTMUCONbits.CTMUEN = 1; //Enable CTMU
In the case of the PIDEM Touch Sense 2 Demo Board, the capacitive sensor connected to that channel is read.
all 16 A/D channels are used for capacitive touch. Read- After all 16 touch sensors have been read, the Timer1
ing of each of the sensor channels (A/D channels) is interrupt handler sets a flag called, “dataReadyCTMU”,
controlled by Timer1. Timer1 is setup to fire at a 1 ms and the main routine uses this flag to know when to
interval. Each time that the Timer1 interrupt handler process the new data just gathered from all 16 capacitive
runs, it increments the channel number of the A/D and touch sensors.
1 2 3 4
5 6 7 8 9
End
DS01250A-page 6
© 2009 Microchip Technology Inc.
CTMU Operation
AN1250
Example 3 provides the equivalent code for reading the the corresponding Index variable so that the correct
capacitive touch sensors using the CTMU on a PIC24F channel is set to an analog A/D. The A/D value is
device. Example 4 has the same algorithm for a temporarily stored in the variable, immediateValue.
PIC18F device. Note that the channel number being The LoopCount determines how long the CTMU
read is referenced by the Index variable. The current source charges the capacitive touch circuit.
ADSELECT array is setup to have the correct bits set for
The main() function contains a while(1) loop sensor data is complete, and the LED display informa-
(endless) that checks for the dataReadyCTMU flag (set tion is also updated, Timer1 is re-enabled, and the whole
by the Timer1 interrupt handler). If the dataReadyCTMU process begins again.
flag is not set, other tasks are performed while it waits. In The structuring of the code in this manner is done to
the case of the PICDEM Touch Sense 2 Demo Board, make the system deterministic. Using a fixed timer to
communication of data over the USB is serviced. If the read each capacitive touch sensor channel at a 1 ms
dataReadyCTMU flag is set, the main() function clears rate fixes the update rate to approximately 16 ms (1 ms
the flag and calls the routines necessary to process the times 16 channels). The actual update rate is slightly
newly acquired data. The main() function temporarily slower, since Timer1 is disabled while the new data is
disables Timer1 to insure that no new data is introduced processed.
in the middle of the routines that are handling data
processing. After all processing of the capacitive touch
Enter
Read Sensor
Pressed Unpressed
No No
Unpressed_Count ++
Pressed_Count ++
Exit
C1 C2 C3 C4
R1
R1 R1 R1 R1
C1 C2 C3 C4
R2
R2 R2 R2 R2
C1 C2 C3 C4
R3
R3 R3 R3 R3
C1 C2 C3 C4
EQUATION 3:
EQUATION 4:
Notice that the trace between the two triangular pads is It should also be noted that when neither the left nor
grounded. This trace provides additional isolation right slider has crossed the tripped value (base or
between the two triangular capacitive touch sensors by unpressed), the position is not calculated. This
reducing the effect of capacitive coupling. prevents jitter between values that are displayed on the
The slider works by reading the amount of shift in slider LEDs.
capacitance from a normal untouched sensor. The slow To achieve maximum linearity and accuracy of the slider,
moving average described earlier is used to track the it is important to keep the capacitance for each of the
untouched “base” capacitance of each of the two triangular sensors matched as closely as possible since
sensors. When the value is shifted from this base value the software algorithm is using and comparing the
to a value where the trip point is reached for either of values for two triangular sensors. The trace lengths to
the two slider sensors, the base value is then locked each triangular sensor and adjacent sensors, LEDs and
and the slow moving average is no longer used for other board traces become important. The CTMU cur-
slider position calculations until the value of both slider rent trimming capability, mentioned in the “Multiple
sensors is again above the trip threshold. The base Keys Press” section, is applicable to the slider sensors
values for each of the two sensors is captured and as well.
used for the slider position calculations. The software
algorithm then looks at the change in the slider value
FIGURE A-1: PICDEM™ TOUCH SENSE 2 DEMO BOARD WITH COVER REMOVED
R8 R5 R4 R9 R3
470 470 470 470 470
FIGURE A-2:
DS01250A-page 16
RED RED RED RED RED
AN1250
BTN_0 R6
MC 7 8 9
RE5
MC 7 8 9
47
S1 S2 S3 S26 S22
D1 D10 D7 D2 D3
BTN_1 RED RED RED RED RED
MR 4 5 6 R1
MC 4 5 6
RE6
S4 S5 S6 S28 S24
47
BTN_2 /
D28 D29 D30 D31 D32
MS 1 2 3 */ RED RED RED RED * RED
S7 S8 S9 S25 S21 R10
MS 1 2 3
RE7
BTN_3
47
+/- 0 + -=
D37 D36 D35 D34 D33
S11 S10 S12 S27 S23 RED RED RED RED - RED
R2
+/- 0 + =
RE8
47
*
.
Slider
BTN_9
10F +3.3V
FIGURE A-3:
RE4
RE3
RE2
RE1
RE0
RD7
RD6
RD5
RD4
RD3
RD2
RD1
RD13
RD12
99
98
97
96
95
94
93
92
91
90
89
88
87
86
85
84
83
82
81
80
79
78
77
76
100
RE4
RE3
RE2
RE1
RE0
RA7
RA6
RD6
RG0
RG1
RD13
RD12
RG13
RG12
RG14
TA5/RD3
TA3/RD1
TC6/RF1
TC1/RD7
ENVREG
1 75
TA4D/RD2
RG15 Vss
PMPRD/RD5
PMPWR/RD4
+3.3V Vdd TA0/RC14
TC7/VBUSS/RF0
3 73
VCAP/VDDCORE
C1 RE5 PMPD5/RE5 TA1/RC13
4 72
.1F RE6 SCL3/PMPD6/RE6 INT0/RD0
5 71
RE7 SDA3/PMPD7/RE7 RD11
6 70
RC1 RC1 RD10 RD10
+5V 7 69
RC2 RC2 RD9 RD9
BZ1 8 68
RC3 RC3 RD8 RD8
+3.3V
9 67
RC4 RC4 SDA1/RA15
10 66
RG6 PMPA5/RG6 SCL1/RA14
R24
+
11 U1 65 NL
- BUZZ PMPA4/RG7 Vss R25
1K 12 64
R41 PMPA3/RG8 OSC2/CLK0/RC15 OSC2 Y1
13 63
+3.3V MCLR MCLR PIC24FJ256GB110 OSC1/CLKI/RC12 OSC1 OSC2
10K 14 62 8MHz
PMPA2/RG9 Vdd +3.3V
15 61
Vss TDO/RA5 C4
C5 16 60
+3.3V Vdd TDI/RA4 .1F
.1F 17 59 C9 C10
C2 RA0 SDA2/RA3
18 58 22pF 22pF
.1F RE8 RE8 SCL2/RA2
19 57
RE9 RE9 D+/RG2 D+
20 56
BTN_5 AN5/SCK1/RB5 D-/RG3 D-
21 55
BTN_4 AN4/SDO1/RB4 VUSB +3.3V
22 54
BTN_3 AN3/RB3 VBUS VBUS
23
BTN_2 AN2/RB2 RF8
53
24
BTN_1 AN1/RB1 RF2
52
25
BTN_0 AN0/SDI1/RB0 USBID
51
AN11/RB11
AVss
AVdd
VREF-/RA9
Vss
Vss
TCK/RA1
RF4
RF5
VREF+/RA10
AN7/RB7
AN8/RB8
AN9/RB9
Vdd
RF13
RF12
Vdd
RD14
RD15
AN6/SCK1/RB6
AN10/RB10
AN12/RB12
AN13/RB13
AN14/RB14
AN15/RB15
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
PICDEM™ TOUCH SENSE 2 DEMO BOARD SCHEMATIC (PAGE 2 OF 3)
BTN_6
BTN_7
BTN_8
BTN_9
BTN_11
BTN_10
BTN_12
BTN_13
BTN_14
BTN_15
+3.3V +3.3V
C13 C6
.1F .1F +3.3V
C7
.1F
AN1250
DS01250A-page 17
BTN_14 +3.3V +3.3V +3.3V +3.3V +3.3V +3.3V +3.3V +3.3V +3.3V +3.3V
R19 R20 R21 R22 R23 R26 R28 R27 R30 R32
BTN_13 BTN_11 470 470 470 470 470 470 470 470 470 470
FIGURE A-4:
D19 D20 D21 D22 D23 D24 D27 D26 D38 D65
GRN YEL GRN YEL GRN YEL GRN YEL RED YEL
DS01250A-page 18
BTN_12
AN1250
RD6 RD7 RC1 RC2 RC3 RC4 RD12 RD13 RG6 RE9
retneC rewoP
J3
mini-B PICkit™2Program
D11
VBUS
1
VBUS +5V
HeaderforU1
BTN_15 POWER
S20 2 PICkit2
D- D- MBR0520L
3 R18 100
D+ D+ VPP MCLR
6
4 VDD +5V
5
5 VSS GND
4
Shield PICkit2PROGRAM
ICSPDAT PGM2 HEADERFORU1
3
6
ICSPCLK PGM1
2
NOCONNECT
1
J1
1
BTN_6
4
PGM1
3
2
BTN_7
PGM2
219-2MST
Optional(unpopulated)
D18
1 3 2 3 2
IN OUT IN OUT +3.3V
3 MRA4003
GND GND
2 C14 C16 C27
C15 C17 C26 C18
1 1
.1F 47F 47F.1F 1F 33F .1F
PJ-002B
TP3
1 2 1 2
3
3
4 4
• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
• Microchip is willing to work with the customer who is concerned about the integrity of their code.
• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
01/16/09