Analog Comparator Circuit Design
A comparator answers a question: is the input above the reference or below it. It is often implemented with an operational amplifier, and that is the first mistake, because an amplifier and a comparator are optimised for different things.
Why Not an Operational Amplifier
An operational amplifier is designed to be stable in a closed loop, so it is compensated and its output slews rather than switching. Used as a comparator it is slow and it may oscillate when its output passes through the linear region.
A comparator has no compensation, a high gain and an output that switches between two states as fast as the process allows. Its input stage is designed to recover quickly from an overdrive rather than to be linear.
An amplifier used as a comparator also draws a large supply current during the transition, because both output devices conduct. The current spike is a source of noise and it can disturb the supply of the circuit it is measuring.
input offset voltage and Its Effect
input offset voltage is the difference between the two inputs at which the output changes. It appears directly as an error in the threshold, and it drifts with temperature.
A comparator with an offset of two millivolts used with a reference of a hundred millivolts has a two percent threshold error before any other term. Where the threshold matters, a part with a chopper stabilised input or a trimmed offset is used.
The offset also varies with the common mode voltage, which is the case when both inputs move. That variation is what turns the offset into a non linearity in a level detector with a moving input.

hysteresis and Its Design
hysteresis makes the threshold different for a rising and a falling input, and it is what prevents the output from chattering when the input is at the threshold or when it carries noise.
Positive feedback from the output to the non inverting input provides the hysteresis. The two resistors that set it also set the input impedance and the effect of the output swing on the threshold.
The hysteresis has to exceed the noise and the offset drift but stay below the smallest signal that has to be detected. A hysteresis larger than the signal makes the comparator miss events entirely, which is a failure that appears only in the field.
propagation delay and Response
propagation delay is the time from the input crossing the threshold to the output changing state. It is specified for a defined overdrive, and it grows as the overdrive is reduced.
A small overdrive is exactly what happens at the threshold of a slow signal, and the delay can be many times the datasheet figure. Where the timing matters, the overdrive has to be made large by design.
The output slew rate limits the transition as well, and it is specified separately. A comparator with a fast delay and a slow output stage is no faster than the output stage when driving a capacitive load.

The output stage
An open collector output requires a pull up resistor and can be pulled to a voltage above the supply of the comparator. That is convenient for interfacing to a different logic level, and the rise time is set by the resistor and the capacitance.
A push pull output drives both directions and gives a faster edge into a capacitive load. The swing is limited by the supply, and a rail to rail output is available where the logic level requires it.
A differential output suits a long cable or a differential receiver and gives the best immunity. It costs two pins and it is used where the comparator sits far from the logic it drives.
Reference and Input Design
The reference has to be stable, because its drift appears as a threshold error. A divider from the supply moves with the supply, which is acceptable in a ratiometric system and wrong where the threshold must be absolute.
A decoupling capacitor at the reference node removes the noise that the divider picks up from the supply. The impedance of the divider should be low enough that the bias current of the comparator does not shift the reference.
Input protection matters where the input can exceed the supply. A series resistor and a clamp diode limit the current into the input stage, and their leakage adds a small error that has to be accounted for at a high reference impedance.
Layout and Supply
Keep the reference, the input network and the comparator together, and return them to the analog ground. The threshold is a small voltage and any shared impedance with a switching current appears as a threshold shift.
The supply decoupling should be at the pin, and a part that draws a current spike at each transition benefits from a small ceramic capacitor directly at the supply pin. The spike is what couples into neighbouring circuits.
Route the input away from the output, because the output switches a full logic swing and the input is a high impedance node at a millivolt level. A trace running beside the output couples the switching edge into the threshold. The layout measures that keep the two apart are described in our guide to mixed signal board design.
Verification and Faults
Verify the comparator by sweeping the input slowly through the threshold and recording the output transition in both directions. The difference between the two is the hysteresis, and it should match the calculation.
Measure the propagation delay with a fast edge and a defined overdrive, using a probe of low capacitance. A delay measured with a slow input is the slew rate of the source rather than the comparator.
An output that chatters at the threshold indicates insufficient hysteresis or noise on the input, and one that misses events entirely usually has too much hysteresis for the signal. The release checks that keep such a circuit consistent are collected in our PCB design release checklist, the assembly points in judging PCB quality, and the means of keeping the noise out in our guide to EMI suppression design principles.
Process Control and Verification
On a design of this kind, output stage is the item that decides how the rest of the board is arranged. A short note on the drawing about handling, storage or packaging is often worth more than an extra decimal place on a tolerance. Where a value sits close to a process limit, the drawing should say so, since the shop can then open the process window rather than working to a nominal figure that carries no tolerance.
Process Control and Verification
On a design of this kind, output stage is the item that decides how the rest of the board is arranged. A short note on the drawing about handling, storage or packaging is often worth more than an extra decimal place on a tolerance. Where a value sits close to a process limit, the drawing should say so, since the shop can then open the process window rather than working to a nominal figure that carries no tolerance.
FAQ
Can I use an op amp as a comparator? For a slow, undemanding signal it works. For anything else a comparator is faster, has a defined output and does not draw a current spike at each transition.
How much hysteresis do I need? More than the noise and the offset drift, and less than the smallest signal to be detected.
Why is my comparator slower than the datasheet? The delay is specified for a large overdrive. At the threshold with a slow input the delay is much longer.



