LM393 output oscillating issue - Page 1
Forum section: electronics / beginners

author: Veketti
author_rank: Regular Contributor
timestamp: December 26, 2021, 08:26:21 am
content: Dear All,I've got issue trying to make LM393 comparator to work as the output oscillates like crazy in ~1.8MHz frequency even though it should have hysteresis. This only happens when going from higher voltage to lower voltage to the input. The other way around there is only say three oscillations so to that direction it is pretty stable. However my need is to trigger when the voltage lowers. Connection is directly from datasheet, except I only had 1Mohm resistor when it calls for 10Mohm. Reference voltage is 2.218 and on attached oscilloscope screenshot blue line is the Vin and yellow line is the comparator output. Attached also the connection. Connections are made on breadboard. What might be wrong and how to correct?Thank you in advance.

author: EEEnthusiast
author_rank: Frequent Contributor
timestamp: December 26, 2021, 08:39:38 am
content: Can you probe with adding a 100 ohm resistor in series with the opamp output. I'm wondering if your scope probe or something else is loading the opamp with capacitance and causing instability.

author: Veketti
author_rank: Regular Contributor
timestamp: December 26, 2021, 09:00:28 am
content: Thanks for reply. I added 100 ohm resistor and no change, except the oscialltion frequency dropped to 1 MHz..

author: EEEnthusiast
author_rank: Frequent Contributor
timestamp: December 26, 2021, 09:09:27 am
content: In that case, may be increasing the feedback resistor is the only option. You are adding too much feedback that keeps it oscillating.

author: Veketti
author_rank: Regular Contributor
timestamp: December 26, 2021, 09:30:36 am
content: I just found sortiment of SMD resistors which had 10 Mohm resistor so I was able to test with correct values. Now, however output voltage tapers down slowly until it almost reach as low as the input voltage and then switches. Have I misunderstood, but I thought this should keep the output stable until it cuts it sharply. Now this is kind of missing the point why this comparator exists..

author: gcewing
author_rank: Regular Contributor
timestamp: December 26, 2021, 10:36:40 am
content: I suspect that you have the inverting and non-inverting inputs swapped. That would give you an inverting amplifier instead of a Schmitt trigger, but made with something that's not really designed to be used that way. I wouldn't be surprised if you get oscillations in that situation.

author: RoGeorge
author_rank: Super Contributor
timestamp: December 26, 2021, 11:13:55 am
content: Did you put any decoupling capacitors right near the power pins of the 393, something like 10nF parallel with 100nF?If not, you should add them and see if the oscillations goes away.Could also be stray capacitance/inductance with the rest of the board, bad power supply, or even flux remaining from the soldering process (some types of flux debris are conductive). Or maybe it's a defective IC. A 393 with hysteresis shouldn't oscillate.Can you put a picture with the physical circuit?

author: Veketti
author_rank: Regular Contributor
timestamp: December 26, 2021, 12:35:58 pm
content: Unfortunately the inputs are not swapped. I tried also decoupling capacitors but no differences. Also changed to another IC and no changes. Power is supplied through lab power (Rigol DP832). I tried also configure the unused comparator as a voltage follower according to TI's tech note SBOA204A. That made the situation worse and brought the horrible oscillations to the rising voltage trigger as well. Is it so that it's impossible to test this on breadboard? I've faced similar situation with OP amps that not working on breadboard but in actual circuit it works. This however doesn't bring much confidence to me..

author: EEEnthusiast
author_rank: Frequent Contributor
timestamp: December 26, 2021, 01:16:47 pm
content: On a bread-board, the capacitance between adjacent pins is very high, due to the slots for the pins being parallel for a long distance.However, the LM393 should not be affected much. If you have an LM321 or LM324 in hand, please try that. Those work with almost all breadboards. I have never seen issues with those.

