Microchip Technology ARD00385 Data Sheet

Page of 570
 2009-2011 Microchip Technology Inc.
DS39957D-page 393
PIC18F87K90 FAMILY
24.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 Voltage
Reference (CV
REF
) on the non-inverting channel. This is
compared to either CxINB, CxINC, C2INB/C2IND or the
microcontroller’s fixed internal reference voltage (V
BG
,
1.024V nominal) on the inverting channel. The
comparator inputs and outputs are tied to fixed I/O pins,
defined in 
. The available comparator config-
urations and their corresponding bit settings are shown
in 
.
TABLE 24-1:
COMPARATOR INPUTS AND 
OUTPUTS
24.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 (VBG), to the
comparator, V
IN
-. Depending on the comparator
operating mode, either an external or internal voltage
reference may be used. For external analog pins that
are unavailable in 64-pin devices (C1INC, C2INC and
C2IND), the corresponding configurations that use
them as inputs are unavailable.
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
reference 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 from the Compar-
ator Voltage Reference (CV
REF
) module. This module is
. 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.
24.5.2
COMPARATOR ENABLE AND 
OUTPUT SELECTION
The comparator outputs are read through the CMSTAT
register. The CMSTAT<5> bit reads the Comparator 1
output, CMSTAT<6> reads Comparator 2 output and
CMSTAT<7> reads Comparator 3 output. These bits
are read-only. 
The comparator outputs may also be directly output to
the RF2, RF1 and RG1 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 TRISF<2:1> and
TRISG<1> bits still function as the digital output enable
bits for the RF2, RF1 and RG1 pins. 
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 
.
Comparator
 Input or Output
I/O Pin
1
C1INA (V
IN
+)
RF6
C1INB (V
IN
-)
RF5
C1INC
 (V
IN
-)
RH6
C2INB (V
IN
-)
RF3
C1OUT
RF2
2
C2INA (V
IN
+)
RF4
C2INB (V
IN
-)
RF3
C2INC
(
(V
IN
-)
RH4
C2IND
 (V
IN
-)
RH5
C2OUT
RF1
3
C3INA (V
IN
+)
RG2
C3INB (V
IN
-)
RG3
C3INC (V
IN
-)
RG4
C2INB (V
IN
-)
RF3
C3OUT
RG1
Note 1:
C1INC, C2INC and C2IND are all 
unavailable for 64-pin devices 
(PIC18F6XK90).
Note:
The comparator input pin, selected by
CCH<1:0>, must be configured as an input
by setting both the corresponding TRISF,
TRISG or TRISH bit and the corresponding
ANSELx bit in the ANCONx register.