A difference amplifier will do what you want, but it has a potentially serious problem. The input impedances are not well defined, or matched. Referencing Jay's circuit, the input impedance of the noninverting side is \$R_1+R_f\$. That is as close to a defined input impedance as we get with this topology. Since there is negative feedback, the inverting pin will track the noninverting pin. What would normally be a virtual ground is now varying based on \$V_+ \$, and with it the input impedance of the inverting side.
If this issue is a problem for your application, a better option would be an instrumentation amplifier.
\$V_{out}=(1+\dfrac{2R_1}{R_{gain}})(\dfrac{R_3}{R_2})(V_2-V_1)\$
The inputs are buffered and have matched input impedances, equal to the op amp input impedance. You can either build one yourself, or buy an IC. An IC solution will ultimately have better performance, especially in common mode rejection.
As a first approximation, there isn't a difference. A similar question might be "what's the difference between a DC motor and a generator?" Either will function in either capacity, but each is optimized to maximize certain qualities at the expense of others, according to the intended application.
Let's compare the internal schematic for a common op-amp, TL072, and a common comparator, LM339:
TL072
LM339
Things in common:
- differential pair input
- very high gain
Differences:
The TL072 uses JFETs for the input. This is because JFETs provide extremely high input impedance, which is desirable for an op-amp. Most op-amp analysis assumes that the bias currents (the currents moving through the inputs) are zero, but this is only true to the extent that the input impedance is infinite. For a comparator, you do want high input impedance to avoid loading the source excessively, but it's not so important that input impedance is very high.
The LM339 has an open collector output. For a comparator, this is good, because it allows it to interface with any number of output voltages through a pull-up resistor, or trivially implement a wired-or bus. You wouldn't want this for an op-amp, because usually, you want an op-amp to be as good at sourcing current as sinking it, so that your output waveform is symmetrical. Notice the NPN-PNP push-pull pair output of TL072.
The LM339 can pull the output as low as 0.2V or as high as \$V_{cc}\$, by virtue of its open-collector output. TL072 specifies an output voltage swing of \$\pm 10V\$ when \$Vcc = 15V\$ when the load is less than \$2k\Omega\$.
An experienced IC designer could probably point out more differences, from the schematic alone. I'm not one of those, but I can see the differences in the datasheets. For example, I don't see a common-mode or power-supply rejection ratio, harmonic distortion, or noise figure specified at all for LM339. These could be measured for a comparator, and you will find them in every op-amp datasheet, but for a comparator application, these parameters aren't especially relevant, so they aren't specified, and if they were, would likely be very poor.
So, in every case, you could use an op-amp as a comparator, or a comparator as an op-amp, if your requirements are not very demanding. Given the difference in how the parts are specified, it may not be possible to know from the specifications how it will even perform.
Best Answer
An LM339 is ALWAYS a differential comparator.
The impression that there are "general purpose" non differential versions is probably because somebody has missed out the term "differential" without intending it to mean not-differential.
A reference to a page that seems to say otherwise would allow us to explain the confusion.
Differential comparators - overview of meaning of the term:
In the following I will refer to 'signal' or 'voltage' when I talk about what is amplified. The description can be extended to other variables as required.
Integrated Circuit comparators are essentially all "differential.
The term "differential comparator" essentially means
"a device that compares and acts on the difference between two variables"
so for a comparator to not be differential is, in the strict sense, impossible.
The terms differential or (implied) non-differential are more usually used for amplifiers. Here the terms make some sense but even a non-differential amplifier IS a differential amplifier at heart. Because -
A differential amplifier is one which amplifies the difference between two points (usually a voltage difference) where neither point is "ground".
A non differential amplifer amplifies the magnitude of a signal without explicit reference to another signal point BUT the actual reference is usually circuit ground. In a few cases a signal is amplified "in isolation" but here the reference point is the centre of the input signal if not otherwise specified, and, if the output signal has a new centre point it is said to have an "offset" - which is an acknowledgement that the original reference point was the centre of the input signal.
It is arguable that you could build a comparator that would not be described as "differential" but this would be unusual. This could occur if you used ground as one input.
So, a 3V comparator would operate when the input was at 3V above ground - the other unseen differential input would be connected to a reference point 3V above ground.