author: THDplusN_bad
author_rank: Regular Contributor
timestamp: December 26, 2021, 01:22:10 pm
content: Hello Veketti,the previous tips were all correct, but allow me to say that you need to improve your breadboarding technique.The "flying wires" in your setup form large loops, which all contribute to the oscillation problem. They may pick up RF noise and 50/60 Hz hum as well as contradict any measures such as the mentioned power supply bypassing - parasitic inductance and resistance are your foes.When you build your schematic on a bread board, try to follow the basic rules as provided on page 2 in this document from Analog Devices:https://www.analog.com/media/en/training-seminars/tutorials/MT-100.pdfI am aware that this mainly refers to custom "bread boarding", say PCBs - but the same principles apply to the "solderless" bread board type you are using.So,Keep all connections as short as possible. Cut and bent the terminals of components such as capacitors and resistors to fit into place. Vertical orientation might be better than horizontal for some connections. This is particularly important for the feedback path and the power supply connections.Do not use long wires routed from the bench power supplies, but form a locally bypassed power supply with 100µF and 100nF cap in parallel with pin headers that lead to the bench power supply. The power supply "rails" on the solderless breadboard are ideal for that. Run short wires from the power supply rails to the OpAmp and use local bypass capacitors as suggested earlier as close to the OpAmp as possible.If nothing else helps, switch to a "perfboard"https://en.wikipedia.org/wiki/Perfboardand solder your components instead of using the solderless bread board. These have significant capacitance in the order of several pF between contact points.When you design your first own "real" PCB, try to learn from the best analog designers; such as Jim Williams, Bonnie Baker, Bob Pease, Walt Kester or Walt Jung. There are dozens of "hands-on" Application Notes and similar documents related to the prevention of oscillation issues, out-of-the-loop resistors and proper power supply bypassing.Do not give up on this yet; just try one modification at a time and evaluate each step.And most importantly: Have fun!Cheers,THDplusN_bad

author: Veketti
author_rank: Regular Contributor
timestamp: December 26, 2021, 04:08:22 pm
content: I got OP amp LM2904 and tested it as it had comparator example circuit. It didn't oscillate at all, but it was inverted and veeery slow. 286 us switching time... Inversion doesn't matter, but delay does, so this IC is not suitable. Unfortunately I didn't have any of those other IC's that EEEnthusiast mentioned..

author: magic
author_rank: Super Contributor
timestamp: December 26, 2021, 04:25:45 pm
content: Dunno, try a capacitor (ceramic or foil, maybe 10~100nF) between IN- and GND, physically close to the chip.Beware that since you bought those ICs from some dodgy online supplier, they could be something other than LM393 (like LM358), although in this case slew rate is too fast for a cheap opamp - they look like real comparators.LM2904 is about the same as LM358 which is half the LM324 or twice the LM321. No point trying them all

