adding offset to comparator: LM311 doesn't work the way I expect - Page 1
Forum section: electronics / projects

author: exe
author_rank: Unknown
timestamp: November 27, 2020, 01:57:10 pm
content: Hello my friends,I often need a comparator/opamp with some predefined offset. Such as a current limiter, for example (see screenshot from lt1575 datasheet, showing shunt sense comparator). I thought I found an ingenious idea: using a compator with offset/balance pins. With two or three resistors I could define an offset, awesome! I include the picture of the schematic and simulation that I used to test my idea. Basically, I made a unity-gain buffer, and measured offset voltage between IN+ and IN- pins. Why I think I can use it in linear mode: the datasheet provides a few linear circuits. It seems to be working in sim, but not in reality. On screenshot you can see a ~50mV offset that roughly remains the same despite chaning input (I apply a sine-wave to input and measure difference between inputs).The LT1011 part in simulator is kinda expensive, so I bought a venerable LM311P from TI. And it doesn't work. The first problem is that it wildly oscillated on my breadboard until I added an output capacitor (0.1u because that was the capacitor I had at hand). The next problem is offset voltage goes crazy. Even without any balancing, it is ~38mV (datasheet says 10mV max). Worse yet, after compensation it drifts a lot (tens of mv) with common-mode voltage.I suspected a broken part, so I replaced one LM311 with another LM311P, but it behaves the same way. I suspected oscillation, but adding/changing capacitor on supply pins didn't change anything.Any ideas what's wrong with this circuit?

author: Kleinstein
author_rank: Super Contributor
timestamp: November 27, 2020, 02:19:45 pm
content: The offset voltage set by the compensation pin is usually quite temperature sensitive - kind of a simple PAT (proportional to absolute temperature) circuit.So the offset trim pins are usually mainly to compensate the OPs / comparators own offset.The LM311 is already quite fast and thus prone to oscillation on the breadboard.Comparators are also missing the compensation that OPs have, so they easily oscillate when used with feedback. The circuits shown are kind of OK (still the drift) for an OP, but not a comparator.

author: Ian.M
author_rank: Super Contributor
timestamp: November 27, 2020, 03:26:10 pm
content: As the comparator is designed to to have a very high gain and fast slew rate, although its internal circuit has some similarities to an OPAMP, as Kleinstein has pointed out, its uncompensated, and *DOES* *NOT* provide access to the internal nodes required to add compensation. Unity gain stability is particularly challenging to achieve for a fast OPAMP, so as the high gain and slew rate would put it in in that category if it was internally compensated, it may be worth trying configuring your LM311 as a x10 non-inverting amplifier rather than as a unit gain buffer, so you can add some capacitance (say 100pF) from COL OUT to IN- to roll-off the HF gain. YMMV!I'm also dubious of the merits of slugging the HF response with a large capacitor on the output. This works when its a comparator because, in conjunction with the limited output current, it acts as a glitch filter, but when configured as an OPAMP, in conjunction with the effective output impedance (dominated by the pullup resistor) it adds an undesirable extra pole in the frequency response, which tends to decrease the stability. Its likely that its unstable even though you think its stable, and is acting as a class D PWM amplifier! If you don't have a fast current probe, add a small resistor (say 10R) between EMIT OUT and ground, and probe it as a proxy for the current sunk by COL OUT, using a 50MHz or better bandwidth scope, to check for HF oscillation.Also, I wouldn't even try to use a fast OPAMP, or a comparator as an OPAMP, on a breadboard without a 100nF decoupling cap directly across its supply pins!LT's appnote'Does Your Op Amp Oscillate?'may be of interest.

author: exe
author_rank: Unknown
timestamp: November 27, 2020, 03:44:42 pm
content: Huh, I see the issues. Let me explain the application, may be I'm doing it wrong. I wanted a reasonably fast comparator to enable down-programmer in a power supply when output goes, say, +50mV above the set voltage. I don't need precision here, +-10mV variation is fine over the whole temperature range (say 25-50C). What do you think about using comparator with offset? I wanted to do it this way because of low component count.BTW, I wanted to use LP311DR, which is a slower comparator, and it might help with stability. I ordered it about a week ago, but it will only arrive in a week or two (ordered from lcsc using cheap delivery, so I have to wait now).An alternative could be, for example, lift the reference voltage with an instrumentation amplifier, but then I'd need a 50mV low-impedance reference to drive REF pin. But that would add quite a few parts: reference, reference buffer, instrumentation amp... I think there was an opamp or in-amp with a buffered reference pin, but can't find it now and it seems to be an exotic part.PS I'll test the circuit with 10x gain and report results here. I'm curious to see the result.

