English
Language : 

PIC18F23K22 Datasheet, PDF (325/492 Pages) Microchip Technology – 28/40/44-Pin, Low-Power, High-Performance Microcontrollers with nanoWatt XLP Technology
19.4 Measuring Capacitance with the
CTMU
There are two separate methods of measuring
capacitance with the CTMU. The first is the absolute
method, in which the actual capacitance value is
desired. The second is the relative method, in which
the actual capacitance is not needed, rather an
indication of a change in capacitance is required.
19.4.1 ABSOLUTE CAPACITANCE
MEASUREMENT
For absolute capacitance measurements, both the
current and capacitance calibration steps found in
Section 19.3 “Calibrating the CTMU Module”
should be followed. Capacitance measurements are
then performed using the following steps:
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 (see Section 19.3.1 “Current
Source Calibration”), T is a fixed delay and V is
measured by performing an A/D conversion.
8. Subtract the stray and A/D capacitance
(COFFSET from Section 19.3.2 “Capacitance
Calibration”) from CTOTAL to determine the
measured capacitance.
PIC18(L)F2X/4XK22
19.4.2 RELATIVE CHARGE
MEASUREMENT
An application may not require precise capacitance
measurements. For example, when detecting a valid
press of a capacitance-based switch, detecting a rela-
tive change of capacitance is of interest. In this type of
application, when the switch is open (or not touched),
the total capacitance is the capacitance of the combina-
tion of the board traces, the A/D Converter, etc. A larger
voltage will be measured by the A/D Converter. When
the switch is closed (or is 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.
Detecting capacitance changes is easily accomplished
with the CTMU using these steps:
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
conversion is an indication of the relative capacitance.
Note that in this case, no calibration of the current
source or circuit capacitance measurement is needed.
See Example 19-4 for a sample software routine for a
capacitive touch switch.
 2010 Microchip Technology Inc.
Preliminary
DS41412B-page 325