Upload
doque
View
215
Download
0
Embed Size (px)
Citation preview
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 1
1337 CTMUCapacitive Touch Sensing
Using CTMU
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 2
1337 CTMU Class Objectives
• When you complete this class you will:• Be familiar with the CTMU module• Use the CTMU for capacitive touch applications• Use tools to tune/optimize CTMU capacitive
touch applications• Use software techniques used for capacitive
touch sensing• Understand how to use the CTMU for time
measurement and other applications
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 3
Agenda: 1337 Cap Touch - CTMU� Introduction to the CTMU Module� Lab 1 – Setting up the CTMU for Cap Touch � Software to Implement Cap Touch� Lab 2 – Reading a Cap Touch Button� Other Uses for CTMU (Theory & Applications)� Advanced Cap Touch Topics� Lab 3 – Matrix Keypad Implementation� Tools for Cap Touch Application Tuning� Lab 4 – Setting up the mTouch™ GUI to tune
buttons� How Materials Properties Affect Cap Touch� Lab 5 – Use of Different Overlays and Re-tuning
the Application � Summary
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 4
What is the CTMU?
Charge Time Measurement Unit
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 5
CTMU Block DiagramCTMUCONCTMUCON
CTMUICONCTMUICON
Edge Edge Control Control LogicLogic
External Edge External Edge Trigger PinsTrigger Pins
Timer1Timer1OC1OC1 Pulse Pulse
Output Output PinPin
CTMU CTMU Control Control LogicLogic
A/D A/D Conversion Conversion
TriggerTrigger
Pulse Pulse Generation Generation
LogicLogic
Comparator 2 OutputComparator 2 OutputComparator 2Comparator 2InputInput
Current SourceCurrent Source
Current Current ControlControl
A/D ConverterA/D Converter
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 6
CTMU Current Source
To A/D Converter
CTMU
Current Source
Trigger Starts/Stops Current Source
Discharge
Current Source charges:Capacitive Touch circuitryA/D Converter Cap
Trimmable current sourceRange : 0.55 uA, 5.5 uA and 55 uA
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 7
PIC® MCU A/DPIC® MCU A/D with CTMUCTMU Interface with ADC
A/D Converter
Current SourceA/D Conversion Trigger
CTMU
Sensor 0
CCA/DA/D
Sensor 15
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 8
Uses for the CTMU� Capacitance Measurement (Relative)
� Capacitive Touch� Stud Finder
� Capacitance Measurement (Absolute)� Humidity Sensor� Capacitance Meter
� Resistance Measurement� Sensors
� Inductance Measurement� Inductive Touch
� Time Measurement� TDR Cable Length Measurement� Flow Measurement
� Temperature Measurement� Thermostat
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 9
Parts with CTMU
More to follow in PIC24F and PIC18F families…
Part Family Architecture No. Ch XLP? USB Pin Count Flash (kbytes)
PIC18F87J90 8-bit 12 No No 64, 80 128PIC18F 46J11 8-bit 13 Yes No 28, 44 64PIC18F 46J50 8-bit 13 Yes Yes 28, 44 64PIC24FJ256GA1 16-bit 16 No No 64, 80, 100 64,128,192,256
PIC24FJ256GB1 16-bit 16 No Yes 64, 80, 100 64,128,192,256
PIC24FJ64GA1 16-bit 12 No No 28, 44 32, 64PIC24FJ64GB004 16-bit 12 Yes Yes 28, 44 64PIC24F16KA102 16-bit 7, 9 Yes No 14, 20, 28 4, 8, 16
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 10
Microchip Cap TouchmTouch™ Sensing Solutions use two methods:� Frequency Measurement (Relaxation Oscillator)
� Touch sensor is the C in an RC oscillator
� Voltage Measurement (Charge Time Measurement) � Capacitor is charged for a fixed time and the voltage is measured.
Voltage MeasurementFrequency Measurement
Vout
VCap
VCs
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 11
How is the CTMU usedfor Capacitive Touch?
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 12
Theory of operation: Introduction of finger produces a parallel capacitance
CF
How Does it Work?
CP
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 13
How CTMU Works for Capacitive Touch
EE101 basics:� Instantaneous Current in a capacitor
i = C · dV/dt� If i = constant current, then
I = C · V/t I · t = C · V
� If I and t are held constant, as C increases, V must decrease
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 14
__
CTMU Touch Circuit Components
A/D Converter
Current Source
CADCCIRCSWCF
VAD
Discharge
Trigger
CTMU
I = C· Vt
CP = CAD + CCIR + CSW = 30pFCF = 7pF
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 15
Sample Calculations
CP = CAD + CCIR + CSW = 30pFCF = 7pF
__I = C· Vt
____I =C· Vt
• I = 5.5µA• t = 10µS• CP = 30pF
V = 1.833
• I = 5.5µA• t = 10µS• C = CP + CF = 37pF
V = 1.486
When un-touched
When touched
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 16
Lab 1: Setting up the CTMU for Cap Touch
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 17
Lab 1a Objective� Gain a basic understanding of the CTMU
control registers (CTMUCON & CTMUICON)� Be able to set up the CTMU for cap touch
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 18
Lab 1a InstructionsPart 1a: Find the CTMU setup in the
initialization routine:� Set Registers CTMUCON and CTMUICON for
Capacitive Touch sensing� Use PIC24FJ256GB110 Family Data Sheet
for CTMU register details� Actual Part we are using is PIC24FJ128GB106
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 19
PIC24FJ256GB110 Data Sheet
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 20
Lab 1a Tips� Use the highest current setting for the CTMU
(55 uA)� Make sure the current source is OFF� Enable the CTMU last in init routine
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 21
Lab 1a Result
� Compile, Program, and Run the project
� An LED should light when the ‘8’ key is touched
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 22
Lab 1a Solution//setup CTMU
//CTMUCONCTMUCONbits.CTMUEN = 0; //make sure CTMU is disabledCTMUCONbits.CTMUSIDL = 0; //CTMU continues to run in idle modeCTMUCONbits.TGEN = 0; //disable edge delay generation mode CTMUCONbits.EDGEN = 0; //edges are blockedCTMUCONbits.EDGSEQEN = 0; //edge sequence not neededCTMUCONbits.IDISSEN = 0; //Do not ground the current sourceCTMUCONbits.CTTRIG = 0; //Trigger Output is disabledCTMUCONbits.EDG2POL = 0; //N/A since edges are blockedCTMUCONbits.EDG2SEL = 0x3; //Edge2 Src = OC1 (also N/A)CTMUCONbits.EDG1POL = 1; //N/A since edges are blockedCTMUCONbits.EDG1SEL = 0x3; //Edge1 Src = Timer1 (also N/A)
//CTMUICON
CTMUICON = 0x300; //55uA//or// CTMUICONbits.IRNG = 0x03; //55uA//optional
CTMUICONbits.ITRIM = 0; //Nominal - No Adjustment
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 23
Lab 1b: What does it Look Like?
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 24
Lab 1b Objective� Observe the CTMU charging of a
Capacitive Touch Button� See a difference in the CTMU charging
waveform when a finger is touching the button
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 25
CTMU Full Waveform
Begin Charge
End ChargeA/D Conversion
Discharge
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 26
CTMU Waveforms Untouched & Touched
Not Touched
Touched
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 27
Lab 1b Summary
� A touch is visible on the oscilloscope� The CTMU current source charges the
cap touch button in a very linear manner� Leakage of the cap touch circuit can also
be observed on the oscilloscope
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 28
Lab 2: Reading a Cap Touch Button
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 29
Lab 2 ObjectivePerform the 5 basic steps to read a CTMU cap touch
button:1. Discharge Circuit to ensure a start from 0 Volts
(this has been done)2. Turn on Current Source to charge touch circuit3. Wait for a fixed time period (2 uS for this hardware)4. Turn off Current Source to stop charging touch
circuit5. Perform A/D conversion to read voltage present on
touch circuit
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 30
� 8KeyBoard.c� CTMUcapsense.c� Timer4.c� 8KeyBoard.h� CTMUcapsense.h� Timer4.h
Lab 2 General Information: Project Files
Open Lab2 – C:\MASTERS\1337\Lab2
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 31
Lab 2 General Information: Main() Routine
New Data to process?
Start
Initialization
Service USB
Service otherapplication tasks
N
Stop Timer 4
Process New CapTouch Data
Start Timer 4
Y
Timer 4 Sets this variable
Insures no interrupt whileprocessing new data
Lab 2 code here
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 32
Lab 2 General Information: Timer 4 ISR
Timer 4 Interrupt(1 mS)
Process CTMUChannel
All ChannelsRead?
Increment Channelto read
Exit ISR
N
Reset Channel #Set Flag to process
new data
Y
Setup in Init
Lab 2 Code
Check for all CTMUChannels read
Flag is read by main routine
Get ready for next interrupt
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 33
Lab 2 General Information: Application Software Design
•The main program loop processes the Cap Touch data after all of the channels have been scanned
•Timer 4 is used to read a CTMU channel on a 1 mS interval
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 34
Lab 2 Notes� Use MPLAB® IDE breakpoints to look at cap
touch values � Add these variables to the watch window:
� curRawData[] � tripValue[] � AverageData[]
� Tips� Read cap touch buttons multiple times for better
reliability and noise rejection� The slow averaging of the cap touch button values
allows environmental changes to be nulled out of the cap touch buttons
� The cap touch button trip point can be adjusted to allow for higher or lower sensitivity
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 35
Lab 2 Results
� Compile, Program, and Run the project� When any of the 8 keys are touched, a
corresponding LED should light
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 36
Lab 2 Solution#define loopCount 5CTMUCONbits.EDG1STAT = 0; // Clear edge1CTMUCONbits.EDG2STAT = 0; // Clear edge2AD1CON1bits.SAMP = 1; // Manually start ADC sampling
//////////////////////////////////////////////////////////////////////////////////////////CTMUCONbits.EDG1STAT = 1; // 2. Set edge1 - Start Charge//for (zvar = 0; zvar < loopCount; zvar++); // 3. Delay for CTMU charge time//CTMUCONbits.EDG1STAT = 0; // 4. Clear edge1 - Stop Charge//IFS0bits.AD1IF = 0;AD1CON1bits.SAMP = 0; //5. manually initiate an ADC conversion//while(!IFS0bits.AD1IF); // Wait for the A/D conversion to finish
///////////////////////////////////////////////////////////////////////////////////////immediateValue = ADC1BUF0; // Read value from the A/D conversion
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 37
Lab 2 Questions???
� Why use the highest current setting?� Charges the Cap Touch Circuit the
fastest� Insures that PC board capacitor
leakage is overcome
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 38
Lab 2 Questions???
� Why does the voltage vary from button to button?� Button distance from microcontroller� Button shape� Proximity to other buttons and board
traces
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 39
Lab 2 Questions???
� What is the response time of the cap touch buttons?� Timer 4 reads 1 cap touch channel
every 1 msec� 16 channels are read� 1msec x 16channels = 16 msec
response time
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 40
Lab 2 summary� Charging of cap touch buttons is
dependant on the amount of time the CTMU current source is enabled
� Reading of multiple cap touch buttons is easy; simply change the channel selected by the A/D converter and repeat the routine
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 41
Software DesignKey Points
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 42
Averaging Algorithm
� Why is it needed?� A cap touch button reading
varies due to environmental changes
� The Slow Average Routine accounts for these variances
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 43
Capacitance in Real WorldC
ount
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 44
Firmware Algorithm – Averaging
� Compare latest measured value with slow moving average� Automatically adjust for
environmental changes� Can also be ‘guarded’
average� Trip level is relative to
moving average� Other functions
implemented the same as normal buttons:� Debouncing� Touch and release� Etc.
Time
Cou
nts
AbsoluteAverage
SensorTouched
SensorReleased
‘Floating’Trip level
‘Floating’Released level
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 45
Button Detection Challenges
Time
Cou
nts
Dirt/Sudden change
Average adjusts to prevent‘stuck’ button
AbsoluteAverage
Trip
Time
Cou
nts
Humidity/Temp variation
Slow Average and detectionlevel moves with change
AbsoluteAverage
Trip
Time
Cou
nts
Power up with ‘hand on sensor’
Adjust Average to newcounts rate
AbsoluteAverage
Trip
Time
Cou
nts
Normal Button Detection
React on ‘button’press
AbsoluteAverage
Trip
React on ‘button’release
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 46
Software Tips & Tricks for Better Cap Touch Reliability
� Use a software debounce routine� Use a dynamic calculation of the cap touch
button trip point� Set all buttons as I/O pins (output, ‘0’ value)
except for the button being currently read� Shift the 10-bit A/D value to a 16-bit value� Freeze calculation of slow average when a
button press is detected� Reset the slow average value to the current
value when a button release is detected
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 47
Software Tips & Tricks #1
Start
Read Sensor
Sensor ReadingPressed?
Pressed_Count = 0
Unpressed_Count++
Unpressed_Count > = 3?
Unpressed
NUnpressed_Count = 0
Pressed_Count++
Pressed_Count > = 3?
Y
Pressed
Y
N N
Y
A
A
Use a software debounce routine
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 48
Software Tips & Tricks #2
� As Environment changes the un-pressed value of the cap touch button, the trip value is a bigger/smaller percentage of the value read
� Example:1. First Condition
� Initial un-pressed value = 500� Assume fixed Trip value = 100� Required shift for press = 20%
2. Second Condition� Initial un-pressed value = 250� Same fixed Trip value = 100� Required shift for press = 40%
050
100150200250300350400450500
Condition 1 Condition 2
Unpressed
Trigger
% ChangeReq'd
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 49
Software Tips & Tricks #3
� Re-calculate the Trip point values when the slow average is updated
� Use a fixed value for the trip point divisor:
1. First Condition (use 5 as a divisor)
� Initial un-pressed value = 500� Trip value = 500/5 (100)� Required shift for press = 20%
2. Second Condition (again, use 5 as a divisor)
� Initial un-pressed value = 250� Trip value = 250/5 (50)� Required shift for press = 20%
050
100150200250300350400450500
Condition 1 Condition 2
Unpressed
Trigger
% ChangeReq'd
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 50
Software Tips & Tricks #4
� Setting all adjacent cap touch buttons to “ground” potential minimizes the amount of stray capacitance and stabilizes the reading of the cap touch button.� Set ADC pin configuration to all digital except channel
being read� Set TRIS bits for all channels except current channel to
output pins� Drive the outputs low, which effectively grounds the cap
touch button
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 51
Software Tips & Tricks #5
� Shifting to a 16-bit value helps with the accuracy of the slow moving average Example:� Use 5 values for the average (10-bit)
807, 820, 761, 779, 794 (Avg = 792)� Use 5 shifted values (16-bit)
51648, 52480, 48704, 49856, 50816 (Avg = 50701)
This allows better accuracy without having to use floating point math
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 52
Software Tips & Tricks #6
� Use for button functions that require a long hold time
Code Example: if(avg_delay[Index] == NUM_AVG)
{ if(buttonState[Index] ==PRESSED)
{// Skip average calculation.}
}* This is also known as a gated average
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 53
Software Tips & Tricks #7
� Allows better response when a button is released
� Allows for better performance for repetitive button presses Example:if (curRawData[Index] > averageData[Index])
{averageData[Index] = curRawData[Index]; // If curRawData is above Average, reset to high average.
}
* This is the second half of the gated averaging method
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 54
What Else Can the CTMU do?
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 55
CTMUWhat Else Can the CTMU Do?� Time Measurement� Capacitive Measurement� Temperature Measurement� Inductive Measurement� DAC Applications� PWM / Pulse Delay Applications
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 56
1337 CTMUTime Measurement
Using CTMU
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 57
Time Measurement - CTMUTypical Applications� Time Domain Reflectometry (TDR)� Distance Measurement (laser or RF)� Adaptive Cruise Control� Safety Braking
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 58
Time Measurement - CTMUBack to CTMU basics� I = C(dV/dT) or EQ 1� dT = (C/I)dV Integrate EQ 2� If I and C are constants, then after
integration� T = (C/I)V + K EQ 3� In General K will be 0
� So T is proportional to V
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 59
Time Measurement - CTMU
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 60
Time Measurement - CTMU
VideoDemonstration
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 61
Time Measurement - CTMUResolution Calculations� Assume
� I = 55uA� C = CADC + CPAD + CPIN + CSTRAY = 15pF
� If VDD = 3.0V then V = 3/1024 = 2.93mV� T = (15pF/55uA) * 2.93mV = 0.799nS
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 62
Time Measurement - CTMUCalibration� Assume 0.01% Crystal� Using Software create two precision
times� Set CTED1, Set CTED2 (time 1)� Set CTED1, Nop, Nop, Set CTED2(time2)
� Use these two times to calculate the values for C/I and K in Eq 3
� No need to find exact values for C and I
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 63
Time Measurement - CTMUTips for Increasing Resolution� Use an external VREF of 2.5V
� T = (15pF/55uA) * (2.5/1024) = .666nS� Use an External High Resolution ADC
� Use an external 16 bit ADC� Assume capacitance is doubled to 30pF� T = (30pF/55uA) * (3.0/65536) = 24.9pS
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 64
Time Measurement - CTMU
PIC24F or PIC18FWith CTMU
16 BIT ADCANx
PORTx.[7:0]
Processor Interface
8
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 65
1337 CTMUCapacitance Measurement
Using CTMU
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 66
Capacitance Measurement - CTMU
Typical Applications� Test Equipment Capacitor Meter� Humidity Measurement� Capacitive Microphone
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 67
Capacitance Measurement - CTMU
Back to CTMU basics� I = C(dV/dT) or EQ 1� dT = (C/I)dV Integrate EQ 2� If I and C are constant during the reading� C = (T*I)/V EQ 3
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 68
Capacitance Measurement - CTMU
Calibration� From EQ 3
� C = Cmeasure + CADC + CPAD + CPIN + CSTRAY
� For Calibration Let Cmeasure = 0� Csystem = CADC + CPAD + CPIN + CSTRAY
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 69
Capacitance Measurement - CTMU
Calibration Continued� Method One
� Using Software create two precision times� Set CTED1, Set CTED2 (time 1)� Set CTED1, Nop, Nop, Set CTED2 (time2)
� Use these two times to calculate the values for Csystem , and I in Eq 3
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 70
Capacitance Measurement - CTMU
� Method Two� Add Precision resistor to board
� Measure the current using resistor and ADC
� Measure Csystem
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 71
Capacitance Measurement - CTMU
Resolution� Assume:
� T = 500nS� V = 1V� I = 55uA� C = (55uA*500nS)/1V = 27.5pF� If Voltage Resolution is 3/1024 or 2.93mV � Then 1 bit delta is
� C = (55ua*500ns)/1.00293 = 27.42pf� Delta C = 0.08pF
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 72
1337 CTMUTemperature Measurement
Using CTMU
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 73
Temperature Measurement - CTMU
Typical Applications� Thermostat control for homes� Temperature monitoring of
electronics� Low cost medical thermometers
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 74
Temperature Measurement - CTMU
Basic Diode Equation� I = I0 (e
(qV/kT) -1) EQ 1� I/I0 +1 = e(qV/kT) EQ 2� Ln(I/I0 +1) = qV/kT EQ 3� Ln(I/I0 +1) = B EQ 4� T = qV/kB EQ 5� So Temperature T is proportional to V
voltage across the diode.� This relationship shown in the
following graph
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 75
Temperature Measurement - CTMU
Temperature measurement
0
10000
20000
30000
40000
50000
60000
0 20 40 60 80 100 120
Temperature
AD
C c
ount
(x25
6)
1N4007 1N4148 1N914 LED-D22 2N3904(NPN)LED-D27 2N3906(PNP) 2|| 1N914
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 76
Temperature Measurement - CTMU
Making a measurement� Select ADC channel that diode is
attached to� Enable CTMU� Set EDGESTAT1� Wait for settling time� Read ADC� Calculate Temperature
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 77
Temperature Measurement - CTMU
Calibration� From graphs we have a linear
relation between T and V� Take voltage measurements at two
temperatures� Calculate gain and offset
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 78
1337 CTMUInductance Measurement
Using CTMU
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 79
Inductance Measurement - CTMU
PIC24F or PIC18F with CTMU
CTED1
CTED2
VDD step Function
V0 Response Vo
T
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 80
Inductance Measurement - CTMU
Inductor Equations� I = VDD /R(1 – e(-TR/L)) EQ 1� V0 = VDD (1 - e(-TR/L)) Where V0 = IR EQ 2� 1 - V0 / VDD = e(-TR/L) EQ 3� -TR/L = B Where B=Ln(1 - V0 / VDD ) EQ 4� L = -TR/B EQ 5� Note the linear relationship between T
and L
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 81
Inductance Measurement - CTMU
Resolution CalculationsAssume:� R = 1K� V0 = 1V� VDD = 3V� T = 500nS� L = (-1000/-.405)*500nS = 1.233mH� For a delta of 0.8ns� L = (-1000/-.405)*500.8nS = 1.235mH� Resolution is 2uH
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 82
1337 CTMUDigital to Analog Converter
Using CTMU
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 83
DAC using - CTMU
PIC24 or PIC18 with CTMU
Sample And Hold
AN0
SAMPLE/HOLD
PORT I/O Pin
DAC OUT
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 84
DAC using - CTMUDAC Software� Setup
� Determine desired full scale Time and Voltage� Adjust current source to achieve full scale
voltage at full scale time� Implementation
� Discharge AN0 Pin� Charge AN0 for time T where
� T = TFULLSCALE * Vout / VFULLSCALE
� Sample AN0 With Sample and hold� Hold Voltage
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 85
DAC using - CTMUDAC Resolution� Assumptions:
� Full scale voltage is 2V� Full scale time is 62.5ns *216 or 4.096ms
� Therefore:� dV/dT = 2/4.096mS (or .488uV/nS)
� Since the minimum time step is 62.5nS resolution is .488uv*62.5 or 30.5uv
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 86
1337 CTMUPWM / Pulse Delay
Using CTMU
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 87
PWM / Pulse Delay - CTMU
Typical Applications� Blanking pulse for radar / sonar
systems� High frequency PWM� Precision edge delay for test
equipment
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 88
PWM / Pulse Delay – CTMU Hardware Setup
CTMU
_
+
CV Ref
Current Source
Comparator Input
CTED1
Pulse Input
Comparator Out
CDELAY
CTPLSPulse Output
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 89
PWM / Pulse Delay - CTMU
CTED1
INPUTS
OUTPUTS
Comparator In
CTPLS
CTMUCurrent Source
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 90
PWM / Pulse Delay - CTMUSetting up PWM/Pulse delay� Set TMGENEN bit = 1� Determine Ramp voltage at
maximum delay� Adjust CTMU current source to reach
Max Ramp Voltage at Max time� Program DAC for desired time delay
� VDAC = T/TMAX
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 91
PWM / Pulse Delay - CTMUEDGE Resolution� Assume:
� Full scale voltage of 2V� dV/dT 2V/uS
� With a 10 bit DAC minimum dV is 2/1024 or 1.95mV
� Therefore minimum dT is (1.95mV/2V)uS or .977nS
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 92
Summary of using the CTMU � Time Measurement
� Use CTED1 & CTED2 to start and stop CTMU current source� Time is represented by the voltage read by the ADC
� Temperature measurement� Single Diode only hardware needed� Basic Diode equation used; Temperature is proportional to voltage
� Capacitance Measurement� Use processor instruction cycle time as a fixed quantity� Capacitance is represented by the voltage read by the ADC
� PWM / Pulse Delay� Use Internal Comparator / Internal Reference Voltage� Delay Time is set by the CDELAY connected to comparator input
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 93
Advanced Cap Touch – Matrix Keys and Sliders
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 94
Paired Channel Method
� Expands 4 buttons to 10� 1, 3, 7, & 9 are whole buttons� 2, 4, 5, 6, 8, & 0 are paired
channel buttons� Paired press only produces ½
the capacitance shift � Requires scan of all buttons for
a valid decode� Can not differentiate two
buttons pressed from a paired press
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 95
Matrix Channels� A grid of ‘a’ rows by ‘b’
columns requires (a + b) channels, but implements (a x b) buttons
� Software determines button press after scanning all rows and columns
� Requires high speed scan (esp. for larger matrix)
C1 C2 C3 C4
R1
R2
R3
Q: What is the best optimization of sensor channels for a matrix?A: An Equal Number of Rows and Columns
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 96
Slider
Right SensorRaw Value
100%
0%
Left SensorRaw Value
Cou
nt
� Requires 2 Channels� Basic Equations:� Right Sensor
� % = 100 x (R/(L+R))� Left Sensor
� % = 100 x (1-(L/(L+R)))� Where L and R are the Delta from an
unpressed sensor
Triangular Copper Pads on PC Board
PIC® MCU
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 97
Lab 3: Matrix Keys Implementation
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 98
Lab 3 Objective� Be able to create an algorithm to decode a key
pad created using a matrix of cap touch buttons
� Take action upon cap touch button presses� Understand basic advantages and limitations of
using matrix cap touch buttons
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 99
Lab 3 General Information
� 7 Channels – 3 Rows x 4 Columns� Read all 7 channels normally� Decode the row and column; display the
depressed key� Located in MatrixDecode() function in
CTMUcapsense.c
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 100
Lab 3 Tips� Use channels 8 – 14 for the matrix keypad� Adjust trip points. Capacitance shift will be
lower for 2 reasons:1. Either 3 or 4 cap touch pads connected together2. Your finger is only touching ½ of a normal cap touch
button� Use LED1 – LED12 macros to display the keys
� LED1 = ON or LED1 = 1� LED1 = OFF or LED1 = 0
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 101
Lab 3 Questions?� Could Multiple button presses be detected?� Which tips & tricks can be used to improve
reliability of the matrix keypad?� How could you limit the key selection to a
single key? What would be the criteria for choosing the key?
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 102
Lab 3 Questions � Multiple button detection – possible but limited
to…� Buttons must be on same row or column� Software Algorithm must check for multiple
combinations (i.e. if a row is pressed, each column must be checked for a press)
� Other combinations are not allowed Example: Button 1 (row 1 column 1) & Button 6 (row 2 column 2) ALSO produces Button 2 (row 2 column 1) & Button 5 (row 1 column 2)
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 103
Lab 3 Questions ???
� Which tips & tricks can be used to improve reliability of the matrix keypad?� Use a software debounce routine� Use a dynamic calculation of the cap touch button trip
point� Set all buttons as I/O pins (output, ‘0’ value) except for
the button being currently read� Shift the 10-bit A/D value to a 16-bit value� Freeze calculation of slow average when a button press
is detected� Reset the slow average value to the current value when
a button release is detected
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 104
Lab 3 Questions???
� How could you limit the key selection to a single key? What would be the criteria for choosing the key?� Use an algorithm to find the most pressed row and
column � Lock out any further presses until the currently selected
button becomes unpressed
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 105
Lab 3 Solution// Is a keypad column/row pressed?if (curRawData[Index] < (averageData[Index] - tripValue[Index])) {
switch(Index){
case 8: Col1 = 1; break;
case 9: Col2 = 1; break;
case 10: Col3 = 1; break;
case 11: Col4 = 1; break;
case 12: Row1 = 1; break;
case 13: Row2 = 1; break;
case 14: Row3 = 1; break;
default: break;}
}else // If pressed criteria not reached, set to not pressed{
switch(Index){
case 8: Col1 = 0; break;
case 9: Col2 = 0; break;
case 10: Col3 = 0; break;
case 11: Col4 = 0; break;
case 12: Row1 = 0; break;
case 13: Row2 = 0; break;
case 14: Row3 = 0; break;
default: break;}
}
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 106
Lab 3 Solution (cont’d)//Decode the matrix buttonsif(Col1 != 0) //check column 1{
if(Row1 != 0){
LED1 = ON;}if(Row2 != 0){
LED5 = ON;}if(Row3 != 0){
LED9 = ON;}
}else{
LED1 = OFF;Nop();LED5 = OFF;Nop();LED9 = OFF;
}//repeat for columns 2,3, &4
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 107
Lab 3 Summary
� The CTMU is well suited for matrix key arrangements because of its high speed
� Matrix keys maximize the number of available buttons, while minimizing required I/O
� Matrix keys have limitations� Sensitivity is reduced from standard cap touch
buttons� Multiple button presses not able to be detected
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 108
Lab 4: Using the mTouch™ GUI
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 109
Lab 4 Objective
� Become familiar with using the mTouch™ GUI as a useful tuning tool for Capacitive Touch Applications
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 110
� Open Lab 4 Project in MPLAB® IDE; compile load and run
� Open the mTouch™ GUI -� Choose the “PIC24F CTMU Eval” Radio Button� Choose the “8 Button” Radio Button
Lab 4 General Information
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 111
Lab 4 Summary
� The mTouch™ GUI is a helpful tool for setting up and tuning cap touch applications
� The mTouch GUI has many features:� Viewing of cap touch values� Ability to adjust trip points on the target
application� Graphing of cap touch values� Logging of cap touch values� Ability to scale viewing for any cap touch button
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 112
Lab 5: Using Overlay Materials
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 113
Lab 5 Objective
� Discover how placing an overlay material on the cap touch button affects performance
� Learn how to adjust the cap touch application to compensate for the addition of the overlay
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 114
Lab 5 General Information
� Open, build, and run the Lab 5 project
� Launch the mTouch™ GUI� Place the overlay on the 8 button
daughter board
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 115
Lab 5 Summary
� Introduction of a covering material over a capacitive touch button greatly reduces its sensitivity
� Noise susceptibility is also increased� Software techniques described earlier in
this class are helpful in improving performance
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 116
1337 CTMU Summary� Today we covered:
� The CTMU module and how to use it for:� Capacitive Measurement� Time Measurement
� Designing a Cap Touch Application:� Setting up the CTMU for Cap Touch� Software Algorithms� Overlay Properties
� Using the mTouch™ GUI application as an application tuning aid
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 117
Other Related MASTERs Classes
� 1336 CTF – Capacitive Touch Fundamentals� Introductory Level Course� Tom Perme – Instructor� 2 hour course
� 1338 TSM – Touch Sensing Through Metal� Inductive Touch Class� Keith Curtis – Instructor� 2 hour course
� 1339 TSC – Touch Screen Controllers� Class covers: analog resistive, surface capacitive, and projected
capacitive touch screen technologies� Lance Lamont – Instructor� 2 hour course
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 118
mTouch™ Resources
� mTouch Sensing Solutions Design Center: www.microchip.com/mtouch� Capacitive Sensors by Larry K. Baxter
ISBN 0-7803-5351-X� AN1101 Basic Overview of operation
� Webinar online� AN1102 Hardware and Layout of sensors
� Webinar online� AN1103 Software Techniques for detecting buttons� AN1104 How to get more buttons?� AN1171 Using the CSM� AN1202 Using PIC10F for Capacitive Touch� AN1250 Microchip CTMU for Capacitive Touch Applications� DS39724 CTMU Ref Manual
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 119
Available ResourcesPICDEM™ Touch Sense 1 Development Board• PIC16F-based demo boardDM164125
PICDEM Touch Sense 2 Development Board• PIC24F-based demo boardDM164128
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 120
Available Resources
mTouch™ Diagnostic GUI• For customizing the
Capacitive Touch Solution
MPLAB® Starter Kit for PIC24F• PIC24F Based• 5 Cap Touch Keys• OLED Graphics Display• DM24001
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 121
16F727
100 pt
255 pt
Matrix
Buttons
PKSA
USB 24FJ128GB106
(N-1)*100
$USD 84.95
DM183026: Cap Touch Eval Kit
© 2009 Microchip Technology Incorporated. All Rights Reserved. 1337 CTMU Slide 122
TrademarksThe Microchip name and logo, the Microchip logo, dsPIC, KeeLoq, KeeLoq logo, MPLAB, PIC, PICmicro, PICSTART, rfPIC and UNI/O are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.
� FilterLab, Hampshire, HI-TECH C, Linear Active Thermistor, MXDEV, MXLAB, SEEVAL and The Embedded Control Solutions Company are registered trademarks of Microchip Technology Incorporated in the U.S.A.
� Analog-for-the-Digital Age, Application Maestro, CodeGuard, dsPICDEM, dsPICDEM.net, dsPICworks, dsSPEAK, ECAN, ECONOMONITOR, FanSense, HI-TIDE, In-Circuit Serial Programming, ICSP, ICEPIC, Mindi, MiWi, MPASM, MPLAB Certified logo, MPLIB, MPLINK, mTouch, nanoWatt XLP, Omniscient Code Generation, PICC, PICC-18, PICkit, PICDEM, PICDEM.net, PICtail, PIC32 logo, REAL ICE, rfLAB, Select Mode, Total Endurance, TSHARC, WiperLock and ZENA are trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.
� SQTP is a service mark of Microchip Technology Incorporated in the U.S.A.� All other trademarks mentioned herein are property of their respective
companies.� © 2009, Microchip Technology Incorporated, Printed in the U.S.A., All Rights
Reserved.