author: David Hess
author_rank: Super Contributor
timestamp: November 27, 2020, 04:24:44 pm
content: Quote from: Ian.M on November 27, 2020, 03:26:10 pmThat method works to implement dominant pole compensation; even with the extra phase shift, the gain drops below 1 before enough phase shift is present to cause oscillation. It works with slower parts like the LM393/LM339 but probably not with an LM311 which might not even be stable in its linear range. Using an LM311 in this way would require careful attention to power supply decoupling and layout.Regulators often rely on dominant pole compensation because it produces low AC output impedance but it does severely limit bandwidth.

author: exe
author_rank: Unknown
timestamp: November 27, 2020, 05:49:23 pm
content: I tried with 9:1 output divider and results are... inconsistent, including supply current and offset. I'm not sure what I'm doing wrong, it might wrong wiring or unstable contact, but I think I'll try to use it as a comparator. It's a bit more tedious to measure offset, but should be less prone to user errors.

author: David Hess
author_rank: Super Contributor
timestamp: November 27, 2020, 08:55:07 pm
content: Quote from: exe on November 27, 2020, 05:49:23 pmAs was mentioned earlier, if you are trying this with the 311 on a solderless breadboard, you may be doomed to fail because of the high parasitic elements of the solderless breadboard. The 311 is already prone to oscillation with less than ideal construction.Check out the appendix of Linear Technology application note 13 "High Speed Comparator Techniques" for a discussion of this.

author: exe
author_rank: Unknown
timestamp: November 27, 2020, 10:06:12 pm
content: Yeah, by using it as a compator I get more consistent results. Still, it's easy to make it oscillating even in this configuration. The measured offset is about 2-3mV or thereabout.I'll stop experimenting with this one, and continue with lp311 when it arrives (a slower low-power version of lm311).

author: Zero999
author_rank: Super Contributor
timestamp: November 27, 2020, 11:19:01 pm
content: I'm confused. You're talking about the LM311, but your schematic shows it configured as a unity gain op-amp. Comparator ICs, such as the LM311 are not designed to be used as linear amplifiers. You should use an op-amp IC if you want a linear amplifier, such as a unity gain buffer. The only reason for using a comparator as a linear amplifier, is when there's one spare in a package, i.e. the LM339, you need a linear amplifier and want to save cost/space.The site linked below has a tool to assist designing an op-amp gain stage with a set amount of gain and offset.http://earmark.net/gesr/opamp/

author: magic
author_rank: Super Contributor
timestamp: November 28, 2020, 08:58:30 am
content: Why not µA741, LM101, TL071 or similar?They also have offset trim, they are opamps proper, they probabyl don't cost any more than LM311.

author: exe
author_rank: Unknown
timestamp: November 28, 2020, 10:41:28 am
content: Quote from: Zero999 on November 27, 2020, 11:19:01 pmThat was only to measure offset voltage. The attempt was unsuccessful. In a feedback configuration I can measure offset with a dmm. Otherwise, I think, I need an oscilloscope that is set to trigger on output change, which seemed to be more work to setup and less precise.Quote from: magic on November 28, 2020, 08:58:30 amThanks, I'm ordering TL071/TL051. The reasons they are a second choice are phase reversal and saturation recovery. That's why I wanted to use a proper comparator. I still want to try them, may be those issues are not issues. Tonight or tomorrow I'll try to use TL072/TL052 as a comparator (I don't have any ICs with trim pins apart from LM311). May be it will work well.

author: Zero999
author_rank: Super Contributor
timestamp: November 29, 2020, 05:58:44 pm
content: Quote from: exe on November 28, 2020, 10:41:28 amMeasuring the offset voltage of a comparator is tricky. It can be done without an oscilloscope, with just a DVM and a triangle wave generator.If the comparator has no offset, then if one input is 0V and a symmetrical triangle wave is applied to the other input, the output should have a 50% duty cycle.You can measure the offset voltage by applying a symmetrical triangle wave input to one input and looking at the duty cycle of the output. For example, if inverting input is held at 0V and the non-inverting input has 1mV of offset and a 10mV peak triangle wave is applied to it, the duty cycle of the output will be 55%. If the power supply is +/-10V and the output swings from rail-to-rail, the average output voltage will be 1V.

