Datasheet

2011 Microchip Technology Inc. DS39932D-page 365
PIC18F46J11 FAMILY
22.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.
Both comparators allow a selection of the signal from
pin, CxINA, or the voltage from the comparator refer-
ence (CV
REF) on the non-inverting channel. This is
compared to either CxINB, CTMU or the microcon-
troller’s fixed internal reference voltage (V
IRV, 0.6V
nominal) on the inverting channel.
Table 22-1 provides the comparator inputs and outputs
tied to fixed I/O pins.
Figure 22-4 illustrates the available comparator
configurations and their corresponding bit settings.
TABLE 22-1: COMPARATOR INPUTS AND
OUTPUTS
22.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
IRV), to the
comparator V
IN-. Depending on the comparator operat-
ing mode, either an external or internal voltage
reference may be used. The analog signal present at
V
IN- is compared to the signal at VIN+ 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
reference 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 (CV
REF) from
the comparator voltage reference module. This module
is described in more detail in Section 22.0 “Compara-
tor 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.
22.5.2 COMPARATOR ENABLE AND
OUTPUT SELECTION
The comparator outputs are read through the CMSTAT
register. The CMSTAT<0> reads the Comparator 1 out-
put and CMSTAT<1> reads the Comparator 2 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.
By default, the comparator’s output is at logic high
whenever the voltage on V
IN+ is greater than on VIN-.
The polarity of the comparator outputs can be inverted
using the CPOL bit (CMxCON<5>).
The uncertainty of each of the comparators is related to
the input offset voltage and the response time given in
the specifications, as discussed in Section 22.2
“Comparator Operation”.
Comparator Input or Output I/O Pin
1
C1INA (V
IN+) RA0
C1INB (VIN-) RA3
C1OUT Remapped
RPn
2
C2INA(V
IN+) RA1
C2INB(VIN-) RA2
C2OUT Remapped
RPn
Note: The comparator input pin selected by
CCH<1:0> must be configured as an input
by setting both the corresponding TRIS
and PCFG bits in the ANCON1 register.