do the negative/ref pins for a comparator have to be held above 0v or can I just ground them (I wonder what it does when both are at 0v)?
A comparator compares two voltages.
If the (+) pin is larger than the (-) pin then the output is high.
If the (+) pin is smaller than the (-) pin then the output is low.
More or less; if (+) = (-) then the output is unknown.
For the comparator to work the two inputs must be within the "common mode range". This part: that range is from supply to supply. 0 to 5V Many parts will work to a slightly negative level. Most parts will not work near the upper supply. ( 5V-1.5= 3.5V)
This part has hysteresis of about 9mV. Most do not have!
>If one input is at 1V and the other starts at 0V and ramps up to 2V the output will switch at input = 1.009V. (input going up)
>If one input is at 1V and the other starts at 2V and ramps down to 0V the output will switch at input = 0.991V. (input going down)
If there was no hysteresis the two points would be very close to 1.0000000? volts.
"Input offset voltage": This is an error voltage. The part can not be made perfectly. This part typically has an error of 0.0005 volts but could be as far off as +/-0.03V.
> One input is at 1.00000 volts and the other input is varied to see what happens. Worse case the comparator might switch as high as 1.03 volts or as low as 0.97V. (+/- 30mV)
PIC output: The output likely will not reach 0V. Very close.
Why you should not connect one input to 0V:
>0V is at the very lowest the part will work at. common mode range
>The other input will need to go 9mV below ground to get the part to change output states. hysteresis Also Hysteresis has a min/typ/max range.
>The input offset range will cause the part to see 0V as anywhere from -30mV to +30mV.
Connect one input directly to the PIC pin. Connect the other pin to a supply that is 1/2 supply. This will solve all the above problems.
>For CMOS parts like the PIC use 1/2 supply. For TTL pars use a supply that is in the center of the data range.
>Example using TTL: low = 0 to 0.8V, high = 2 and above. So set the compare voltage to be about 1.5 volts.