Need help with Op Amp Circuit

Thread Starter

n4mwd

Joined Mar 21, 2016
50
I seem to always have trouble with Op amps and I was hoping somebody here could tell me what I'm doing wrong. The problem I am trying to solve is that I have an input (see the switch in the diagram below) and I must create a PASS/FAIL logic level such that Switch position #4 gives a logic high and all other positions give a logic low. Oh, and just to make things more interesting, the 12V supply in the circuit is highly unstable and can vary from 6V to 15V.

My faulty circuit is supposed to work like this. The output of the switch drives a resistor divider and the supply drives an identical divider. The center taps V2 and V1 are fed into an op amp differencing circuit. So the output of the op amp can be fed into the ADC on an MPU which can determine the final logic output based on the voltage. I only have one spare pin on the MPU so I have to use the op amp differencing circuit rather than let the MPU figure it out from two inputs.

Without the op amp, the resistor dividers work as predicted. ***BTW, I just realized that I labeled V1 and V2 backwards on this schematic*** V2 (labeled V1 in this schematic) is always half the supply. If the switch is on position 1 or 2, then V1 (labeled V2) is 0V. In position 3, its 6V. In Position 4, its 5.97V.

The idea is that the Op Amp differencing amp would produce 6V, 6V, 0V, and 0.03V for switch positions 1-4 respectively. The ADC can handle it from there. The only problem is that when I breadboarded this circuit, it doesn't come close to working. I get all sorts of strange voltages at the output (measured with a DVM). Not only that, but even V1 and V2 are off when the Op Amp was connected.

Does anybody know what I'm doing wrong? Or perhaps have a better way to differentiating switch position 4 from the others? The actual switch connections cannot be altered, but the rest of the circuit is fair game.

upload_2016-3-21_19-17-10.png

NOTE: Schematic drawing error - I switched V1 and V2 labels by accident.
 

#12

Joined Nov 30, 2010
18,224
Assuming a 12 volt supply I read that as: 5v, 1.5v, 3V, and 6.03 volts
BTW, V1 (labeled V2) will never be zero because it is being driven by the op-amp through R41.
Check the voltages and tell me what you get so I can see if I went off the track.

Right now, the logic of this is a bowl of spaghetti to me.
Take a breath. Start over. Tell us what you need. Keep it under 500 words.:D
Do not explain to us how an op-amp works.
I really need you to remove logical the clutter from your verbiage.
@n4mwd
 

SLK001

Joined Nov 29, 2011
1,549
Are you really trying to use a 741 as a rail-to-rail output opamp with only a + supply? Or, a better question, is what is your VCC and VEE for your opamp?
 

Thread Starter

n4mwd

Joined Mar 21, 2016
50
Are you really trying to use a 741 as a rail-to-rail output opamp with only a + supply? Or, a better question, is what is your VCC and VEE for your opamp?
Yes, I connected it with +12V and Gnd. I figured it would be OK since it only outputs in the positive range. Or it is supposed to. The only real difference is that I actually used half an LM1458 which is two 741's on a chip - or its supposed to be.
 

Thread Starter

n4mwd

Joined Mar 21, 2016
50
Take a breath. Start over. Tell us what you need. Keep it under 500 words.:D
Do not explain to us how an op-amp works.
I really need you to remove logical the clutter from your verbiage.
@n4mwd
Don't worry about me explaining how an op-amp works, because I haven't got a clue... Magic would be the first thing to come to mind. Digital is what I normally do so linear of any kind is a stretch for me.

Anyway, the goal of the circuit is to differentiate between four possible inputs - ground, open, Vcc and Vcc through a 100 ohm resistor. So if the input is a 100 ohm resistor connected to Vcc, the it outputs logic high. If the input is connected to Gnd, Vcc or left open, its outputs logic low. Vcc can range from 6V to 15V.

I am not set on any one way of doing this, but I do have the constraint of having only one pin available on the MPU.
 

#12

Joined Nov 30, 2010
18,224
Define, "logic high". 5v? 3.3V? Vcc?
I have found the first problems.

1)This amplifier chip can not work with inputs that are within 3 volts of ground or Vcc.
If Vcc can be as low as 6 volts, that leaves nothing to work with for an input voltage.

2) You want low out for inputs both high and low but high output for one input which is between them. Right now, I don't have that answer. It's looking like a window comparator with only the middle voltage causing, "high". Can't do that with only one amplifier.
 
Last edited:

Papabravo

Joined Feb 24, 2006
21,159
Don't you want to use a comparator for this purpose? That way, with a pullup to the Vcc of your choice, you convert an analog condition to a digital output. You'll never get there with a 741 or a 1458 operating from a single power supply. Why? If you read the data sheet you'll see that the output can really get close to either supply rail. That is why NOBODY uses 741's for logic outputs, period, full stop.
 

Thread Starter

n4mwd

Joined Mar 21, 2016
50
I think I have it. Needs a dual open-collector comparator chip.
Logic High would be "not Low" or "not Gnd", but in this particular case, logic high means 3.3V because that is the voltage requirements of the MPU that I'm using.

