Op-amp switching threshold problem

Thread Starter

mondo90

Joined May 16, 2025
122
Hi,
I try to understand why for the below circuit:
1758914673113.png

V_out is close to negative rail? We have a 0.9 positive input so theoretically it should get amplified with a gain of 5 to something close to positive rail (4.9 maybe) however what I see is exact opposite. I know this is correct behavior and has something to do with input threshold of 1V which needs to be hit for this configuration but I can't grasp why 1V is a threshold here. I already red https://www.allaboutcircuits.com/textbook/semiconductors/chpt-8/positive-feedback/ as well as S&S chapter on op amps (chapter 2) but still can't get it. Can you help?
 

Thread Starter

mondo90

Joined May 16, 2025
122
I think the answer is for some reason the output is negative when the numerical analysis starts. Therefore the feedback 10k resistor feeds back some small negative voltage to the noninverting input and that gets amplified causing even more negative input. This process repeats until we hit a negative saturation.
 

bertus

Joined Apr 5, 2008
22,882
Hello,

There is 5 volts on the 10k, you need more than 1 volt on the 2k to have the opamp flip to the other voltage.
Try a sinewave of 3 volts top-top as input and see what happens.

Bertus
 

Ian0

Joined Aug 7, 2020
13,097
Don't use an op-amp as a comparator. Some of them don't work as comparators due to the input protection. LT1677 is one of that type. There are two back-to-back diodes across the inputs which will make a mess of any calculations of threshold voltages. If you are making a comparator circuit USE A COMPARATOR.
 

MrAl

Joined Jun 17, 2014
13,667
Hi,
I try to understand why for the below circuit:
View attachment 356463

V_out is close to negative rail? We have a 0.9 positive input so theoretically it should get amplified with a gain of 5 to something close to positive rail (4.9 maybe) however what I see is exact opposite. I know this is correct behavior and has something to do with input threshold of 1V which needs to be hit for this configuration but I can't grasp why 1V is a threshold here. I already red https://www.allaboutcircuits.com/textbook/semiconductors/chpt-8/positive-feedback/ as well as S&S chapter on op amps (chapter 2) but still can't get it. Can you help?
Hi,

That's not a gain of 5 really, it turns out to be a gain of -5. Here is some math behind it.

Calculate the non-inverting input gain G12 from input to output: G12=Vin*R2/(R1+R2)
Calculate the non-inverting input gain G21 from output to input: G21=Vout*R1/(R1+R2)
The voltage (vp) at the non-inverting input is therefore:
vp=G12+G21
The voltage (vn) at the inverting input is zero:
vn=0
Now the output can be expressed as:
Vout=A*(vp-vn)
and solving this explicitly for Vout we get:
Vout=(Vin*A*R2)/(R2+(1-A)*R1)
and taking the limit as A goes toward infinity we end up with:
Vout=-(Vin*R2)/R1

This would be a gain of -5 in your circuit, but you also have to check it for a latch-up condition because there is positive feedback.

Normally when we talk about a gain for an opamp we are talking about the gain with negative feedback, and sometimes with both negative feedback and carefully planned positive feedback.

You can try a smaller input voltage to see what happens.

If you are intending to have this act like a comparator, then you have an awful lot of hysteresis there. Try raising the 10k resistor by a lot.
 

Thread Starter

mondo90

Joined May 16, 2025
122
Don't use an op-amp as a comparator. Some of them don't work as comparators due to the input protection. LT1677 is one of that type. There are two back-to-back diodes across the inputs which will make a mess of any calculations of threshold voltages. If you are making a comparator circuit USE A COMPARATOR.
Hi Ian0! Good input thanks. This is not intended to be a comparator, rather a Schmidt trigger as part of triangle wave generator:
1758916680098.png

Do you think it is a good method for triangle generation?
 

Ian0

Joined Aug 7, 2020
13,097
Hi Ian0! Good input thanks. This is not intended to be a comparator, rather a Schmidt trigger as part of triangle wave generator:
View attachment 356466

Do you think it is a good method for triangle generation?
No. Firstly, a Schmitt trigger IS a comparator.
Secondly, look at figure 5 of the datasheet and see those diodes. If you manage to bias those diodes into conduction, you are going to mess up your hysteresis levels. You need a comparator. Not all op-amps work as comparators.
 

sghioto

Joined Dec 31, 2017
8,633
V_out is close to negative rail? We have a 0.9 positive input so theoretically it should get amplified with a gain of 5 to something close to positive rail (4.9 maybe) however what I see is exact opposite.
Connect the 0.9 volt to the +input.
Gain = 1 + R2/R1
1758917960096.png
 

Thread Starter

mondo90

