Comparator Hysteresis Calculation: LM393 Step by Step

Circuit Design and Application Notes Advanced 12 min read Published:
Comparator hysteresis calculation: LM393 threshold and resistor design with a hysteresis loop drawing

A comparator with hysteresis is a comparator circuit that shifts its own threshold whenever its output changes state: it switches at an upper threshold (VH) while the input is rising and at a lower threshold (VL) while the input is falling. The gap between the two thresholds (ΔV = VH − VL) keeps noise on the input from making the output chatter. In this article we work through a circuit with an LM393 on a 5 V supply and thresholds of 2.4 V and 2.6 V, step by step. The result: R1 = R2 = 20 kΩ, a 240 kΩ feedback resistor and a 10 kΩ pull-up. We also show, with the formulas, how the pull-up resistor on the open-collector output shifts the upper threshold.

Why does a comparator need hysteresis?

A comparator compares the voltages on its two inputs and drives its output to one of two states. Its gain is very high: the LM393’s large-signal voltage gain is 200 V/mV typical and 50 V/mV minimum. This gain is specified at a 15 V supply; as an order of magnitude, an input difference of roughly 5 V / 200 V/mV = 25 µV is enough for a full 5 V output swing. At the minimum gain this value is roughly 100 µV.

When the input approaches the threshold slowly (signals such as temperature, light or battery voltage), a few millivolts of noise on it cross this 25 µV region many times. Instead of a single transition, the output produces a burst of pulses. In a microcontroller those pulses mean false interrupts, in a relay they mean buzzing, and in a counter they mean miscounts. Ripple on the supply rail and coupling of the output edge back to the input through the PCB make the effect worse.

Hysteresis applies a small amount of positive feedback from the output to the non-inverting (+) input, which ties the threshold to the output state. The moment the output changes, the threshold moves back by ΔV; for noise to flip the output again it has to be larger than ΔV. The first design rule follows from this: choose a hysteresis larger than the peak-to-peak noise at the input.

LM393 and LM2903: pinout and the values used in the calculation

The LM393DR is a dual comparator from Texas Instruments in a SOIC-8 package. It contains two independent comparators and runs from a single supply. The input common-mode range includes ground. The output stage is open collector: the output transistor only sinks current, and an external pull-up resistor provides the high level. This lets you pull the output up to a logic voltage independent of the comparator supply (for example 3.3 V). The LM2903M has the same pinout and operates over a wider temperature range.

LM393 and LM2903 8-pin package pinout, top view: 1 1OUT, 2 1IN−, 3 1IN+, 4 GND, 5 2IN+, 6 2IN−, 7 2OUT, 8 VCC
LM393 and LM2903 pinout in 8-pin SOIC and PDIP packages (top view). Both comparators share the same supply and ground pins.

The LM393 values in the table come from TI’s LM393 family datasheet (the LM393 column without the A suffix), and the LM2903M values from the LM2903-N datasheet. Unless otherwise noted, values are for VCC = 5 V and 25 °C.

Parameter LM393 (LM393DR) LM2903 (LM2903M)
Supply voltage 2–30 V recommended, 36 V absolute maximum 2–36 V single supply, ±1 to ±18 V dual supply
Operating temperature 0 … +70 °C −40 … +85 °C
Input offset voltage (VIO) 2 mV typ, 5 mV max (9 mV max over full range) 2 mV typ, 7 mV max (15 mV max over full range)
Input bias current (IIB) 25 nA typ, 250 nA max (400 nA over full range) 25 nA typ, 250 nA max (500 nA over full range)
Input common-mode range 0 … VCC − 1.5 V (VCC − 2 V over full range) 0 … VCC − 1.5 V (VCC − 2 V over full range)
Voltage gain (VCC = 15 V) 50 min, 200 V/mV typ 25 min, 100 V/mV typ
Output low voltage (sinking 4 mA) 130 mV typ, 400 mV max 250 mV typ, 400 mV max
Output sink current (VOL = 1.5 V) 6 mA min 6 mA min, 16 mA typ
Response time (100 mV step, 5 mV overdrive, 5.1 kΩ pull-up) 1.3 µs typ 1.5 µs typ
Supply current (both comparators, no load) 1 mA max 0.4 mA typ, 1 mA max