author: magic
author_rank: Super Contributor
timestamp: November 29, 2020, 06:51:36 pm
content: What's supposed to be wrong with simply applying a test voltage of a few mV to the input and watching the output?

author: Zero999
author_rank: Super Contributor
timestamp: November 29, 2020, 07:00:37 pm
content: Quote from: magic on November 29, 2020, 06:51:36 pmNoise could make that tricky to do in practice.

author: exe
author_rank: Unknown
timestamp: November 29, 2020, 10:34:07 pm
content: Quote from: magic on November 29, 2020, 06:51:36 pmI did that, it was surprisingly unstable. The voltage was applied via a trimpot which I slowly rotated. There was quite a big "deadband" when it was oscillating. I know that because I connected a led to the output (with 27kOhm pull-up resistor), there was +-a few mV when led was dim or even visibly oscillating. So, I'm saying that offset is no more than 2mV because that's the smallest change on input that reliably switches output from one state to another. So, definetely not a noob-friendly device :/.PS ordered tl071 lp311, I'm eager to see how they perform, esp how stable offset vs temperature is.PPS Natsemi's datasheet says "The LP311 is quite easy to apply without any oscillation". Will see, he-he.

author: magic
author_rank: Super Contributor
timestamp: November 30, 2020, 08:00:33 am
content: I might need to try it myself, I can't believe it's that badDid you try with the trimpot across the rails and divided down with something like 10kΩ:10Ω?

author: exe
author_rank: Unknown
timestamp: November 30, 2020, 09:28:54 am
content: I have a single 15V rail, a reference voltage somewhere in the middle of supply, and a 10 kOhm trimpot. I also added 0.1u capacitor from trimpot output to ground, this helped a little bit.

author: schmitt trigger
author_rank: Super Contributor
timestamp: November 30, 2020, 05:27:24 pm
content: In the original National Semi datasheet, there was a full page devoted to techniques to avoid comparator oscillations.Unfortunately, TI decided to delete that information on the current datasheet.However I found the OnSemi datasheet still includes it, page 7.

author: Zero999
author_rank: Super Contributor
timestamp: November 30, 2020, 09:21:47 pm
content: Quote from: schmitt trigger on November 30, 2020, 05:27:24 pmHere's a the classic National Semiconductor data sheet.Quote from: exe on November 30, 2020, 09:28:54 amRegarding biasing the LM311 in its linear region, to measure the offset voltage. Have you tried using the emitter output (pin 1) for the output? A capacitor between pin 5 and 1 might also help. Try a high gain inverting configuration, which should also make it more stable. Bear in mind, the functions of the inverting and non-inverting inputs reverse, if pin 1 is used as an ouptut.

author: exe
author_rank: Unknown
timestamp: December 01, 2020, 11:22:03 am
content: Quote from: Zero999 on November 30, 2020, 09:21:47 pmThanks for the datasheet.I'll try high-gain configuration if I have time till Thursday. On Thursday I expect LP311 and TL071 to arrive, so I continue with those parts. Dang, time is at premium this week.

author: David Hess
author_rank: Super Contributor
timestamp: December 02, 2020, 03:11:55 am
content: Quote from: Ian.M on November 27, 2020, 03:26:10 pmThat actually is a valid way to find the input offset voltage of a comparator. Somewhere I have seen an application note where a comparator is placed into a negative feedback loop to sample and then hold the input offset voltage correction.