Joined May 16, 2025
122
@sghioto , thanks. I currently try to understand the circuit as it is, namely the 1V threshold (which I think I got already) rather then reworking it.
@Ian0, yes Shmitt trigger is a comparator and it seems to work with my circuit right? Have you seen the waveform? Second, this circuit is taken from the AoE book (literally) and as you can see they use OP amps not comparators:
1758922905007.png

The input protection diodes just introduce some DC offset right? I am a bit confused here because if there is some offset at the input then theoretically it should saturate the output instantaneously. What is the real problem with them?
Also, I plan to mount this circuit on the breadboard and I only have two comparators LM393 and LM339 but LTspicie doesn't even model them. Similarly I physically have op amp UA741 but there is no lt psicie model. Therefore I use LT1677 for now to get the main idea implemented.
 

Ian0

Joined Aug 7, 2020
13,097
@sghioto , thanks. I currently try to understand the circuit as it is, namely the 1V threshold (which I think I got already) rather then reworking it.
@Ian0, yes Shmitt trigger is a comparator and it seems to work with my circuit right? Have you seen the waveform? Second, this circuit is taken from the AoE book (literally) and as you can see they use OP amps not comparators:
View attachment 356473

The input protection diodes just introduce some DC offset right? I am a bit confused here because if there is some offset at the input then theoretically it should saturate the output instantaneously. What is the real problem with them?
Also, I plan to mount this circuit on the breadboard and I only have two comparators LM393 and LM339 but LTspicie doesn't even model them. Similarly I physically have op amp UA741 but there is no lt psicie model. Therefore I use LT1677 for now to get the main idea implemented.
Firstly, an LMC6482 doesn't have protection diodes between the inputs (CMOS op-amps tend not to), so that circuit will work. (It won't work very well at high frequencies, because to make a good triangle wave, you need to start from a good square-wave, and something with as slow slew-rate as the LMC6482 won't make a good square-wave.
Secondly, it's nothing to do with offset. You have set a threshold of 5V*(R2/(R2+R3)) = 0.833V. You can't achieve that because you have a diode across R2, so you can only get 0.6V. So you get the wrong result.
Thirdly, just because you found it in a book doesn't make it right. It's done for convenience to make it from a dual op-amp. With a slew-rate of 1V/us, you will get a triangle wave at the square-wave output at any frequency above 50kHz, because the output will take 10us to change state. Anything above 5kHz or so is going to start distorting the triangle wave.
 

Thread Starter

mondo90

Joined May 16, 2025
122
Firstly, an LMC6482 doesn't have protection diodes between the inputs (CMOS op-amps tend not to), so that circuit will work. (It won't work very well at high frequencies, because to make a good triangle wave, you need to start from a good square-wave, and something with as slow slew-rate as the LMC6482 won't make a good square-wave.
Yes and since I plan to use it for audio class d AMP the reference frequency needs to be much higher than the audio signal freq. So I am looking at a frequency of ~100k for that triangle.

Secondly, it's nothing to do with offset. You have set a threshold of 5V*(R2/(R2+R3)) = 0.833V. You can't achieve that because you have a diode across R2, so you can only get 0.6V. So you get the wrong result.
Are you saying the LTSpicie model is inaccurate and doesn't reflect that input diodes? So the circuit only works in the simulation but will never work in real?

It's done for convenience to make it from a dual op-amp.
So I do have a dual comparator LM393 https://www.ti.com/product/LM393 so theoretically I can fit those two op amps from my schematic into this one. However, this comparator has open collector output, does it mean I need to add a pull up resistor to 5V?
 
Last edited:

Ian0

Joined Aug 7, 2020
13,097
Yes and since I plan to use it for audio class d AMP the reference frequency needs to be much higher than the audio signal freq. So I am looking at a frequency for ~100k for that triangle.
How linear do you need your triangle-wave? If you class-D is open-loop then it needs to be really accurate. If you have feedback, then less so. Maybe a 555 might do it? Or if it has to be straight, a 555 and a couple of current sources?
Are you saying the LTSpicie model is inaccurate and doesn't reflect that input diodes? So the circuit only works in the simulation but will never work in real?
That depends if whoever made the model remembered them! Just add a voltage probe between the two inputs, and if it ever exceeds 0.6V in either direction they are missing. Just add them in with a couple of external 1N4148s and you'll see what will really happen.

So I do have a dual comparator LM393 https://www.ti.com/product/LM393 so theoretically I can fit those two op amps from my schematic into this one. However, this comparator has open collector output, does it mean I need to add a pull up resistor to 5V?
You are better off with a comparator with push-pull output such as the LTC3702, and perhaps if you want >40kHz, even that might be too slow. LT1677 is designed for precision and low noise, its slew rate will be a problem at 100kHz.
 

