easy way to create small voltages for the analog comparator

I often come across a situation where you want some signal to "flip" the analog comparator.
for example to count sines or detect a zero crossing.
to do that, you compare this signal to 0 volts by connecting one of the comparator inputs to gnd. easy.

but if the signal is absent, then the faintest noise does the same : it flips the comparator.
this is "not good" (tm).

So, instead of comparing to 0 volts you would like to compare the signal to (say) a few millivolts,
to suppress the noise-caused comparator flips.

I have had good results putting a digital pin in input mode with pullup enabled.
the pullup is 20k. connect this pin to ground over (say) a 20 ohm resistor. this gives
20/20000 of 5 volts = 5 millivolts directly on the digital input pin.

connect this input pin to a comparator input to compare the signal to 5 millivolts.
since the comparator ports do not require any significant current, and the input pin can deliver
5/20 of a mA, this does the job handsomely.

Do check with a multimeter the actual voltage generated, because the 20K internal pullup can
have another value (datasheet says 20 to 50k, although I have not measured anything else than 20k),
and the small resistor you added has (probably) also a margin of 10%.

when using batteries and conserving energy by sleeping,
the pin could/should be changed to an output with value 0 volt just before sleep, to minimize current wastage.

Any reason not to connect a voltage divider right to the comparator input to get your 5mV? It would save an I/O pin.

The Ruggeduino: compatible with Arduino UNO, 24V operation, all I/O's fused and protected

O'k, you are using input circuitry to disconnect 20 k Ohm resistors during sleeping,
than what will disconnect your comparator from drain a power? Or it's internal?

Can this method be used to measure output from a strain gauge bridge?

@ruggedcircuits :
of course you can do it in other ways just as well, but this one offers :

  • less additional components on the board (IF you have a pin spare)
  • can be switched off

@Skatun :
maybe, but not directly. for measuring use the ADC.
maybe the voltage generated can be used as the upper limit of
your measurement (the VREF/AREF). have a look at the atmel datasheet for a lot of info on the ADC.

@magician : the comparator can be switched off using the PRR register. the comparator input are very high impedance and do not draw any current. I'm not sure I understand your remark.