Op amp as a comparator, bad practice? - Page 1
Forum section: electronics / beginners

author: Infraviolet
author_rank: Super Contributor
timestamp: May 11, 2022, 10:42:36 pm
content: I've got a design I'm working on which already has some 4 element op amp chips on it, but needs to perform a comparator operation at the very end of signal amplification and filtering. I have spare op amps within the 4 element chips, so if I can use one like this it saves me having to squeeze an extra chip on to the PCB design. I've tested the design and for the speeds I'm working at (10s of KHz) it works well with an mcp6024 set up with +5V and Gnd as its rails. I have the analogue input signal entering the inverting input, the non-inverting input is held at a variable voltage by a potential divider set up with three resistors between 5v, gnd and the op amp's output pin.Is this bad practice in this circumstance, is the op amp going to die quite quickly if used like this? As it spends most of its time outputting either 5V (as near as possible) or gnd(as near as possible) it is in saturation except at times when it is briefly flipping between states.I certainly see some little spikes in the output from the circuit, nothing serious enough to cause problems for a digital pin reading the "comparator's" output, but does this imply the op amp chip is being mistreated?Thanks

author: TimFox
author_rank: Super Contributor
timestamp: May 11, 2022, 10:49:21 pm
content: Some op amps will get unhappy with a large differential voltage between the inputs, which often happens in comparator applications.Check the datasheet with respect to your voltages. Maybe you want to add back-to-back parallel diodes across the inputs, if that doesn't mess up the rest of your circuit.

author: free_electron
author_rank: Super Contributor
timestamp: May 12, 2022, 02:38:38 am
content: back to back input diodes (high differential voltages) and give it a bit of hysteresis (very small differential voltages) . Comparators always have a bit of hysteresis built-in so they don't become oscillators.Opamps are designed to have external feedback. comparators don't need it.

author: bdunham7
author_rank: Super Contributor
timestamp: May 12, 2022, 02:45:41 am
content: Quote from: Infraviolet on May 11, 2022, 10:42:36 pmDo tell--which ones?

author: ledtester
author_rank: Super Contributor
timestamp: May 12, 2022, 03:39:59 am
content: Some info from TI on the input clamp diodes:https://e2e.ti.com/blogs_/archives/b/thesignal/posts/op-amps-used-as-comparators-is-it-okayAnd in this video the op amp vs. comparator discussion starts at about 3:20:https://training.ti.com/kr/ti-precision-labs-comparators-pros-and-cons-using-op-amp-comparator

author: Ian.M
author_rank: Super Contributor
timestamp: May 12, 2022, 04:11:52 am
content: For theMCP6024, it specifically doesn't need a pair of anti-parallel diodes across its inputs to limit the differential input voltage. It has rail-to-rail high impedance CMOS inputs, each protected by an internal reverse biassed diode junction to Vss, does not suffer from phase reversal, and Fig. 4-11: Unused Operational Amplifiers, (B) explicitly shows it with its inputs strapped to opposite supply rails.The only fly in the ointment would be possible coupling between the comparator OPAMP and others handling low level signals on the same die, so don't do something stupid like using a spare from the input stage for the comparator!

author: brucehoult
author_rank: Super Contributor
timestamp: May 12, 2022, 04:42:17 am
content: Quote from: Infraviolet on May 11, 2022, 10:42:36 pmThe output pin connected to the non-inverting input? Isn't that guarantying it's going to oscillate when it's near the trigger point?Say the inverting input is well above the trigger point and the output is low, pulling the trigger point lower. As the inverting input falls slowly it will reach the trigger point, causing the output to to high and the trigger point to increase -- so that level of input is no longer low enough and the output will go low again.

author: Ian.M
author_rank: Super Contributor
timestamp: May 12, 2022, 05:21:23 am
content: Quote from: brucehoult on May 12, 2022, 04:42:17 amErrrrr...... That sounds like the normal DC positive feedback to provide hysteresis. Start with In- > In+ and falling. The output will be low. As In- reaches In+ the output starts going high, raising In+ so the output 'snaps' high and In- is now below In+ by the hysteresis voltage range.