author: Kleinstein
author_rank: Super Contributor
timestamp: December 26, 2021, 04:26:36 pm
content: There could be a problem if the ref voltage is too high. The LM393 like the LM358 has a limited common mode range. If at the upper edge the hysteresis can make it oscillate in and out of phase inversion.For the breadboard I would consider soldering the decoupling cap (e.g. 100 nF THT) directly to the top part of the pins, so it gets a reliable short connection and still fits in the board. The LM393 is cheap and one could keep that using for breadboard use only.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: December 26, 2021, 04:41:39 pm
content: Quote from: EEEnthusiast on December 26, 2021, 01:16:47 pmDing ding ding!The wiring, while a mess -- isn't such a big deal at these frequencies (~MHz plus low harmonics), or voltages or currents (5V?, like 10mA max). Very roughly speaking, the inductance of a wire is 1nH/mm, so the ~10cm links are a good 100nH, maybe more going through loops. And with so many loops interleaved together, the mutual inductance is also significant (say 5 or 10% worth, between haphazardly placed loops; up to maybe 60 or 70% for closely paired loops). But again, with like 10mA peak at 100ns switching time, the voltage drop across any of those is only going to be ca. V = L dI/dt = (100nH) (10mA) / (100ns) = 10mV. Fine, I guess that's relevant at the very instant of switching, where the inputs are within about 10mV, but that's not going to persist for more than a few cycles of the burst; something else is needed to account for that effect!And so also, it doesn't much matter whether there's a bypass cap super close by, as long as it's somewhere on the board, and you've not gone out of your way to give it long fly leads or anything.A handy troubleshooting tip: you can tell whether it's inductive or capacitive, in situations like this, by waving things around! What things? Well, things like loop area of wire jumpers, or their spacing (coupling). If you have some ferrite pieces handy, you can, say, insert a rod into the loops, and see if that affects anything; or close an E-core set around a wire to increase its inductance -- or several at once to greatly increase their mutual inductance. (Rods can be salvaged from AM radios; core sets from power supplies. Disassemble carefully, they shatter easily! Tip: superglue can be used to reassemble them, if they aren't in too many pieces. Heat helps to loosen the varnish and glue.) That covers inductance; for capacitance, you can use your own hands -- grasping a wire will increase its capacitance by some pF, and directly touching a node puts an effective R+C to ground on that node (using your body's resistance and capacitance; the resistance is frequency-dependent but varies from the ~Mohm of dry skin, to ~100s ohms at VHF).In this case, I think you will find, if you touch the two wires at OUT and -IN, the frequency will drop. The slot-to-slot capacitance of solderless breadboard is typically 4pF, and you can increase it by a few in this way. Which should reduce the frequency from a bit over 1MHz, to a bit below. The output risetime will also slow a little (since it's just a resistor pullup into whatever total node capacitance is -- scope probe included).So what's the fix? Increase the capacitance (to ground) on the -IN node, so it's not so easily bullied around by the adjacent OUT node. Just a few 100 pF will help greatly, but some ~nF may be needed to cure it entirely this way, which isn't great (maybe you need a faster signal at that node, so can't afford nearly so much capacitance). You can also balance the capacitance: if +IN and -IN have the same source resistances, then equal capacitances to them will null the coupling from OUT -- basically, given the above condition, add a jumper from +IN to the slot just left of OUT. Use the breadboard capacitance against itself!Of course if the resistances aren't the same (and actually, with a pot over there, the resistance will vary some with position), you need to use a ratio of capacitances corresponding to the ratio of resistances.Important fact: you can use extra positive feedback capacitance -- basically a few to tens of pF in parallel with the 1M, which has the effect of holding off additional transitions (including intended ones!) after the first flip, within a time frame given by the feedback RC time constant.Speaking of scope probe, mind that on X1, it has much more capacitance (~100pF!) and a low frequency response (~6MHz?). X10 is preferred, having lower capacitance and full frequency response (100MHz+), and the scope has more than enough gain to deal with the attenuation for signals like this.Tim

author: Veketti
author_rank: Regular Contributor
timestamp: December 26, 2021, 06:48:17 pm
content: Wow, just wow. I almost gave up, but from T3sl4co1l advice added 10pF ceramic cap parallel to the 1M and BOOM it's perfect! See the attached scope screen shot. Million thanks, you saved my day.Now the question is. Do I need to implement this 10pF cap similarly to my PCB design, or is this just the issue of breadboard? And why is it not included in the example of LM393 datasheet?

author: T3sl4co1l
author_rank: Super Contributor
timestamp: December 26, 2021, 07:58:39 pm
content: Well, you can do some calculations to estimate whether it's needed or not. Go back to the RC time constants, and figure how much input error is tolerable before it'll start oscillating (i.e., where it's comparable to, or greater than, the intended hysteresis margin).Or use rate of change. If the output falls 5V in ~100ns or whatever, that's 5V/100ns = 50V/us rate, andI = C dV/dtAnd say it's 1pF so1pF * 50V/us = 50uA50uA into a 1k resistor is 50mV, certainly more than the input offset, so maybe a concern. For sure into 10k (500mV).If your setup is as shown in the schematic, then 5V into 1M into 10k is ~1/100th, or 50mV hysteresis, so this amount would be a problem. No surprise, then, that the breadboard's ~4pF is behaving as shown. And that an extra >4pF to +IN fixes it.Note that the datasheet shows -IN being "Vref", i.e., near zero ohms source resistance, a fixed voltage. So, it doesn't bounce due to the stray capacitance.On PCB, this will be more like 0.1-0.5pF, unless you're going out of your way to make a terrible circuit -- so you can reduce the resistances to better swamp out the stray capacitance (say use 1k instead of 10k), add a few pF between OUT and +IN, increase the hysteresis amount as needed (and, if tolerable), or even something cheeky like route the +IN and OUT traces together for a while so they end up with stray capacitance (using terrible layout perhaps to your advantage).Tim