Comparator Hysteresis and Interface Design

A comparator converts an analogue level into a logic decision, and the decision is only as good as the circuit around it. A comparator with no hysteresis will switch repeatedly when the input passes slowly through the threshold, and the resulting burst of edges is passed to whatever counter or interrupt input follows. Adding hysteresis costs two resistors and removes a whole class of intermittent faults.

What a Comparator Does Differently from an Op Amp

An operational amplifier is designed to be used with negative feedback so that its output settles at a level set by the input difference. A comparator is designed to be used without feedback, so that its output swings to one rail or the other as quickly as it can, and its internal circuitry is optimised for that behaviour rather than for linearity.

The output stage is the visible difference. Many comparators have an open collector or open drain output, which allows the logic level to be set independently of the comparator supply and permits several outputs to be wired together. The trade is that a pull up resistor is required and the rise time depends on its value and on the load capacitance.

Speed is the other difference. A comparator is specified by its propagation delay and by its slew rate at the output, and those numbers are much faster than the equivalent figures for an amplifier used in the same way at the same supply current. Using an op amp as a comparator works at low speed and becomes a source of trouble as the frequency rises.

Threshold Voltage and Input Offset

threshold voltage is the level at which the output changes state, and it is set by the reference connected to the other input. The reference can be derived from a divider, from a dedicated reference device or from the supply itself when the measurement is ratiometric with the supply.

input offset voltage is the error between the applied differential voltage and the value that actually causes the transition. It is a few millivolts for a general purpose comparator and a few microvolts for a precision one, and it adds directly to the threshold error. Where the threshold has to be accurate, the offset has to be included in the error budget along with the tolerance of the reference.

The input common mode range is a second limitation. Many comparators cannot accept inputs close to either supply rail, so a signal that swings over the full range will produce an incorrect output near the extremes. A rail to rail input comparator, or a divided version of the input, is needed where the full range has to be covered.

Comparator circuit with hysteresis on a sensor board

Adding Hysteresis

hysteresis makes the threshold depend on the current output state. When the output is high, the effective threshold is slightly lower than the nominal value, and when the output is low, it is slightly higher. A slow input must therefore move past the threshold and beyond the hysteresis window before the output changes again, which removes the chatter.

Positive feedback is the mechanism. A resistor from the output to the non inverting input, in combination with the source impedance seen at that input, creates the two thresholds. The feedback resistor must be large enough not to load the output excessively and small enough to produce the required window, and its effect depends on the impedance of the source, which is why the design has to be done with the actual source in place.

Where the input is driven from a low impedance source, the hysteresis depends almost entirely on the feedback and input resistors. Where the source impedance is high or variable, the window becomes uncertain, and a buffer amplifier before the comparator is the cleaner solution. This is the same reasoning that applies to any threshold detection circuit.

Calculating the Hysteresis Window

Start from the amount of noise that the input will carry. The hysteresis window should be several times the peak to peak noise at the comparator input, so that a noisy signal cannot cross both thresholds in quick succession. A window that is too small does nothing, and one that is too large introduces a delay proportional to the window divided by the slew rate of the signal.

Then check the effect on the timing. For a signal that ramps slowly, the extra delay is the hysteresis window divided by the ramp rate, which can be significant in a measurement circuit. For a fast edge, the delay is negligible. The window is therefore a compromise between immunity and timing, and the two requirements should be written down before the resistors are chosen.

The reference and the input divider tolerances set the accuracy of the threshold. Using resistors with a low temperature coefficient and a tight tolerance keeps the threshold stable, and deriving the reference from the same source as the signal makes the threshold track the supply. Where the threshold has to be precise, a dedicated reference is worth more than tighter resistors.

Comparator input network and threshold reference on a PCB

Propagation Delay and Output Stage

propagation delay is the time from the input crossing the threshold to the output changing state, and it is specified for a given amount of overdrive. A signal that barely exceeds the threshold will take longer than the datasheet figure, which is measured with a defined overdrive voltage. Where the timing matters, the input should be driven well past the threshold rather than exactly to it.

The output stage determines what the comparator can drive. An open drain output with a pull up resistor gives a defined logic level and allows wired OR connections, but the rise time is set by the resistor and the load capacitance. A long trace with a weak pull up produces a slow edge that may itself be interpreted as multiple events by a fast logic input.

Some comparators include an internal latch that holds the output until it is clocked. That is useful in a fast system where the output would otherwise change during the conversion window, and it removes the need for an external flip flop. The latch input has its own timing requirements, which have to be respected in the same way as any other synchronous signal.

Layout of a Comparator Input

Treat the comparator input as a sensitive analogue node. Keep the traces short, route them away from switching nodes and digital lines, and place the hysteresis and filtering components close to the input pin rather than at the source. The input is where noise matters most, because the comparator amplifies the difference between the two inputs with no feedback to speak of.

Place the bypass capacitor at the comparator supply pin with a short return to ground, and keep the reference node quiet. A reference that moves with the supply or with nearby switching current shifts the threshold, and the shift appears as a change in the point at which the circuit trips. This is the same partition discipline described in mixed signal board design, and a comparator belongs firmly in the analogue area.

Where the input comes from a sensor over a cable, add a filter at the board and consider a series resistor to limit the current during a transient. The paths that interference takes into a sensitive input, and the methods for finding them, are described in EMI suppression design.

Verification and Common Faults

Verify the threshold by sweeping the input slowly in both directions and recording the two transition points. The difference between them is the hysteresis window, and the midpoint is the threshold. Comparing the measured values with the design shows whether the source impedance is affecting the window as expected.

Chatter at the output is the most common fault, and it is diagnosed by looking at the output and the input together on a scope. If the output changes state several times in a burst as the input crosses the threshold, the hysteresis is too small, or the noise at the input is larger than the window. Measuring the noise at the input pin rather than at the source shows which.

A comparator that fails to switch at all usually has a common mode range problem. If the input is within a few hundred millivolts of either supply rail and the device is not specified for that range, the output becomes undefined. A divided input or a device with a rail to rail input range solves it, and the manufacturing notes in manufacturable PCB design cover how to provide test access so that these thresholds can be checked in production.

FAQ

How much hysteresis do I need? Several times the peak to peak noise at the input, and no more. Measure the noise with the system running, then choose the window and check the extra delay it introduces.

Can I use an op amp as a comparator? For slow signals and loose timing, yes. Above a few kilohertz the recovery from saturation dominates and the behaviour becomes unpredictable, so a real comparator is the better choice.

Why does my threshold change when a relay operates? The supply that feeds the reference is being disturbed. Decouple the reference, or derive it from a source that is not shared with the relay coil supply.

Leave A Comment