Comparators
From Mechatronics Wiki
A comparator subtracts two voltages and gives you a logic output. Thus it lives at the boundary between the analog world of continuous voltages, and the digital world of 1's and 0's, represented by +5V and 0V, logic high and logic low.Comparators have two inputs, called inverting and non-inverting inputs, and labeled simply - and + on a circuit diagram. We will call the potential at these inputs V-- and V+. Don't confuse these inputs with power supply connections! See figure 1: inputs on the side, power on the top and bottom. Often power is not even shown, but if you neglect to provide it the chip won't work.
The output of a comparator is logic high (+5V) if V+ > V-- and low (0V) if V+ < V-- . If they are within about 1mV of equal, anything goes.
Comparators are much like opamps, but opamps intend to have a continuous output Vout = G(V+ - V--), where comparators intend to saturate, that is, always to have a full positive or zero output.
An ideal comparator, like an ideal opamp, has zero output impedance. That means, when it drives its output to 0V, it will maintain 0V regardless of how much current it has to sink in order to do so. Real comparators are pretty good -- if forced to sink too much current they may burn up, but the output voltage won't rise more than 100mV or so.
We will focus on the LM311P, a particularly nice comparator. Look up its datasheet. In the application shown, it is performing as a thresholding detector for a phototransistor. The trimmer potentiometer sets V- to an adjustable potential between 0V and 5V. If the phototransistor receives enough light and conducts enough current to bring V+ above the potential of V-, the output of the comparator goes high.
Why don't they include a pull up resistor inside? Sometimes they do. However, the open collector output allows you to pull it up to other voltages besides +5 at your whim, for instance to +3 or +24, or to drive an LED (and its limiting resisitor.) You can also arrange several comparators "wired OR", meaning the outputs of several comparators are connected and if any of them pulls the output to ground, it dominates all the others. You couldn't do that if one was pulling the output high and another pulling it low.
There are several limitations, but comparators are nevertheless very easy, robust, useful components.
- Comparators are limited in amount of current they can sink (sink means take to ground.) They can overheat and die. This one can sink 50mA -- a lot by comparator standards.
- Comparators are limited in the pull-up voltage they can withstand. This one can withstand +50V (positive only, mind you!) That's also huge.
- LM311P has several connections you didn't want to know about: strobe, balance, and emitter. Tie strobe and balance to Vcc+ (the positive supply) and the emitter to Vcc- (which is usually ground)
- LM311 runs happily with Vcc+ = 5V and Vcc- = 0V. There are many other ways to use it
- LM311 allows its inputs to range independently anywhere from +15 to -15, without damage. Many comparators are much more finicky. For many, the range of the inputs must not exceed the range between the power supply rails (e.g. 0 to +5)



