In electronics, it is often useful to compare two voltages and identify which voltage is larger. While operational amplifiers can be used in this application, a dedicated comparator microchip can operate faster, more reliably, and often has additional features which reduce component counts and provide better responses. Comparators are used as null detectors, or triggers to identify when a voltage has reached a reference voltage, zero crossing detectors, level shifters, and in analog-to-digital converters.
A comparator is essentially a very high gain operational amplifier that drives an output to one of two states, high or low, based on the difference between an input voltage and a reference threshold voltage. A comparator can be inverting or non-inverting, which allows the trigger to drive the output either high or low as needed in the circuit. A comparator circuit is essentially a 1-bit analog to digital converter, with a selectable conversion point, which makes the comparator act as a switch triggered by a signal on its input.
OpAmp vs. Comparator
With the similarity between a high gain OpAmp and a comparator, why is there a need for a dedicated comparator IC? If a low offset, low drift, low current and low cost are driving factors than OpAmps may be an acceptable option. However, comparators are specifically designed to operate with digital circuitry and output TTL signals avoiding the lengthy recovery time, long propagation delay, and TTL incompatible output challenges of using OpAmps directly.
The input signal of a comparator is compared to the threshold voltage for the circuit and changes the output voltage based on the input voltage being greater or less than the threshold voltage. A non-inverting comparator drives the output high when the input is more positive than the threshold voltage and an inverting comparator drives the output low when the input voltage is above the threshold voltage. The amount that the input voltage must be above the threshold voltage to trigger a change depends on the gain of the comparator. A comparator with a gain of 80dB (10,000) would require a difference of less than a millivolt for typical circuits powered 5 volts or less (5V/10000=0.0005V).
Of course, with inputs this sensitive, the noise on the input can cause the output to ring, especially with slow changing signals. The answer to this is adding hysteresis, or a return threshold. With hysteresis, once and input crosses the threshold voltage(Vt1) and the output changes, the output is locked until the input voltage drops below a second threshold voltage (Vt2) which is lower than the initial threshold voltage (Vt1). Often the two threshold voltages are referred to as the Lower State Transition Voltage (LSTV) or VTRIP- and Upper State Transition Voltage (USTV) or VTRIP+ to avoid confusion.
Key Specifications of Comparators
Several parameters must be considered when selecting a comparator for any application. As with many components, a speed vs power tradeoff can be made. A very low power comparator will typically not function as fast as one that draws more power. Comparators are generally very quick to respond, so for most applications, low power options with a few nanoseconds of delay will work just fine.
Many comparators are available with hysteresis built in, adjustable with external resistors or set at a few millivolts. If a comparator does not have internal hysteresis, an external network of passive components can be used to build a custom hysteresis. Comparators with a dedicated hysteresis pin greatly simplify the process of setting the hysteresis point, can be made programmable with a digital potentiometer and isolate the input signal from the hysteresis network, a significant benefit if the source impedance is high and cannot take the load a hysteresis network.
The output of a comparator can either be an open drain or push-pull output. Open drain outputs require external pullup resistors to generate a logic high signal while push-pull outputs does not need a pullup resistor and can source a greater amount of current. Open drain outputs can be made to work with multiple TTL voltage levels (5V and 3.3V for example) by using different power supplies with the pullup resistor which is a big benefit if multiple TTL voltages are used on one PCB. Comparators can also have an integrated voltage reference, which eliminates the need of an external voltage reference.