2007 Microchip Technology Inc.
Preliminary
DS39775B-page 339
PIC18F87J50 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.
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, CxINC, CXIND or the micro-
controller’s fixed internal reference voltage (V
IRV
, 1.2V
nominal) on the inverting channel. The comparator
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 CCH1:CCH0 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 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 V
SS
and V
DD
, 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 23.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.
23.5.1.1
Comparator Configurations in 64-Pin
and 80-Pin Devices
In PIC18F87J50 family devices, the C and D input
channels for both comparators are linked to pins in
PORTH and cannot be reassigned to alternate analog
inputs. Because of this, 64-pin devices offer a total of 4
different configurations for each comparator. In con-
trast, 80-pin devices offer a choice of 6 configurations
for
Comparator
1,
and
Comparator 2. The configurations shown in Figure 23-4
are footnoted to indicate where they are not available.
8
configurations
for
23.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 RF1 and RF2 I/O pins
by setting the COE bit
(CMxCON<6>). When enabled, multiplexors in the
output path of the pins switch to the output of the com-
parator. The TRISF<1:2> bits still function as the digital
output enable for the RF1 and RF2 pins while in this
mode.
By default, the comparator’s output is at logic high
whenever the voltage on V
IN
+ is greater than on V
IN
-.
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 23.2
“Comparator Operation”
.
Comparator
Input or Output
I/O Pin
1
C1INA (V
IN
+)
C1INB (V
IN
-)
C1INC (V
IN
-)
(1)
C1OUT
C2INA(V
IN
+)
C2INB(V
IN
-)
C2INC(V
IN
-)
(1)
C2IND(V
IN
-)
(1)
C2OUT
RF6
RF5
RH6
(1)
RF7
RF5
RF2
RH4
(1)
RH5
(1)
RC5
2
Note 1:
Available in 80-pin devices only.
Note:
The comparator input pin selected by
CCH1:CH0 must be configured as an input
by setting both the corresponding TRISF or
TRISH bit, and the corresponding PCFG bit
in the ANCON1 register.