Comparator circuit help

Although both the comparator and the opamp have differential inputs they are
designed and function completely differently. The comparator allows a wide range
of differential input values (which an opamp hates). The common mode rejection
ratio also needs to be high. The output circuits are also completely different.
Since the comparator is a digital device, its output is designed and tailored to
switch as quickly as possible from the Vcc you supply to ground and back again.
So it outputs high or low. An opamp on the other hand is an analog device so its
output is designed to deliver a low distorton signal based on its inputs. (It does
not like any discontinuity of input because it cannot follow that very well.)
Also, look at the comparator circuit: do you see a feed back resistor? DO NOT
SUBSTITUTE AN OPAMP FOR A COMPARATOR! It will run open loop leading to overshoot,
undershoot, bursts of pulses or outright oscillation! And the faster the opamp,
the more prone it is to oscillate! The schematic symbols look the same but the
functions are completely different!

Ok.
I'll keep that in mind.
I would probably use an LM339 anyway because they're so cheap and easily available (and I have some).
But thanks for the rundown on that.

wvmarle:
OpAmp and comparator are different things - you can use an OpAmp as comparator (for slow signals - experience taught me a 1 MHz OpAmp as comparator may just be able to handle a 10 kHz signal) but not the other way around.

You can use some opamps as comparators sometimes, usually there will be problems doing this, its not
worth it unless you have a pressing reason to do this and read the datasheet carefully for issues like phase-reversal, input differential mode range, saturation recovery time, output high level limit, output slew rate...

Comparators need a little care in their use as they can be very fast, which means you need to decouple with
the standard 100nF ceramic right on the package pins, and usually add a little hysteresis feedback to avoid glitching. And you have to remember that pull-up resistor!

One thing you can not do is use a comparator as an opamp, they are unstable with negative feedback,
being designed only for positive feedback (hysteresis).

And the Arduino Uno chip has a built-in comparator, not many people realize this, but its hardwired to pins 6 and 7 (digital pins 6 and 7, note!) but pin 7 can be replaced by any of the analog pins with suitable register configuration. There is an interrupt handler for the comparator. The datasheet for the ATmega328P has the gory details.