author: Infraviolet
author_rank: Super Contributor
timestamp: May 12, 2022, 09:07:07 pm
content: Thanks for the tips.The circuit is indeed designed to have hysteresis, it acts as a comparator and by choosing the values of the three resistors (non-inv to gnd, non-inv to 5v and non-inv to output) I can set, withn certain limits, custom values for the upepr and lower threshold voltages. For example I can have it so the input has to rise above 3.8V to turn the output to one state, but drop below 3V to set the output to the other state, good for somewhat noisy input signals.As for that fly in the ointment, that is only if I try to handle small sensitive signals with another of the 4 elements in the same MCP6024 op amp, not if I handle other fairly non-sensitive signals sensitive signals in other parts of it? So avoid doing things like amplifying up a tiny voltage, but it is fine to do things which don't have gains more than two or three fold?P.S. I'm thinking of building some more stuff with these circuit elements but can only get, with reasonable lead times, MCP6004 chips in the format factor needed. As the signal isn't hugely fast, nor is it something where I'm trying to preserve very fine features of a signal, could the MCP6004 do an MCP6024's job here? It is physically pin compatible in layout, datasheet says the 6004 has high impedance CMOS inputs like the 6024.Thanks

author: Kleinstein
author_rank: Super Contributor
timestamp: May 12, 2022, 09:20:13 pm
content: The MCP6004 is similar to the MCP6024, but considerably slower. This may be an issue if a stage has high gain. Th eother point is that the slew rate is lower. Even the relatively fast MCP6024 has a slew rate that is not very high and could be a problem for some logig chips. Many comparators have a higher slew rate even for relatively low power ones.When using 1 OP as a comparator there may be coupling between the OP. The problem is not so much the gain of the stage, but more the impedance of the stage. So small amplitude and high impedance signal at another OP could be a problem.

author: strawberry
author_rank: Super Contributor
timestamp: May 12, 2022, 09:27:00 pm
content: comparators are not compensatedclass B

author: Ian.M
author_rank: Super Contributor
timestamp: May 12, 2022, 09:27:15 pm
content: Its not the gain of the other elements that matters, its their input signal level vs the signal caused by the transient. However the problem is more obvious at higher gain.In addition to external cross-coupling between traces, there is some internal (to the IC) cross-coupling due to the transient full slew rate switching current of the output stage flowing through the resistance of the on-die Vdd and Vss metallization, and of the bondout wires, and the sensitivity of the other amplifiers on the die to the resulting power transients is determined by their PSRR (min. 74 dB Typ. 90dB) so for your MCP6024, the effect of that transient on the input is effectively attenuated by about four orders of magnitude.@Kleinstein: Thanks for calling attention to high impedance stages.

author: David Hess
author_rank: Super Contributor
timestamp: May 12, 2022, 11:38:14 pm
content: Modern operational amplifiers will not be damaged operating as a comparator, but some early dual and quad parts had problems where one operational amplifier operating in saturation affected proper operation of the other units because of shared bias circuits.

author: magic
author_rank: Super Contributor
timestamp: May 13, 2022, 08:44:53 am
content: Shared bias circuits cause incorrect operation, if anything, not damage.Damage may occur due to input clamping diodes and those are still present in some modern opamps.As a general rule, almost no bipolar input opamps are suitable, except for some old types such as 741 and 358.4558 family are safe too, but they have phase reversal near the negative rail which may result in wrong output.Ditto TL072, but that's JFET, not bipolar.

author: Zero999
author_rank: Super Contributor
timestamp: May 13, 2022, 02:24:30 pm
content: Quote from: Ian.M on May 12, 2022, 04:11:52 amThe MCP6024 should be fine as a comparator. It has rail-to-rail inputs and outputs.It has other pitfalls which are probably irrelevant to the topic, such as: higher noise at common mode voltages above 3.5V and lower input offset voltage, when VDD<2.5V.

author: David Hess
author_rank: Super Contributor
timestamp: May 14, 2022, 02:40:15 am
content: Quote from: magic on May 13, 2022, 08:44:53 amOperational amplifiers which rely on an NPN process but use PNP inputs are suitable because they have a maximum differential input voltage specification of 30+ volts which comes from their high PNP emitter breakdown voltage. This includes 301/741 type parts which have a PNP input cascode, PNP input parts like the RC4136/RC4558, and PNP input single supply parts like the 324/358 and LT1013/LT1014.Most or all JFET input parts have a high differential input voltage range. CMOS parts are limited by their gate-oxide breakdown voltage.Other bipolar parts including rail-to-rail bipolar input parts are limited by base-emitter breakdown, and usually have diode input protection but not always. Some parts support a differential input voltage of 5 to 7 volts or so, and some are limited to 0.6 to 1.2 volts.An exception which proves the rule are "over-the-top" parts from Linear Technology. These have rail-to-rail inputs but the NPN input is arranged like a 741/301, and the PNP input is arranged like an RC4558, so they support high differential input voltages. I do not know if Texas Instruments has anything like these.