MrAl

Joined Jun 17, 2014
13,667
Hi Ian0! Good input thanks. This is not intended to be a comparator, rather a Schmidt trigger as part of triangle wave generator:
View attachment 356466

Do you think it is a good method for triangle generation?
Hi again,

Oh I see what you are doing now.

It's interesting to use an opamp in that manner, and I always hear people starting that you should use an opamp for a comparator. From my experience though, it depends entirely on the application not a hard and fast rule that must always be strictly adhered to. I've used opamps as comparators in certain applications. The advantage is no pullup as compared to the run of the mill comparators like the LM339. The other advantage is even more significant: if you need one opamp and you get a dual opamp package, why would you want to have to install a second IC package just to get an actual comparator rather than op amp if you already have a second opamp not doing anything?
I did an application just like that. It was a triac controller. It works on 50 to 60Hz line frequency so it does not have to switch super fast. It used one LM358 opamp. There was no way I was going to ADD an LM339 or other comparator to the PC board just because I needed a comparator function.

Now if you need 5ns response time you probably need an actual comparator, so each application has its own requirements. As we go up in frequency things always change. It is like anything else though ... we use what we need not what is named in such a way that it sounds like it might be better. One technique is purely subjective while the other is more complete.
 

Ian0

Joined Aug 7, 2020
13,097
Hi again,

Oh I see what you are doing now.

It's interesting to use an opamp in that manner, and I always hear people starting that you should use an opamp for a comparator. From my experience though, it depends entirely on the application not a hard and fast rule that must always be strictly adhered to. I've used opamps as comparators in certain applications. The advantage is no pullup as compared to the run of the mill comparators like the LM339. The other advantage is even more significant: if you need one opamp and you get a dual opamp package, why would you want to have to install a second IC package just to get an actual comparator rather than op amp if you already have a second opamp not doing anything?
I did an application just like that. It was a triac controller. It works on 50 to 60Hz line frequency so it does not have to switch super fast. It used one LM358 opamp. There was no way I was going to ADD an LM339 or other comparator to the PC board just because I needed a comparator function.

Now if you need 5ns response time you probably need an actual comparator, so each application has its own requirements. As we go up in frequency things always change. It is like anything else though ... we use what we need not what is named in such a way that it sounds like it might be better. One technique is purely subjective while the other is more complete.
There's single op-amps and single comparators in SOT-25 packages. That looks like an advantage when you are drawing the schematic, and less so when you are trying to track those extra power supply connections.
 

Ian0

Joined Aug 7, 2020
13,097
The other advantage is even more significant: if you need one opamp and you get a dual opamp package, why would you want to have to install a second IC package just to get an actual comparator rather than op amp if you already have a second opamp not doing anything?
I wonder why the LM392 never caught on?
 

0ri0n

Joined Jan 7, 2025
160
Yes and since I plan to use it for audio class d AMP the reference frequency needs to be much higher than the audio signal freq. So I am looking at a frequency for ~100k for that triangle.
https://www.ti.com/lit/pdf/slau508

This design note has everything you need to calculate the components for the triangle generator and the error amplifier using negative feedback to correct for errors in the PWM output voltage. It works from a single 5V supply. Measured THD is very low. Notice that R2R comparators were used where neccessary to get decent (high frequency) square waves.
 

MrAl

Joined Jun 17, 2014
13,667
There's single op-amps and single comparators in SOT-25 packages. That looks like an advantage when you are drawing the schematic, and less so when you are trying to track those extra power supply connections.
Oh yes that sounds interesting.
 

MrAl

Joined Jun 17, 2014
13,667
I wonder why the LM392 never caught on?
My guess would be that when we choose an op amp we need certain specs, and when we choose a comparator we need certain specs. To find both specifications that match our application might be difficult. For my triac controller this might have worked because the speed was not that fast, but it would involve purchasing that special part as well as maintaining that extra part in the parts room. I also noticed that the comparator in that chip seems to be 3 times slower than the LM339 so maybe that was a turning point.

I found the same problem with an 8 pin package that had an op amp and voltage reference on the same chip. The problem there was it was only available in SMD package, and it became hard to get. If I started using it for a production run, it could have been a big problem later on.

One thing nice though in the hobby world vs professional world is I find that I have a lot more flexibility with respect to the choice of parts. Since it may be a one-off project, I can afford to put parts in that are way over specified, like high current transistors rated 10 times what is needed. That allows some really interesting advantages like higher efficiency. In the ready-made IC chip world, it is hard to find that kind of thing too because cost is always so much of a concern.
 
Top