Thanks for the circuit help. I think you are on the right track for sure. I have a few more questions.

1) In your circuit, the output of the switch feeds the center of a voltage divider with two 1K resistors. If the switch is open, the two resistors form a 2K equivalent short from Vcc (up to 15V) to Gnd. This would cause the two resistors to consume about 112 mW. If the switch is in any other position, one of the resistors will shunt 225 mW. So is there any reason why we can't make these 10K resistors to keep the power requirements down? Will doing so upset the balance of everything else?

2) I don't have the exact chips that you suggest. I do have an LM339 quad comparator. I am not sure if it has Open Collector outputs, but I think it might. Any reason why the LM339 wont work?

Again, thanks for putting me on the right track. Its late here right now, but I will breadboard it in the morning with the 339 and let you know what happens.
 

#12

Joined Nov 30, 2010
18,224
the two resistors form a 2K equivalent short from Vcc (up to 15V) to Gnd.
A 2K short? That's 0.0075 amps at 15 volts. The worst case scenario is less than 1/4 watt. I think we have different definitions of, "short".:D
If you use 10K resistors, the 100 ohm resistor will constitute 1% of the total. I think you can do that if you buy 1% precision resistors.
The LM339 is not guaranteed to work with an input voltage closer to Vcc than 1.5 volts.
With 10K resistors, the input voltage to detect will be 14.85 volts out of 15 volts. That is not within the proper input voltage range.
Apparently this can't be done with the parts you already have.
 

Thread Starter

n4mwd

Joined Mar 21, 2016
50
A 2K short? That's 0.0075 amps at 15 volts. The worst case scenario is less than 1/4 watt. I think we have different definitions of, "short".:D
...
Apparently this can't be done with the parts you already have.
Well, you are correct again. The LM339 didn't work. I verified that the input voltages were what they should be, but it didn't work. I built the circuit as you drew it without modification except for the chip. Its also possible that the LM339 is bad. It looks like I wont be able to continue much farther until I have the proper chip.

Regarding the "short", I neglected to mention another constraint and that is that the 100 ohm resistor from the input can't carry more than about 60 mW. I don't have any control over that resistor or else I would make it a 10K or something reasonable. Also, the 100 ohm resistor input is a "continuous" input whereas the other three inputs would be "momentary". As drawn, the 100 ohm resistor would carry about 200 mW @ 15V.

I studied your schematic and feel reasonably confident that I have figured out how it works. If so, then replacing the 1K resistors with 10K resistors will upset the resistors in the reference bridge. Still, I think I can get it to work with reasonable power levels if I play with the components. Looks like changing the 1K resistors to 4K would do it in terms of power. Unfortunately, that takes the comparator inputs a lot closer to Vcc. Can we decrease the top 390 ohm resistor and still have the chip work?

Anyhow, thanks for your help. I'm going to put an order in for some parts today and I will make sure I include a few of the comparators you mentioned.
 

AnalogKid

Joined Aug 1, 2013
10,986
Post #3 hinted at the problem with no useful information, and post #6 stated it in terms an experienced designer would understand. Let me try to answer your question.

Since you have an A/D input to the uC, you don't automatically need a dual-comparator circuit to do what you want. What you DO need is a different opamp. The LM741 cannot function with either of its inputs within 2 to 3 volts of its negative supply voltage. So with pin 4 at 0 V, both pins 2 and 3 must be greater than +2.0 V (typical) and greater than +3.0 V (worst case) at all times for linear operation. This is a problem for switch positions 1 and 2. This is covered on the datasheet under Input Voltage Range. The same limits apply to the inputs getting too close to the positive power supply rail on pin 7. This is the reason behind the comment in post #6. If the total supply voltage is only 6 V, and the input must be 3 V above the Vee pin and 3 V below the Vcc pin, there is no operating voltage range left.

It gets worse. Separate from the input voltage range problem is the output voltage range problem. A 741 is not a logic device, and its output cannot swing close to either supply pin. Even with a very low load current there still is a 3 V headroom limit for both supply rails. So again, with a 6 V supply there is no operating range.

Other newer opamps are much better at this. Many have an input common mode range that extends down to and even below the - power pin, so that part is relatively easy. Finding one that will make an output only 0.03 V above the - power pin is much harder. There are circuit tricks to add a DC offset to the output to get around this if you can modify the uC application program to remove that offset it in software.

After all of that, more bad news. I think your expectations are unrealistic. All analog circuits have noise and offset errors and other non-linearities. Even if your circuit worked and could make an output of 0.03 V, it might have offset voltage error that makes it 0.04 V. If the uC has a 10-bit A/D converter with a 0V to 5V input range, 1 LSB is less than 0.005 V so the offset error is twice as much as the resolution. That will make for very poor quantizing noise in the result. If the uC A/D is only 8 bits, then the resolution is just under 20 mV, so the difference between switch positions 3 and 4 is only 1 count, an even worse situation. So even if this circuit worked (and yes, it can be made to work), the resulting digital data value might not be reliable.

