COMPARE Mode, Result
Enable or disable the SX comparator, compare voltages on RB.1 and RB.2, and retrieve comparison result to store in Result.
|SX18 / SX20 / SX28 / SX48 / SX52|
|Mode values||0: Disables comparator.|
|1: Enables comparator with RB.0 as Result output.|
|2: Enables comparator without RB.0 as Result output.|
|Result values||0: Voltage RB.1 > RB.2; RB.0 optionally outputs 0.|
|1: voltage RB.1 < RB.2; RB.0 optionally outputs 1.|
The COMPARE instruction enables or disables the built-in comparator hardware on the SX's pins RB.0, RB.1, and RB.2. I/O pins RB.1 and RB.2 are the comparator inputs and RB.0 is optionally the comparator result output pin.
By default, the comparator feature is disabled. Using the COMPARE instruction with a Mode argument of 1 or 2 enables the comparator feature (using input pins RB.1 and RB.2) and returns the result of the comparison in Result. If Mode is 1, the result of the comparison is also output on I/O pin RB.0. The following is an example of the COMPARE instruction:
COMPARE 1, result ' enable comparator, output result on RB.0
This example enables the comparator (setting RB.0 to output the result, with RB.1 and RB.2 as the comparator inputs) and writes the result of the comparison into result. Both result and the output pin RB.0 will be 0 if the input voltage on RB.1 was greater than that of RB.2. Result and the output pin RB.0 will be 1 if the input voltage on RB.1 was less than that of RB.2.
The following are points to remember with Comparator mode:
Related project: 8-bit ADC