The two rows that matter most for the calculation are the common-mode range and the output low voltage. On a 5 V supply, the thresholds must stay between 0 and 3.0 V over the full temperature range. If one input goes above this range while the other stays inside it, the output still makes the right decision; the datasheet states that the inputs can go up to the VCC level without damage. The inputs, however, must not go more than 0.3 V below ground.

Inverting comparator with hysteresis: circuit and operation

In the most common configuration, the measured signal goes to the inverting (−) input. The non-inverting (+) input sits at a reference voltage set by the R1–R2 divider. The feedback resistor RH connects from the output to the (+) input, and RP pulls the output up to VCC. While the input is below the threshold the output is high, and once the input crosses the upper threshold the output goes low. That is why the circuit is called “inverting.”

LM393 inverting comparator with hysteresis: input to pin 2 (1IN−), pin 3 (1IN+) to 5 V through R1 20 kΩ and to ground through R2 20 kΩ, RH 240 kΩ feedback from output pin 1 to 1IN+, RP 10 kΩ pull-up from the output to 5 V, 100 nF decoupling on pin 8 (VCC)
Inverting comparator with hysteresis using the LM393. Pin numbers refer to the 8-pin package and the first comparator; resistor values are the choices of the example design in this article.

The circuit has two states:

  • Output high (input low): The output transistor is off. RH and RP in series pull the (+) input toward VCC; this path appears in parallel with R1, and the voltage at the (+) input rises. This voltage is the upper threshold VH.
  • Output low (input high): The output transistor is saturated and the output is close to 0 V. Now RH appears in parallel with R2, and the voltage at the (+) input drops. This voltage is the lower threshold VL.

Threshold formulas

To simplify the calculation, we convert the R1–R2 divider into its Thevenin equivalent:

  • VTH = VCC × R2 / (R1 + R2)
  • RTH = R1 × R2 / (R1 + R2)

Assuming VOL ≈ 0 while the output is low, the lower threshold is:

VL = VTH × RH / (RTH + RH)

While the output is high, the output node is pulled to VCC through RP, so the total resistance of the feedback path is RH + RP:

VH = VTH + (VCC − VTH) × RTH / (RTH + RH + RP)

If RP is small compared with RH, the difference between the two reduces approximately to:

ΔV ≈ VCC × RTH / (RTH + RH)

The ratio of RTH to RH sets the hysteresis width, and VTH sets the center of the thresholds. The design rests on these two relationships.

Example design: 2.4 V / 2.6 V thresholds on a 5 V supply

Our target is VCC = 5 V, VL = 2.40 V and VH = 2.60 V, that is, ΔV = 200 mV. Because the thresholds stay below the 3.0 V common-mode limit, the LM393 is suitable for this job.

  1. Find the ratio. From ΔV ≈ VCC × RTH / (RTH + RH), RH = RTH × (VCC / ΔV − 1) = RTH × (5 / 0.2 − 1) = 24 × RTH.
  2. Find the divider voltage. Since VL = VTH × RH / (RTH + RH) = VTH × 24 / 25, VTH = 2.40 × 25 / 24 = 2.50 V. The divider splits the supply exactly in half: R1 = R2.
  3. Choose RTH. With RTH = 10 kΩ, R1 = R2 = 20 kΩ and RH = 240 kΩ (240 kΩ is a standard E24 value). The divider draws 5 V / 40 kΩ = 125 µA.
  4. Choose the pull-up. RP = 10 kΩ carries 5 V / 10 kΩ = 0.5 mA while the output is low. This is far below the datasheet’s 4 mA test current; since VOL rises in proportion to current, the output low voltage stays even smaller at 0.5 mA.
  5. Include RP and check. VH = 2.5 + 2.5 × 10 / (10 + 240 + 10) = 2.5 + 0.096 = 2.596 V. VL = 2.5 × 240 / 250 = 2.400 V. The hysteresis is 196 mV; the pull-up has pulled the upper threshold 4 mV below the target. If you want exactly 2.60 V, reduce RH by roughly RP; with 232 kΩ from the E96 series the upper threshold rises to 2.599 V and the lower threshold drops to 2.397 V.