author: exe
author_rank: Unknown
timestamp: December 05, 2020, 08:18:26 pm
content: My friends, I only managed to do a small set of tests for tl071. I think I managed to fry one (balance pin was connected to output held at ~Vcc because I left a small jumper on the breadboard :/ ). The current was limit to 10mA on power supply, but I'm still not sure if chip is fine, even though, according to the circuit, blancing pins are connected to internal 1k "pull down" resistors. So re-doing experiments on the second chip.On fresh tl071, I tested only "static" characteristics. I wanted to see how wide is common-mode voltage and what is power consumption. So, at 15V single supply useable common mode in buffer (unity-gain) configuration is Vee+3 to Vcc-1. Outside this window offset noticeably changes, esp. at around Vee+2.5 or thereabout it goes phase reversal, wee. Offset voltage is very good, imho, remains less than 100uV in range 4V-14.2V. It is also stable with temperature, heating up to 70C (heated with heatgun, crudely controlled with a thermocouple) didn't change it much.Next is to check dynamic characteristics, adding offset and hysteresis. That's for tomorrow or later.PS forgot to mention power consumption. It normally consumes ~2.1mA, and only when input voltage is above 14.3V it goes to "typical value from datasheet" of 1.4mA. That's a bit weird to me.

author: Zero999
author_rank: Super Contributor
timestamp: December 05, 2020, 09:40:58 pm
content: Quote from: exe on December 05, 2020, 08:18:26 pmHow do you know whether it's the common mode range, or output stage which is limiting the voltage range of the unity gain buffer? You'll find the TL071 will normally work with its inputs all the way up to the positive rail, so it's probably the output stage which is the limiting factor there.Another thing to note is that when the inputs are too close to the negative rail, the bias current shoots up, as the J-FET gate junctions become forward biased.

author: exe
author_rank: Unknown
timestamp: December 11, 2020, 09:43:42 pm
content: Quote from: Zero999 on December 05, 2020, 09:40:58 pmTrap for young players. Yes, that was the case.So far I measured only tl071 with no offset. I'm attaching the picture of measurements. Yellow line is difference between IN+ and IN-, common voltage is 4V. Blue line is output, loaded with 10k resistor and a red led. Power supply is 15V, average current consumed by the circuit is 2.8mA, input is 10kHz wave. Key observations: raise time is 7us, virtually no delay before input starts changing. Fall time is 5us, with 3us of overload recovery. Output swing is 12.7V. This gives rising speed of 1.8V/us, and falling 2.5V/us (measured from 0 to 100% of change), which is well below advertised slew rate of 20V/us. I'm not sure what I'm doing wrong. Even if I only take into account raise time of output change 10% to 90%, it's still slow.

author: exe
author_rank: Unknown
timestamp: December 13, 2020, 04:02:04 pm
content: Here is tl051. I expected it to show same performance as tl071 as I suspected it's the same IC, but no, it's slightly better. It consumes +0.5mA more in my test scenario. It's a bit faster: 3us vs 3.5us rise time*, 2.4us vs 2.7us fall time, and recovery is marginally better (2.2us vs 3.1us). Loading input with led (adds +0.6mA on average) doesn't really change output, except makes output swing slightly shorter at positive rail.I'm still puzzled by slew rate, much slower than I expected. Might it be that slew rate is, say, a "small signal" parameter, or only applicable with negative feedback?* Rise and fall times are measured by waveforms (software). It seems it only measures time between ~10% and ~90% of "final value".

author: exe
author_rank: Unknown
timestamp: December 13, 2020, 05:33:01 pm
content: I tried lp311, so far works the best. Somehow I manged to kill red led, even though it was, presumably, connected through 10k pullup resistor. Current consumption is 100uA as measured by my loosely calibrated power supply. With 10k pullup resistor and a green led, the "response time" is about 1.2us, as specified by natsemi datasheet. Interestingly, the datasheet from TI is very sparse and I'd say almost useless.Next step is to add some offset and hysteresis and see how it behaves over voltages and temperature.

author: Ian.M
author_rank: Super Contributor
timestamp: December 14, 2020, 11:29:26 am
content: OPAMP Slew rate is a large signal parameter. It is customarily measured over the interval between 10% and 90% of the output waveform for a 1V fast step change in the input voltage, with a feedback network that will keep the OPAMP in linear operation before and after the step (i.e. output must not rail or even get too close to rails). In many OPAMPs it is usually limited by the rate the input differential pair's tail current source can charge the internal compensation capacitor. You aren't going to get valid results from a low amplitude sinewave input signal, as the differential input voltage at max input dV/dt will be insufficient to steer all the tail current to one side of the differential pair.

author: exe
author_rank: Unknown
timestamp: December 19, 2020, 03:37:26 pm
content: Thank you very much, Ian. I drove my poor tl051 with 1V overdrive signal, and now slew rate seems to be in agreement with datasheet. I now understand difference between comparators and opamps.