# Why is this not working as a Schmitt trigger?

I've been trying to implement a Schmitt trigger using comparators in LTspice. Needless to say, even though I can work with opamps and comparators, I'm totally at lost with using them to make Schmitt triggers. Perhaps it's because I've always just needed to implement non-inverting and inverting amplifiers with opamps and just trust the math. I don't have the intuition of professional electronic engineers in seeing the flow of currents around opamps to predict what's going to happen. It's one of those things I never got around learning up until now.

Here's the circuit:

The full schematic is here.

On the left side is my attempt at making a Schmitt trigger.

To the right is an inverting comparator circuit for reference, whose output we have here:

Now, given the identical $$\V_{IN}\$$ & $$\V_{REF}\$$ on both circuits, the output for the circuit to the left (the attempt for a Schmitt trigger) should produce an output the same as the one on the right, but shifted to the right, if the threshold is symmetric:

Yet, here's the output of the left circuit:

The threshold when $$\V_{IN} < V_{REF}\$$ is correct, but the threshold $$\V_{IN} > V_{REF}\$$ is incorrect.

When I was implementing an oscillator quite a while ago, I needed a Schmitt triggee and I just couldn't get it to work. Eventually I realized I didn't need the Schmitt trigger, but it's still an irritant. Can anybody correct my schematic and explain to me (with delight on your side) what I'm doing wrong?

• I discuss Schmitt triggers here. There are some very good papers to consider listed there. Commented Apr 18 at 8:55
• According to your wave forms, it works properly as a smith trigger, both 10K resistors make it turn on at (2V+0V)/2 = 1V and turn on (2V+10V)/2 =6V. Your calculated thresholds assume the op-amp outputs 2*Vref = 4V when it outputs an HIGH, while it actually outputs 10V Commented Apr 18 at 8:58

# Understanding through intuition

To get an intuitive idea of this (and any other) circuit, it is better to trace its evolution step by step instead of analyzing the final circuit solution. Moreover, I suggest that we include the "wrong" steps (outlined in yellow) as well because they show the need for the "right" ones. Indeed, it will result in a rather long circuit story, but that is the price of understanding.

# What is a comparator?

It is widely believed that a comparator is simply an (op-amp) amplifier with a very high gain. Another important component - the subtractor - is not noticeable because it is implemented by the differential input of modern op-amps.

# Series comparator

(a provisional name)

As I said above, a comparator consists of a subtractor and an amplifier - the former compares the two voltages by subtraction, and the latter amplifies the difference to the value of the supply voltage. Let's first consider the summer, and temporarily replace the amplifier with a voltmeter.

## Series voltage summer

The simplest way to subtract two voltages is by connecting the two voltage sources - the reference source Vref and the input sources Vin, contrary in series. The "subtractor" here is the loop. We can arrange the circuit in three possible ways:

Grounded Vin, floating Vref: In this connection, only Vref is "floating" (not connected to ground). The amplifier can be with a single-ended (internally grounded) input, and it is presented here by a grounded voltmeter Vout.

simulate this circuit – Schematic created using CircuitLab

Here are the graphs of the voltages when Vin is swept (changed) from 0 V to 10 V.

The floating Vref is a problem since all circuit voltages are produced by the power supply that is grounded. So probably it is preliminary grounded, and Vin will be short circuited. I have shown this connection through the ground by an ammeter with 1 Ω internal resistance; so the current is too high.

simulate this circuit

Grounded Vref, floating Vin: Now, only Vin is "floating", and this creates the same problem as above. The amplifier can be with a single-ended input.

simulate this circuit

If Vin is preliminary grounded, Vref is short circuited.

simulate this circuit

Both Vin and Vref grounded: The remedy is for the next stage (amplifier and here a voltmeter) to have a floating (differential) input and a grounded output. Then both the input voltages and the load are grounded.

simulate this circuit

## Op-amp series comparator

If we replace the voltmeter with an op-amp (with a differential input), we obtain a comparator.

With ideal op-amp: CircuitLab advises us to use an ideal op-amp (without supply terminals) whenever possible. But an extremely high input voltage is obtained because it is not limited by anything...

simulate this circuit

... and grows to infinity.

With real op-amp: So let's put a real op-amp with a 10 V supply voltage.

simulate this circuit

Now the output voltage is limited to the supply voltage.

What is hysteresis? First let's see what is behind this weird word. This here means that the comparator changes its threshold depending on the direction of change of the input voltage... or that it has two thresholds... or that it has memory. We assume we know the benefit of this trick and move on.

How to make a hysteresis: The idea is very simple - at the moment of switching, we need to help the input voltage by lowering the threshold. For example, imagine that you are overcoming an obstacle and at that moment someone lowers it.

Trying to add hysteresis: This means adding part of the output voltage to the input voltage. To do this, we think, we can connect a resistor R between the op-amp output and the non-inverting input.

