My LM311 is oscillating - how can I stop it? - Page 1
Forum section: electronics / projects

author: setq
author_rank: Frequent Contributor
timestamp: September 01, 2016, 09:01:25 pm
content: Trying to build an LM311 based zero crossing detector. Basically it consists of an LM311 with grounded inverting input and the signal which is about 600mV p-p @ 10KHz from a ~300 ohm source. Output is TTL. Supply is dual rail. Whole thing is deadbug over a ground plane and well bypassed. Unfortunately it is oscillating on output transitions as the scope trace shows below:Does anyone have any ideas on how to stop this? I don't really want to use a schmitt trigger as I'm going to measure the period of the pulse and that will modify it very slightly.Or is this just the LM311 being crap? If it is, are there any better jellybean comparators on the market

author: Zero999
author_rank: Super Contributor
timestamp: September 01, 2016, 09:10:41 pm
content: I understand why you don't want a Schmitt trigger but some hysteresis is necessary to avoid this oscillation. It doesn't need to be much. A mV or so will help.

author: StillTrying
author_rank: Super Contributor
timestamp: September 01, 2016, 09:11:12 pm
content: Add some +ve feedback, 82k - ish.I don't really want to use a schmitt trigger as I'm going to measure the period of the pulse and that will modify it very slightly.It will change it's mark/space very little and its period none.

author: setq
author_rank: Frequent Contributor
timestamp: September 02, 2016, 01:36:25 pm
content: Thank you both for the suggestions - appreciated.I was enabling the counter on the high output of the comparator so that would slightly affect the measurement of the high.I found a solution thanks to both of your hints. I added some hysteresis in the end as recommended, a 1.2M resistor between out and the reference pin. The reference is now provided by a 10k/10k divider instead of ground and it is all single rail and it is AC coupled to the comparator. I'm throwing the output through a flip flop so it changes state on the negative transition and that gives me a high which is precisely one period long and enables the counter. Works perfectly between the target 1khz - 10khz!This is a lame attempt at measuring very low frequency phase noise. RF is a bit easier with an SA!

author: GK
author_rank: Super Contributor
timestamp: September 02, 2016, 01:45:25 pm
content: Quote from: setq on September 01, 2016, 09:01:25 pmYou can capacitively couple the positive feedback so as to not shift the trigger point away from 0V. Downside of this arrangement is that if the signal source is removed you will get continuous oscillation. Whether or not that matters depends on the application.

author: setq
author_rank: Frequent Contributor
timestamp: September 02, 2016, 02:36:59 pm
content: Interesting idea. Will have a play with that one. Thanks for the suggestion.

author: David Hess
author_rank: Super Contributor
timestamp: September 03, 2016, 05:06:42 am
content: An LM311 is not fast enough to always require hysteresis although it is usually a good idea. Fix the power supply decoupling, lower the output loading, and minimize coupling between the output and inverting input which includes lowing the impedance at the inverting input.

author: diyaudio
author_rank: Frequent Contributor
timestamp: September 03, 2016, 10:12:54 pm
content: Quote from: setq on September 01, 2016, 09:01:25 pmOr is this just the LM311 being crap?Far from it, I'm doing 450Khz as a PID modulator in a 200W class d amplifier.Place a 22pf cap between IN+ and -IN, I have worked with this chip on a class-d modulator to stop erratic pluses.Circuit Techniques for Avoiding Oscillations in Comparator Applicationshttp://www.ti.com/lit/an/snoa860/snoa860.pdf

author: setq
author_rank: Frequent Contributor
timestamp: September 03, 2016, 11:34:40 pm
content: Excellent - thanks for the link. That's super-helpful.

author: Zero999
author_rank: Super Contributor
timestamp: September 04, 2016, 12:10:52 am
content: Quote from: David Hess on September 03, 2016, 05:06:42 amWell I wouldn't say that. It's the high gain and slow signals which will cause oscillation, rather than the speed. An old uA741 will oscillate when changing state when used as a comparator if the voltages on the inputs change slowly enough.

author: dannyf
author_rank: Super Contributor
timestamp: September 04, 2016, 12:24:43 am
content: Quoteyou don't have negative feedback so hard to imagine this thing oscillation, parasitics aside.could it be due to signal conditioning? or lack of hysteresis?

author: Zero999
author_rank: Super Contributor
timestamp: September 04, 2016, 06:23:15 am
content: Probably lack of hysteresis. There doesn't need to be any negative feedback for the output to oscillate when it changes state, with slowly changing signals on the input. When the comparator is in its linear region, the tiniest amount of noise will cause its output to flick back and fourth and even a little feedback in the parasitic capacitances can cause oscillation.