Hysteresis transfer curve: as the input rises, the output falls from about 4.9 V to 0 V at 2.596 V; as the input falls, it rises again at 2.400 V; the gap between the two thresholds is 196 mV
Transfer curve of the example design. As the input rises the output falls at 2.596 V, and as the input falls the output rises again at 2.400 V.

Two more small details. First, while the output is high, about (5 − 2.6) V / 250 kΩ ≈ 9.6 µA flows through RP and RH into the (+) input. This current drops about 96 mV across RP, so the high level is around 4.9 V rather than 5 V. If you connect a logic input to the output, its current adds to this drop. Second, VOL is not zero: a VOL of 0.1 V raises the lower threshold by 0.1 × 10 / 250 = 4 mV. Both stay small next to a 200 mV hysteresis.

Non-inverting configuration: when the signal goes to the (+) input

If you want the output to go high when the input rises, feed the signal to the (+) input through a resistor RIN, connect the (−) input to a fixed VREF, and again connect RH from the output to the (+) input. With VOL ≈ 0 and a pull-up voltage VPU, the thresholds are:

  • VH = VREF × (RIN + RH) / RH
  • VL = [VREF × (RIN + RH + RP) − VPU × RIN] / (RH + RP)

With VREF = 2.5 V, RIN = 10 kΩ, RH = 240 kΩ, RP = 10 kΩ and VPU = 5 V, you get VH = 2.604 V and VL = 2.400 V. The cost of this configuration is that the signal source has to supply the feedback current through RIN; the source’s internal resistance adds to RIN and shifts the thresholds. If you need a reference around 2.5 V for VREF, the options in the voltage reference selection article can be used.

Threshold accuracy: the error budget

Five sources determine where the thresholds actually land:

  • Offset voltage: On the LM393, 5 mV max at 25 °C and 9 mV max over 0–70 °C. Offset shifts both thresholds together and does not change the hysteresis width.
  • Input bias current: Because of the PNP input stage, the current flows out of the input. The worst-case 400 nA creates a 4 mV shift across the 10 kΩ RTH. If you raise RTH to 100 kΩ, this error becomes 40 mV; account for that cost when you reduce the divider current.
  • Resistor tolerance: If 1% R1 and R2 drift in opposite directions, VTH can rise to 5 V × 20.2 / (19.8 + 20.2) = 2.525 V; a shift of about ±25 mV is larger than the error coming from the chip.
  • Supply voltage: Because the divider is fed from VCC, the thresholds change in proportion to VCC. A 5% change in VCC shifts the thresholds by about 125 mV. If the measured signal is derived from the same VCC (an NTC divider, for example), both sides change together and the error largely cancels. If not, feed the divider from a fixed reference.
  • Pull-up and VOL: A few millivolts in the example above; you can calculate them exactly by including them in the formulas.

With a stable supply, the worst-case sum of offset, bias current and 1% resistors is about ±40 mV; next to a 200 mV hysteresis this margin is acceptable. If you need a narrower window, improving the resistor tolerance and the reference is more effective than changing the comparator.

Speed: pull-up resistor and load capacitance

On an open-collector output, the pull-up resistor and the capacitance at the output set the rising edge. The TI datasheet gives the rise time as approximately τR ≈ RP × CL. With 10 kΩ and 15 pF, τR ≈ 150 ns (the 10–90% rise time is about 2.2 τ ≈ 330 ns); this is small next to the LM393’s typical 1.3 µs response time at 5 mV overdrive. A long cable or several logic inputs can add hundreds of pF; in that case you can reduce RP. The datasheet’s design example takes the output current up to 4 mA; at 5 V that means at least about 1.3 kΩ. If you change RP, recalculate VH, because RP appears in the upper threshold formula. Response time gets shorter with input overdrive (how far the input crosses the threshold); with a TTL-level input it drops to 0.3 µs typical.