The circuit in post #8 will detect the switch position as 4 or not-4, but will not tell you the actual value of the 100 ohm resistor. If that is an acceptable result, then it is a better way to go. If you do need an analog reading of position 4, then your circuit can be modified to provide this but it won't be simple.

ak
 

Thread Starter

n4mwd

Joined Mar 21, 2016
50
@AK, I think you are right. The 741 sucks. I wont be using it. However, #12's comparator circuit looks like the way to go. I modified his circuit below to reduce the power consumption to acceptable levels by changing R1 and R2 to 3.9K. However, in so doing, the comparators are splitting hairs. At 6V, the difference between pass and fail is only 0.10V. Can this chip (TLV1702) work that close? Would reducing R3 even lower make things better?

upload_2016-3-22_11-28-9.png
Note: I don't know why its pink. It was white on my editor.
 

Attachments

SLK001

Joined Nov 29, 2011
1,549
The problem with comparators without hysteresis is when the inputs are close to the threshhold voltage, they will oscillate - badly. This is really bad with slow moving inputs.
 

Thread Starter

n4mwd

Joined Mar 21, 2016
50
The problem with comparators without hysteresis is when the inputs are close to the threshhold voltage, they will oscillate - badly. This is really bad with slow moving inputs.
Define "Close".
I think I saw something in the specs on that chip that said to use a cap to prevent oscillation.
 

SLK001

Joined Nov 29, 2011
1,549
Define "Close".
Me?

YOU define what "close" is. Does your input swing above and below the threshhold voltage? That is "close". How fast does it do this? Slow? If "slow", your circuit will oscillate. They oscillate because they are operated open loop, so the gain is huge. You would be better served using a rail-to-rail opamp such as an LMC6484 with gain set to unity.

EDIT: I wasn't thinking clearly when I suggested unity gain. 10X or 20X would be more appropriate.
 
Last edited:

Thread Starter

n4mwd

Joined Mar 21, 2016
50
The inputs are all DC so they shouldn't swing, but the circuit must be able to differentiate a signal difference of only 0.1 volts. So I guess the question is how close can it get before the comparator thinks its inputs are equal.

I like the TLV1702 because it is made to be a comparator and has the open collector outputs. This saves a lot of grief when it comes to interfacing with the MPU.

Additional data: The MPU checks the output of this circuit one time during initialization. After that, its a "don't care" input.
 

AnalogKid

Joined Aug 1, 2013
10,986
The problem with comparators without hysteresis is when the inputs are close to the threshhold voltage, they will oscillate - badly.
No, the won't.
I think I saw something in the specs on that chip that said to use a cap to prevent oscillation.
Comparator circuits like this do not oscillate. There are several things that can cause unwanted output stage transitions. Oscillation is only one of them, and is not a possible problem here.

What he is warning against is noise. If you have a perfectly clean reference potential and a perfectly clean input signal and a comparator cooled by liquid hydrogen, the input can sit 1 nV below the reference and the output will be perfectly stable. Warm up the chip (Johnson noise) and add few microvolts of random noise to the two inputs, and now the output will transition wildly as the two inputs cross over each other due to the instantaneous values of the two noise voltages. Normally, a comparator acts like an opamp with no negative feedback to limit the forward gain, and spends most of the time with its output overdriven to either a high or low clipped or saturated state. When the two inputs are so close together that their difference, when amplified by the comparator's open loop gain, produce an output that is not clipped or saturated. the circuit acts as a big noise amplifier, and amplified noise appears at the output. Normally this is not a problem because the input crosses the reference so quickly that the period of time when the comparator is not saturated is less than one cycle of the noise. However, when the input is transitioning slowly across the reference, the output can be unsaturated long enough to produce a large amplitude burst of random noise. The slower the input is moving, the longer the output noise burst.

Note that there is no specific frequency characteristic of the output transitions and they are not caused by feedback so they are not "oscillations". This is important because solving a noise problem and solving an oscillation problem are two entirely different tasks.

The classic solution is to introduce some intentional positive feedback between the output and the non-inverting (+) input. If the feedback impedance is a percentage of the Thevenin impedance at the input, this creates a condition called hysteresis. When the input (plus its noise) crosses the reference (plus its noise), the output changes state. With hysteresis added, this immediately changes one of the inputs, increasing the input voltage difference to a value that is greater than the worst-case difference between the noisy inputs. So the output changes state once and sits there even when the input is transitioning slowly. This means that for a single comparator there now are two transition points, which makes the arithmetic more messy. And, a comparator with an open-collector output has an asymmetrical output impedance driving the feedback resistor, which makes the math *very* messy. AND, you have two comparators intertwined; messy cubed.

Don't panic. All of this messiness has been around for decades and it cooks down to a big pile of Ohm's Law arithmetic. If whatever is looking at the output can stand a millisecond of noise during transitions, then you probably can ignore all of this.

"Oscillation" is a specific term for a defined condition. This ain't it.

Note - if you add a capacitor to a comparator circuit in the right place - *that* is an oscillator.

ak
 
Last edited:
Top