Comparators can be dedicated IC with built-in hysteresis. But they can also be built from an op-amp. But then external hysteresis resistors should be added. In this article I will try to show you how to choose them.

##### Why do I need hysteresis at all?

First, let’s build a comparator based on an operational amplifier, but without hysteresis. Let’s create such a circuit in LTSpice.

V1 – Pulse signal.

V2 – Noise signal. I used a sinusoidal signal.

V3 – Op-amp power supply.

U1 – I used an “UniwersalOpamp2” model.

R1, R2 – Resistors that set the comparator switching threshold at 2.5 V.

Now let’s see what the input and output waveform looks like:

Rarely, electric waveforms are free from disturbances, noise and surges. When there is no hysteresis, such waveforms cause the comparator output to switch to opposite states repeatedly. This is similar to the bounce waveforms of switch contacts.

And it is for this reason that it is recommended to use hysteresis.

##### It is then somehow to set the hysteresis?

Electrically, the matter is simple. Just add one resistor. But the question is also its value.

The resistor R3 is the resistor that sets the hysteresis for us. Resistors R1 and R2 in our simulation have a value of 100 kΩ each. Therefore, the switching threshold at the moment is set at 2.5 V (half of the supply voltage). Let’s assume that we want to have a hysteresis of 1V, i.e. the switching thresholds should be Vh = 3 V and Vl = 2 V .

The presence of an op-amp may make the circuit a bit difficult to understand. Therefore, let’s try to understand how the resistors will be connected to each other. There are a total of 2 states to consider:

- When the output is high (+5 V).
- When the output is low (0V).

The connection of resistors when the output of the amplifier is high, looks like in Figure 5.

On the other hand, the connection of resistors, when the amplifier output is low, looks like in Figure 6.

Since the hysteresis determined by us is symmetrical, it is enough to calculate the resistor R3 from one figure. Let’s take Figure 5 and calculate the value of R3 from it.

(1)

(2)

Due to this, our scheme is reduced to an ordinary voltage divider:

(3)

(4)

(5)

Substituting the result into equation 2 we get:

(6)

(7)

(8)

(9)

(10)

(11)

(12)

From equation 12 we get the result that our hysteresis resistor should be 200 kΩ. To be sure, using the scheme in Figure 6, we can verify the calculations. The former resistor R13 will now be resistor R23.

(13)

(14)

(15)

(16)

As we can see from equation 16, we got a voltage of 2 V, so what we planned. Thus, we confirmed our calculations.

Now let’s try to simulate a circuit with an additional hysteresis resistor, equal to 200kΩ.

It is clear from the simulation that by adding one additional resistor, we have created a hysteresis loop in the comparator, thanks to which the comparator output does not switch to opposite states when the signal passes around the switching threshold. That was the purpose of adding this resistor. Now it remains to check whether the voltage thresholds for hysteresis calculated by us coincide with the calculations.

The simulation diagram clearly shows that we managed to obtain the switching thresholds that we assumed for the calculations. One threshold is 2V and the other is 3V.

##### Comment

In this case, the calculations were performed only for one case (Figure 5), and the second case (Figure 6) served only to confirm the result of the calculations. I could do so because I assumed the hysteresis symmetrically against the earlier switch point (2.5V). But if I had to do the hysteresis asymmetrically, then I would have to do the system of equations from these two cases and solve this system.