English
Language : 

PIC18F45K80-I Datasheet, PDF (246/622 Pages) Microchip Technology – 28/40/44/64-Pin, Enhanced Flash Microcontrollers with ECAN and nanoWatt XLP Technology
PIC18F66K80 FAMILY
18.5 Measuring Capacitance with the
CTMU
There are two ways to measure capacitance with the
CTMU. The absolute method measures the actual
capacitance value. The relative method only measures
for any change in the capacitance.
18.5.1
ABSOLUTE CAPACITANCE
MEASUREMENT
For absolute capacitance measurements, both the
current and capacitance calibration steps found in
Section 18.4 “Calibrating the CTMU Module” should
be followed.
To perform these measurements:
1. Initialize the A/D Converter.
2. Initialize the CTMU.
3. Set EDG1STAT.
4. Wait for a fixed delay, T.
5. Clear EDG1STAT.
6. Perform an A/D conversion.
7. Calculate the total capacitance, CTOTAL = (I * T)/V,
where:
• I is known from the current source
measurement step (Section 18.4.1 “Current
Source Calibration”)
• T is a fixed delay
• V is measured by performing an A/D conversion
8. Subtract the stray and A/D capacitance
(COFFSET from Section 18.4.2 “Capacitance
Calibration”) from CTOTAL to determine the
measured capacitance.
18.5.2
CAPACITIVE TOUCH SENSE USING
RELATIVE CHARGE
MEASUREMENT
Not all applications require precise capacitance
measurements. When detecting a valid press of a
capacitance-based switch, only a relative change of
capacitance needs to be detected.
In such an application, when the switch is open (or not
touched), the total capacitance is the capacitance of the
combination of the board traces, the A/D Converter and
other elements. A larger voltage will be measured by the
A/D Converter. When the switch is closed (or touched),
the total capacitance is larger due to the addition of the
capacitance of the human body to the above listed
capacitances and a smaller voltage will be measured by
the A/D Converter.
To detect capacitance changes simply:
1. Initialize the A/D Converter and the CTMU.
2. Set EDG1STAT.
3. Wait for a fixed delay.
4. Clear EDG1STAT.
5. Perform an A/D conversion.
The voltage measured by performing the A/D conver-
sion is an indication of the relative capacitance. In this
case, no calibration of the current source or circuit
capacitance measurement is needed. (For a sample
software routine for a capacitive touch switch, see
Example 18-4.)
DS39977F-page 246
 2010-2012 Microchip Technology Inc.