author: setq
author_rank: Frequent Contributor
timestamp: September 05, 2016, 10:37:06 am
content: Adding a tiny bit of hysteresis did the trick. Seems not to adversely affect the measurement as well as the output switches fast enough. I've ordered a few more LM311's as the offset voltage seems to vary considerably so I'm not sure that is enough to not cause problems on a random selection of devices. It works fine for this particular LM311. I've also stuck a FET follower in front of it as the switching was causing some transients on the inverting input. Fun fun.It's actually pretty amazing how quick the LM311 is considering it's ancient.

author: David Hess
author_rank: Super Contributor
timestamp: September 05, 2016, 01:45:42 pm
content: Quote from: Hero999 on September 04, 2016, 12:10:52 amMany comparators including the LM311 are stable in their linear rangeifdecoupling, loading, and parasitic feedback including input impedance are controlled. Even comparators faster than the LM311 can be stable but they all will still oscillate with negative feedback because they have horrible phase margin but that is not a limitation when operating open loop. If you manage to get a 741 to oscillate in its linear range without feedback, and I have had this happen as well, then decoupling, loading, and/or parasitic feedback including input impedance are again at work.Hysteresis is still a good idea even if only to handle noise on the input signal but many fast comparator circuits work fine without it despite a slow input signal. It requires attention to details but some precision applications use no hysteresis and periodically autozero the comparator's offset by forcing it into its linear range; this would not work if comparators always oscillated in their linear range.

author: diyaudio
author_rank: Frequent Contributor
timestamp: September 05, 2016, 06:26:28 pm
content: Quote from: David Hess on September 03, 2016, 05:06:42 amYes it is. Read the LM311 app note I attached.LM 311 you can get up to : (RC = 500 to 5 V, CL = 5 pF )Response time, low-to-high-level115nsResponse time, high-to-low-level165nsWithout some hysteresis the output will toggle like crazy, already evident but not limited to other issues mentioned in the app note.Faster rates can be achieved, just tie the strobe pins together.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: September 05, 2016, 07:50:39 pm
content: BTW, if you can't afford to add hysteresis to +in because of signal levels (a typical case being, you've got a timing capacitor there, and the hysteresis resistor would screw up the charging curve), you can always add it to -in instead (which in this case, is tied to GND, so it's ripe for opportunity).But that's negative feedback, right? Ah, but that's what's great about LM311, it has an "uncommitted" output stage. If you're using it with 'GND' = GND and 'OUT' to a pull-up (as any conventional open-collector comparator would be used), then you can simply add a resistor between 'GND' and GND, and that develops voltage out of phase with the normal output. You only need a few mV, so 10s or 100s of ohms is enough. Tie -in to this node instead, and there you go.Tim

author: David Hess
author_rank: Super Contributor
timestamp: September 07, 2016, 03:58:17 pm
content: Quote from: diyaudio on September 05, 2016, 06:26:28 pmWell, let's see:... the comparatormayburst into oscillation near thecrossing-point.I am only saying that hysteresis isnotalways necessary even with slow inputs on an LM311. This is in contrast to some comparators whichalwaysrequire hysteresis in one form or other under such conditions.

author: tatus1969
author_rank: Super Contributor
timestamp: September 07, 2016, 04:02:44 pm
content: make sure to decouple the supply with low ESR ceramic cap and short leads / SMD. Otherwise the comparator can oscillate from output swiching fed back to its supply rails.

author: Yansi
author_rank: Super Contributor
timestamp: September 07, 2016, 04:43:42 pm
content: That reminds me one of my projects where I have tried to build a dual slope integrating voltmeter. I was using a quad opamp (TL074 or OP482) for anything there including the comparator. It was slow and the output waveform barely looked as a proper "digital edge". It was working fine, but then I wanted to increase precision: LM311 and then it happened. NEVER have managed to stop that bastart from oscillating near the crossing point. Exactly the same output waveform as the setq had. No extreme decoupling* has helpedMaybe I should reincarnate the project and repair the circuit to make it work as it should*DIL packaged LM311, groundplane under, powered from +-5V decoupled using SMD 100pF NP0 + some tens nF SMD + 100nF ceramic in THT.

author: setq
author_rank: Frequent Contributor
timestamp: September 07, 2016, 06:15:15 pm
content: On the subject, a couple of years ago I built a very simple single slope DVM on a breadboard with an LM311 as the input comparator, 555+2n2907 as ramp gen and timing and a 2x74hc390+4x4511's as the display driver. That didn't oscillate at all. Trick there was to buffer the input with an LF356 which has stupid low bias current and stick an RC low pass between that and the comparator with 3dB point about half line frequency. And never go near that with a scope.