English
Language : 

PIC18F26K80-I Datasheet, PDF (240/622 Pages) Microchip Technology – 28/40/44/64-Pin, Enhanced Flash Microcontrollers with ECAN™ and nanoWatt XLP Technology
PIC18F66K80 FAMILY
18.2.5 INTERRUPTS
The CTMU sets its interrupt flag (PIR3<3>) whenever
the current source is enabled, then disabled. An inter-
rupt is generated only if the corresponding interrupt
enable bit (PIE3<3>) is also set. If edge sequencing is
not enabled (i.e., Edge 1 must occur before Edge 2), it
is necessary to monitor the edge status bits and
determine which edge occurred last and caused the
interrupt.
18.3 CTMU Module Initialization
The following sequence is a general guideline used to
initialize the CTMU module:
1. Select the current source range using the
IRNGx bits (CTMUICON<1:0>).
2. Adjust the current source trim using the ITRIMx
bits (CTMUICON<7:2>).
3. Configure the edge input sources for Edge 1 and
Edge 2 by setting the EDG1SEL and EDG2SEL
bits (CTMUCONL<3:2> and <6:5>, respectively).
4. Configure the input polarities for the edge inputs
using the EDG1POL and EDG2POL bits
(CTMUCONL<4,7>).
The default configuration is for negative edge
polarity (high-to-low transitions).
5. Enable edge sequencing using the EDGSEQEN
bit (CTMUCONH<2>).
By default, edge sequencing is disabled.
6. Select the operating mode (Measurement or Time
Delay) with the TGEN bit (CTMUCONH<4>).
The default mode is Time/Capacitance
Measurement.
7. Configure the module to automatically trigger
an A/D conversion when the second edge
event has occurred using the CTTRIG bit
(CTMUCONH<0>).
The conversion trigger is disabled by default.
8. Discharge the connected circuit by setting the
IDISSEN bit (CTMUCONH<1>).
9. After waiting a sufficient time for the circuit to
discharge, clear the IDISSEN bit.
10. Disable the module by clearing the CTMUEN bit
(CTMUCONH<7>).
11. Clear the Edge Status bits, EDG2STAT and
EDG1STAT (CTMUCONL<1:0>).
Both bits should be cleared simultaneously, if
possible, to avoid re-enabling the CTMU current
source.
12. Enable both edge inputs by setting the EDGEN
bit (CTMUCONH<3>).
13. Enable the module by setting the CTMUEN bit.
Depending on the type of measurement or pulse
generation being performed, one or more additional
modules may also need to be initialized and configured
with the CTMU module:
• Edge Source Generation: In addition to the
external edge input pins, ECCP1/CCP2 Special
Event Triggers can be used as edge sources for
the CTMU.
• Capacitance or Time Measurement: The CTMU
module uses the A/D Converter to measure the
voltage across a capacitor that is connected to one
of the analog input channels.
• Pulse Generation: When generating system clock
independent, output pulses, the CTMU module
uses Comparator 2 and the associated
comparator voltage reference.
18.4 Calibrating the CTMU Module
The CTMU requires calibration for precise measure-
ments of capacitance and time, as well as for accurate
time delay. If the application only requires measurement
of a relative change in capacitance or time, calibration is
usually not necessary. An example of a less precise
application is a capacitive touch switch, in which the
touch circuit has a baseline capacitance and the added
capacitance of the human body changes the overall
capacitance of a circuit.
If actual capacitance or time measurement is required,
two hardware calibrations must take place:
• The current source needs calibration to set it to a
precise current.
• The circuit being measured needs calibration to
measure or nullify any capacitance other than that
to be measured.
18.4.1 CURRENT SOURCE CALIBRATION
The current source on board the CTMU module has a
range of ±62% nominal for each of three current
ranges. For precise measurements, it is possible to
measure and adjust this current source by placing a
high-precision resistor, RCAL, onto an unused analog
channel. An example circuit is shown in Figure 18-2.
To measure the current source:
1. Initialize the A/D Converter.
2. Initialize the CTMU.
3. Enable the current source by setting EDG1STAT
(CTMUCONL<0>).
4. Issue time delay for voltage across RCAL to
stabilize and A/D sample/hold capacitor to charge.
5. Perform the A/D conversion.
6. Calculate the current source current using
I = V / RCAL, where RCAL is a high-precision
resistance and V is measured by performing an
A/D conversion.
DS39977F-page 240
 2010-2012 Microchip Technology Inc.