simulate this circuit

However, to our surprise, nothing changes.

Really adding hysteresis: Aha... clear... The "stiff" reference source does not allow the voltage to change. Then let's "enervate" it by connecting another resistor R1 in series with it. Thus R1 and R2 actually form another type of voltage summer with weighted inputs.

simulate this circuit

We see that as the input voltage increases, the threshold shifts up. It should be that when the voltage decreases, the threshold should shift down. But CircuitLab does nоt let the sweeping voltage drop; it can only increase. So we can not see the hysteresis curve (loop) in this DC Sweep Simulation.

# Parallel comparator

(a provisional name)

The "series" comparator above is based on a series subtractor where the two voltage sources (Vref and Vin) are connected in series. It requires an amplifier with a differential input. But if we do not have one? Such was the situation a century ago when they only had single-ended amplifiers and still managed to make a comparator. Now for other reasons we may wish to do so; so let's see how.

The difference between the two configurations is that in order to obtain subtraction, in the above case the two sources must be of the same polarity and here of opposite polarity. As above, we temporarily replace the amplifier with a "single-ended" (grounded) voltmeter.

## Parallel voltage summer

If we connect the two voltage sources to the single amp input (voltmeter here), a short circuit will occur and a very high current will flow between the sources (note that the total voltage is a sum of the two). To limit the current (to 5 A) and to "cheat" CircuitLab, let's connect ammeters with 1 Ω internal resistance in series to sources.

simulate this circuit

Aha... got the same resistor summer as above, only the current is very high. Then we can put resistors R1 and R2 with a much higher (10 kΩ) resistance.

simulate this circuit

## Op-amp parallel comparator

Without hysteresis: Now we have only to replace the voltmeter with an amp with a single-ended input (op-amp with grounded non-inverting input) to obtain a comparator.

simulate this circuit

With hysteresis: To introduce hysteresis, we can apply the same trick as above - connect a resistor R3 between the op-amp output and the non-inverting input. In effect, the three resistors form a 3-input resistor summer where Vref is the opposite polarity of Vin and Vout.

simulate this circuit

Given a single supply rail ($$\10\:\text{V}\$$) and the biased source you show into the (-) input, then the following:

simulate this circuit – Schematic created using CircuitLab

I'll assume that you want the hysteresis to center around $$\V_{_\text{BIAS}}=3\:\text{V}\$$, since that's the DC bias you've added to your AC source. Call the hysteresis band's peak as $$\V_{_\text{HYS}}\$$, so that the band is centered at $$\V_{_\text{H}}=V_{_\text{BIAS}}\pm V_{_\text{HYS}}\$$.

$$\V_{_\text{CC}}=10\:\text{V}\$$:

\begin{align*} \frac{V_{_\text{CC}}\cdot R_2\cdot \left(R_1+R_3\right)}{R_1\cdot R_2+R_1\cdot R_3+R_2\cdot R_3} &=V_{_\text{BIAS}}+ V_{_\text{HYS}} \\\\ \frac{V_{_\text{CC}}\cdot R_2\cdot R_3}{R_1\cdot R_2+R_1\cdot R_3+R_2\cdot R_3} &=V_{_\text{BIAS}}- V_{_\text{HYS}} \end{align*}

Suppose $$\V_{_\text{HYS}}=500\:\text{mV}\$$ and $$\R_2=22\:\text{k}\Omega\$$. Then using Python/SymPy (free):

# Set up equations just once:
EQ1 = Eq( Vcc*R2*(R1+R3) / (R1*R2 + R1*R3 + R2*R3), Vbias + Vhys )
EQ2 = Eq( Vcc*R2*R3 / (R1*R2 + R1*R3 + R2*R3), Vbias - Vhys )
# Solve for Vhys = 0.5 V
for i in solve([ EQ1, EQ2 ], [ R1, R3 ])[0]:
i.subs({ Vcc:10, R2:22e3, Vbias:3.0, Vhys:0.5 })
57200.0000000000
143000.000000000


Substitute in those values for $$\R_1\$$ and $$\R_3\$$:

And I think you can see that it nails the hysteresis range.

Suppose $$\V_{_\text{HYS}}=250\:\text{mV}\$$ and $$\R_2=22\:\text{k}\Omega\$$. Then:

# Solve for Vhys = 0.25 V
for i in solve([ EQ1, EQ2 ], [ R1, R3 ])[0]:
i.subs({ Vcc:10, R2:22e3, Vbias:3.0, Vhys:0.25 })
54000.0000000000
297000.000000000


Plug those in:

That's really about all there is.

I don't have the intuition of professional electronic engineers of seeing the flow of currents around opamps to predict what's gonna happen.

You only need to be able to set up a resistor divider equation.

I've no idea why you added that $$\1\:\text{k}\Omega\$$ resistor at your opamp output in your schematics. There, I remain clueless. Perhaps you can explain your thinking to me.