Cornell University ECE4760
Sometimes it is useful to quickly compare two analog voltages. The PIC32 has two fast, stable, comparators. Both comparators optionally have their positive and negative inputs exposed, and optionally their output. The comparators can each optionally generate interrupts. There are also two internal voltage references. Power is gated to these devices to minimize current if not needed. A minimal setup code might be to turn on the unit, enable the output pin, and connect the negative input to the IVref internal source. The output signal C1OUT must be associated with a pin, in this example RB9.
CMP1Open(CMP_ENABLE | CMP_OUTPUT_ENABLE | CMP1_NEG_INPUT_IVREF);
PPSOutput(4, RPB9, C1OUT); //pin18
mPORTBSetPinsDigitalIn(BIT_3); //Set port as input (pin 7 is RB3)
The specifications give you estimates of the accuracy and speed of the unit.
Copyright Cornell University August 29, 2018