Техническая Спецификация для Microchip Technology ARD00385

Скачать
Страница из 570
PIC18F87K90 FAMILY
DS39957D-page 418
 2009-2011 Microchip Technology Inc.
27.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.
27.5.1
ABSOLUTE CAPACITANCE 
MEASUREMENT
For absolute capacitance measurements, both the
current and capacitance calibration steps, found in
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, C
TOTAL
 = (I * T)/V,
where:
• I is known from the current source 
measurement step (
• T is a fixed delay
• V is measured by performing an A/D 
conversion
8.
Subtract the stray and A/D capacitance
(C
OFFSET
 from 
) from C
TOTAL
 to determine the
measured capacitance.
27.5.2
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
.)