author: Kleinstein
author_rank: Super Contributor
timestamp: May 14, 2022, 03:41:24 am
content: Not all (but many) JFET parts support a high input differential. The OPA170, OPA171, OPA172 are examples with a limited input differential.

author: David Hess
author_rank: Super Contributor
timestamp: May 14, 2022, 09:01:59 pm
content: Quote from: Kleinstein on May 14, 2022, 03:41:24 amIt is too bad Texas Instruments does not show more of what is going on inside those parts. They have a dual complementary differential JFET input, yet are not rail-to-rail in.

author: ledtester
author_rank: Super Contributor
timestamp: May 14, 2022, 09:39:17 pm
content: Quote from: David Hess on May 14, 2022, 09:01:59 pmFrom the TI video in my previous post:QuoteThat page also has a downloadable transcript.It also has this to say about CMOS op amps:Quote

author: magic
author_rank: Super Contributor
timestamp: May 14, 2022, 09:51:43 pm
content: Of course they are CMOS, their product pages clearly say so, if flicker noise isn't enough of a hintThe architecture is described in "functional block diagram".One enhancement P-ch MOSFET input stage drives the main three stage path with CMIR down to ground.Second enhancement N-ch MOSFET input stage drives the output stage when the former runs out of CMIR at the top.Third enhancement P-ch input stage drives the output stage directly at high frequencies to override phase lag of the main path.I believe this is known as "active feedforward compensation", I have read a description somewhere, but I don't remember the details, including how to setup the various relations between stage transconductances and compensation caps to achieve smooth transition. But if this is done right, the amplifier has the bandwidth of a 2-stage topology and DC gain of a 3-stage topology.Because amplifier performance is inferior in the strict 2-stage mode (N-ch), see Table 2, they don't advertise it as RRI. But in every other regard, it is one.

author: Benta
author_rank: Super Contributor
timestamp: May 14, 2022, 11:01:18 pm
content: One thing to consider when using opamps as comparators is, let me call it: "internal saturation" (ask me how I know).When using them at low frquencies, it's normally not a problem.But opamps are not designed for signals saturating the middle- and output stages and will generally have very significant recovery times.This is extremely device-dependent, and even dependent on parts from different suppliers (eg, LM324).And it's normally not in the specifications/datasheet.

author: magic
author_rank: Super Contributor
timestamp: May 15, 2022, 06:59:17 am
content: Quote from: Benta on May 14, 2022, 11:01:18 pmDo you remember which LM324 were better and which were worse?

author: David Hess
author_rank: Super Contributor
timestamp: May 15, 2022, 08:29:32 am
content: Quote from: Benta on May 14, 2022, 11:01:18 pmSimplified schematics do not show it, but comparators have their active stages clamped to avoid saturation.

author: Zero999
author_rank: Super Contributor
timestamp: May 15, 2022, 09:12:44 am
content: https://www.analog.com/media/en/technical-documentation/application-notes/an-849.pdfhttps://forums.parallax.com/uploads/attachments/42093/93509.pdf

author: JMcC
author_rank: Contributor
timestamp: May 20, 2022, 06:24:01 pm
content: Scanning the thread, I see that many have pointed out some the pitfalls of OPA devices as comparators. Lets add limited output slew rate & possibility of phase inversion to those (apologies if I missed that someone caught these already). Devices are cheap, don't waste your time making somethng do a task it was not really designed for.Sometimes it works, but likely your time is better spent really.J

author: Jim from Chicago
author_rank: Regular Contributor
timestamp: April 04, 2023, 05:41:36 pm
content: I have recently been working on a design with an opamp used as a comparator. We recently replaced the old opamp with a new part (TLV910) and some of them are behaving unexpectedly. Some of them are failing and the noninverting input is getting effectively shorted (~tens of ohms) to the positive and negative supply rail. So it seems the opamp is being stressed and damaged by the normal operation of our circuit. We are supplying the opamp with 7V and our circuit is set up such that there can be 7V difference between the input pins, and the max differential spec in the datasheet is supply voltage + 0.2V. So my concern is that we are operating too close to the max spec and stressing/damaging the opamp. The previous opamp we were using had a max differential spec of 30V so there was plenty of margin before.Before encountering this issue, I had no idea that using regular opamps as comparators could be problematic.

