Microchip Technology DM183037 Data Sheet

Page of 696
 2012 Microchip Technology Inc.
DS30575A-page 521
PIC18F97J94 FAMILY
26.6
Measuring Time with the CTMU 
Module
Time can be precisely measured after the ratio (C/I) is
measured from the current and capacitance calibration
step. To do that:
1.
Initialize the A/D Converter and the CTMU.
2.
Set EDG1STAT.
3.
Set EDG2STAT.
4.
Perform an A/D conversion.
5.
Calculate the time between edges as T = (C/I) * V,
where:
• I is calculated in the current calibration 
step (
)
• C is calculated in the capacitance calibra-
tion step (
)
• V is measured by performing the A/D conversion
It is assumed that the time measured is small enough
that the capacitance, C
AD
 + C
EXT
, provides a valid
voltage to the A/D Converter. For the smallest time
measurement, always set the A/D Channel Select bits
via ADCON1L/H to an unused A/D channel; the corre-
sponding pin for which is not connected to any circuit
board trace. This minimizes added stray capacitance,
keeping the total circuit capacitance close to that of the
A/D Converter itself (25 pF).
To measure longer time intervals, an external capacitor
may be connected to an A/D channel and that channel
selected whenever making a time measurement.
FIGURE 26-3:
CTMU TYPICAL CONNECTIONS AND INTERNAL CONFIGURATION FOR TIME 
MEASUREMENT
PIC18F97J94
A/D Converter
CTMU
CTED1
CTED2
AN
X
A/D Voltage
EDG1
EDG2
C
AD
C
EXT
Current Source