Datasheet
2012 Microchip Technology Inc. DS30575A-page 493
PIC18F97J94 FAMILY
23.5 Comparator Control and
Configuration
Each comparator has up to eight possible combina-
tions of inputs: up to four external analog inputs and
one of two internal voltage references.
All of the comparators allow a selection of the signal
from pin, CxINA, or the voltage from the Comparator
Reference (CV
REF) on the non-inverting channel. This
is compared to either CxINB, CxINC, C2IND or the
microcontroller’s fixed internal reference voltage (V
BG,
1.2V nominal) on the inverting channel. The compara-
tor inputs and outputs are tied to fixed I/O pins, defined
in Table 23-1. The available comparator configurations
and their corresponding bit settings are shown in
Figure 23-4.
TABLE 23-1: COMPARATOR INPUTS AND
OUTPUTS
23.5.1 COMPARATOR ENABLE AND
INPUT SELECTION
Setting the CON bit of the CMxCON register
(CMxCON<7>) enables the comparator for operation.
Clearing the CON bit disables the comparator, resulting
in minimum current consumption.
The CCH<1:0> bits in the CMxCON register
(CMxCON<1:0>) direct either one of three analog input
pins, or the Internal Reference Voltage (V
BG), to the
comparator, V
IN-. Depending on the comparator oper-
ating mode, either an external or internal voltage
reference may be used.
The analog signal present at V
IN- is compared to the
signal at V
IN+ and the digital output of the comparator
is adjusted accordingly.
The external reference is used when CREF = 0
(CMxCON<2>) and V
IN+ is connected to the CxINA
pin. When external voltage references are used, the
comparator module can be configured to have the ref-
erence sources externally. The reference signal must
be between VSS and VDD and can be applied to either
pin of the comparator.
The comparator module also allows the selection of an
internally generated voltage reference from the Compar-
ator Voltage Reference (CV
REF) module. This module is
described in more detail in Section 24.0 “Comparator
Voltage Reference Module”. The reference from the
comparator voltage reference module is only available
when CREF = 1. In this mode, the internal voltage
reference is applied to the comparator’s V
IN+ pin.
23.5.2 COMPARATOR ENABLE AND
OUTPUT SELECTION
The comparator outputs are read through the CMSTAT
register. The CMSTAT<0> bit reads the Comparator 1
output, CMSTAT<2> reads the Comparator 2 output
and the CMSTAT<3> bit reads the Comparator 3 output
These bits are read-only.
The comparator outputs may also be directly output to
the RPn I/O pins by setting the COE bit (CMxCON<6>).
When enabled, multiplexers in the output path of the
pins switch to the output of the comparator. While in this
mode, the respective TRISx bits still function as the
digital output enable bits for the RPn I/O pins.
Comparator Input or Output I/O Pin
(†)
1
C1INA (V
IN+) RA5/RF6
C1INB (VIN-) RF5
C1INC (V
IN-) RH6
(2)
C2INB(VIN-) RF2
CVREF (VIN+) RF5
C1OUT RPn
(1)
2
C2INA (V
IN+) RA5
C2INB (VIN-) RF2
C2INC (V
IN-) RH4
(2)
C2IND (VIN-) RH5
(2)
CVREF (VIN+) RF5
C2OUT RPn
(1)
3
C3INA (V
IN+) RA5/RG2
C3INB (VIN-) RG3
C2INB (V
IN-) RF2
C3INC (VIN-) RG4
CVREF (VIN+) RF5
C3OUT RPn
(1)
† The I/O pin is dependent on package type.
Note 1: These pins are remappable I/Os.
2: These pins are not available on 64-pin
devices.
Note: The comparator input pin selected by
CCH<1:0> must be configured as an input
by setting both the corresponding TRISx bit
and the corresponding ANSELx bit in the
ANCONx register.