author: magic
author_rank: Super Contributor
timestamp: April 04, 2023, 06:11:46 pm
content: Any chance of transients exceeding the positive rail or going below ground?Maybe some AC coupling capacitors along the way, or the opamp's supply coming up after the signal is present?

author: TimFox
author_rank: Super Contributor
timestamp: April 04, 2023, 08:50:50 pm
content: When I needed a precision comparator at work (before retirement), I would often use a fast op-amp with two Schottky diodes back-to-back in the feedback loop (inverting circuit) to drive a fast comparator chip.The inverting op-amp circuit allowed easy adjustment of the setpoint with a second input resistor from the bias level, and the comparator could have hysteresis.

author: Jim from Chicago
author_rank: Regular Contributor
timestamp: April 04, 2023, 09:04:57 pm
content: Supply rail is rated for 16V, we are putting 7V on it. I checked the startup and output for the supply which provides the 7V and it looked ok. There is 0.1uF between noninverting and negative supply rail. We put a diode between the negative supply rail and noninverting input to prevent it from going more than a schottky drop below ground.One thing I find odd is that there seems to be some contradictory advice from TI about this issue. In a TI paper about this issue (previously linked in this thread), they say rather strongly that you shouldn't use opamps in open-loop as comparators.But in the datasheet for the opamp I'm using (TLV910), they give an open-loop opamp comparator as a typical application.

author: TimFox
author_rank: Super Contributor
timestamp: April 04, 2023, 09:06:21 pm
content: TI gives specific reasons in their app note why that op amp can be used, despite the general rule against doing so.

author: Jim from Chicago
author_rank: Regular Contributor
timestamp: April 04, 2023, 09:24:56 pm
content: I noticed that but I'm still skeptical that they have addressed all potential concerns. They mention that because they're using a novel input stage, the TLV910 has a relatively wide differential voltage range spec compared to typical opamps. They also mention a relatively high slew rate and low offset. But in the paper I previously referenced, the author says the main difference between regular opamps and dedicated comparators is the output stage, and they don't mention much about the output stage in that section of the TLV910 datasheet.I'm just kind of paranoid about this part because I'm banging my head against the wall trying to figure out why it's failing in my particular circuit. Maybe it is perfectly suitable as a comparator but we are just pushing it too close to it's max differential voltage spec.

author: magic
author_rank: Super Contributor
timestamp: April 05, 2023, 06:33:51 am
content: Quote from: Jim from Chicago on April 04, 2023, 09:04:57 pmThis capacitor discharges to the positive rail through input protection when the circuit powers down. Not sure if there is enough energy there to cause damage, but it is technically out of spec if capacitor discharge current can briefly exceed 10mA. You could try a second schottky to the positive rail, or simply a series resistor in front of the input pin which limits current through the internal diodes (if Johnson noise is not a concern).Quote from: Jim from Chicago on April 04, 2023, 09:04:57 pmThe appnote sounds like generic CYA. There are opamps which can be blown up by using them as comparators (e.g. due to diodes between IN+ and IN- like NE5532), there are others which work OK-ish (like LM358) if you accept sluggish response time and maybe not truly rail to rail output.

author: MathWizard
author_rank: Super Contributor
timestamp: April 06, 2023, 01:30:55 pm
content: The only comparators I know by name are LM393, what are some newer jellybean ones ?

author: David Hess
author_rank: Super Contributor
timestamp: April 07, 2023, 01:05:51 am
content: Quote from: MathWizard on April 06, 2023, 01:30:55 pmThe LM339 is the quad version of the LM393. The LM311 is a faster single part with a more versatile output stage.I would say that the LT1016 is the highest performance universal "jellybean" part.

author: Zero999
author_rank: Super Contributor
timestamp: April 07, 2023, 01:20:08 pm
content: The nice thing about the LM311 is the output stage can sink up to 50mA, which is enough to drive a small relay and it can be configured as a source, if necessary. The disadvantages of the LM311 are it's only one channel and the inputs only extend to 0.5V above the -V supply.I disagree about the LT1016 being jellybean, as there are not other manufacturers. The MCP6542 and TLV3202 are also good and cheap, yet I don't consider them to be jellybean, since they're single source.