Things to watch when building the circuit

  • Decoupling: Place a 100 nF ceramic capacitor close to the VCC pin (8). The TI datasheet recommends a bypass capacitor on the supply pin in noisy or AC-input applications, and the LM2903-N datasheet gives 1 µF for improved performance. Supply ripple narrows the common-mode range.
  • Keep the output away from the inverting input: Do not run the output trace parallel to the (−) input trace. The datasheet’s layout guidance is to put a VCC or ground trace between them if you have to. Without hysteresis, or with very little, this coupling produces oscillation on the edges.
  • Place the input resistors close to the chip: The node where R1, R2 and RH meet the (+) input is high impedance; a long trace picks up noise.
  • Common-mode limit: On a 5 V supply, keep both thresholds below 3.0 V. On a 3.3 V supply this limit drops to 1.3 V; set up the divider accordingly.
  • Unused comparator: Do not leave the inputs of the second comparator floating. The LM2903-N datasheet recommends tying all inputs of an unused comparator to the negative supply, which is ground in a single-supply circuit.
  • Temperature: The LM393 is specified for 0–70 °C. For outdoor or cold-storage applications, choose the LM2903M, which is specified for −40 … +85 °C; thanks to the same pinout, the PCB does not change.
LM393DRTexas Instruments · EE01456$0.58590 In StockView

Common mistakes

  • Forgetting the pull-up resistor: An open-collector output cannot reach the high level without a pull-up; when measured, the output looks “always 0 V” or undefined. In the inverting circuit the pull-up is also part of the upper threshold.
  • Connecting the feedback to the (−) input: A resistor from the output to the (−) input is negative feedback and produces no hysteresis. For hysteresis, the feedback always goes to the (+) input.
  • Choosing hysteresis smaller than the noise: On a signal with 50 mV peak-to-peak noise, 20 mV of hysteresis reduces the chatter but does not eliminate it. Measure the noise with an oscilloscope and choose ΔV larger than that.
  • Placing the threshold outside the common-mode range: On a 5 V supply, a 3.5 V threshold sits exactly at the limit even at 25 °C (VCC − 1.5 V); according to the datasheet, below 25 °C the range narrows and the upper limit becomes VCC − 2 V.
  • Ignoring bias current with a high-value divider: Dividers in the megohm range save current, but a 400 nA bias current can shift the thresholds by hundreds of millivolts.

If you are considering an op-amp instead of a comparator, we compared the differences in the op-amp selection article. You can also see how the two comparators inside the 555 timer use their thresholds in the 555 astable circuit article.

Frequently asked questions

Are hysteresis and a Schmitt trigger the same thing?

In practice, yes. Schmitt trigger is the general name for a comparator with hysteresis: a circuit with two separate thresholds whose output keeps its previous state between them. In logic ICs such as the 74HC14 the hysteresis is fixed internally; in a circuit built with the LM393 you set the thresholds yourself with resistors.

How much hysteresis should I use?

At least as much as the peak-to-peak noise at the input, preferably a little more. Because offset voltage and resistor tolerance shift the thresholds, choosing a very large ΔV also means moving away from the intended on and off points. In the example in this article, 200 mV is 8% of a 2.5 V threshold.

Can I connect the LM393 output directly to a 3.3 V microcontroller?

Yes. Thanks to the open-collector output, you only need to connect the pull-up resistor to 3.3 V instead of 5 V. In that case, in the inverting circuit the feedback comes from 3.3 V while the output is high; recalculate the threshold by writing (3.3 V − VTH) instead of (VCC − VTH) in the VH formula.

What is the difference between the LM393 and the LM2903?

The pinout and operating principle are the same. The LM2903 is specified for a wider temperature range (−40 … +85 °C in the LM2903-N datasheet), while its offset voltage and gain limits are somewhat looser. In a device that stays within 0–70 °C the LM393 is the right choice; outdoors, the LM2903.

Does adding a capacitor at the output help without hysteresis?

Partly. A capacitor at the output smooths fast pulses but does not remove the uncertainty at the decision point; while a slow input wanders around the threshold, the output can still make more than one transition. An RC filter at the input reduces noise, and hysteresis keeps the remaining noise from flipping the output. The two together give good results.

Conclusion

The comparator hysteresis calculation rests on two ratios: RTH / (RTH + RH) sets the hysteresis width, and the divider voltage VTH sets the center of the thresholds. On the open-collector LM393, including the pull-up resistor in the upper threshold formula lets you predict the thresholds to the millivolt. In the 5 V example we got thresholds of 2.400 V and 2.596 V with a 20 kΩ / 20 kΩ divider, 240 kΩ feedback and a 10 kΩ pull-up. You can find the LM393DR used in the circuit and the wide-temperature LM2903M on their product pages, and browse other models in the comparators category.

References

Products in this article

More from Circuit Design and Application Notes