Opamp/comparator: reference voltage randomly pulled low - Page 1
Forum section: electronics / projects

author: okw
author_rank: Frequent Contributor
timestamp: July 30, 2025, 10:57:47 am
content: I've posted a few times about this circuit already, but I'll start a new thread, as I think I've found a reason why the comparator randomly not working as intended.The voltage reference on the non-inverting input seems to sometimes (very rarely) be shorted to ground, or at least "very low" (250mV). I think my oscilloscope is a little off, it's also reading 250mV if the circuit is powerless.So the comparator is stuck, since the inverting input will never go that low, and the hysteresis will never flip.If I power cycle the circuit, the levels are back to normal.What could cause this behaviour? Are the resistors of the voltage divider too big?Could it be some erratic power supply output during power up, that messes up the comparator input (they are high-z and shouldn't affect anything, right?).I hooked into the circuit in a few places (1x, but it shouldn't affect anything?).Probe 1 (yellow) on the 5V, probe 2 (blue) and 3 (purple) on the comparator inputs and 4 (green) on the second output.First screenshot is when the voltage reference is incorrectly low.Then a power-cycle, and in second second everything is back to normal.I had the same problems using a LM358 too, so some users suggested it could suffer from phase reversal and suggested a comparator instead. But I exhibit somewhat the same symptoms (not sure if the reasons are the same, as I didn't have an oscilloscope hooked into my old circuit).

author: xvr
author_rank: Frequent Contributor
timestamp: July 30, 2025, 12:21:39 pm
content: Check R6. Is it really 36K? May be 36R was soldered instead?

author: okw
author_rank: Frequent Contributor
timestamp: July 30, 2025, 12:54:14 pm
content: 363 so it's 36k.

author: youngda9
author_rank: Regular Contributor
timestamp: July 31, 2025, 01:07:51 pm
content: Whenever I have a problem, I always ask "how can I cut the possibilities in half". Start by removing R6 and power back up. Are you getting +2.5V at the non-inverting input? Measure R6 in hand with a DMM to ensure it's the correct value.Removing R6 provides a pad allowing you to feed in a voltage for further troubleshooting.Ensure power and GND are hooked up properly to the comparator.Disconnect all external signals, measure voltage at dividers to ensure correct. If not start removing parts to figure it out.R12 (1K) and R6 (36K) are in parallel with R1(10K) when the output is high (open collector). You have a LOT of hysteresis in either direction with this circuit.It could be test equipment...these are DC values. Measure with a good DMM to verify what your scope is showing.

author: okw
author_rank: Frequent Contributor
timestamp: July 31, 2025, 02:18:07 pm
content: Quote from: youngda9 on July 31, 2025, 01:07:51 pmI've done most of that already, and see correct voltages, resistor values, etc.But the challenge is, this problem only occurs 1 out of maybe 50 of 100 power ups.I know it has a lot of hysteresis, but the signal fluctuations are big. It controls the water level a heated water tank (125'C). Hot vapor makes the signal fluctuate a bit, but when the pump auto-fills to maintain level, it rocks the water surface a bit back and fourth, so it sometimes touches the level probe, which leads to great fluctuations.The scope is for sure off. I just verified the four signals with a Fluke 183:Ch1: 5.24V - Fluke: 4.981VCh2: 1.24V - Fluke: 0.88VCh3: 3.32V - Fluke: 3.826VCh4: 6.02V - Fluke: 4.928VI read somewhere that the hysteresis resistor is always much greater than the reference resistors. So I replaced the divider (R3, R4) with 10k, and kept the 36k hysteresis.To mitigate the signal fluctuations with the new narrower hysteresis, I replaced C2/R5 with 10uF/100k. Helped a lot, but not perfect.Before (with 100k v-ref) it was quite stable (except the occasional low comparator input, which makes the pump run forever).I hope my switch form 100k to 10k eliminates the occasional low comparator input.

author: Peabody
author_rank: Super Contributor
timestamp: July 31, 2025, 02:21:12 pm
content: Can you explain the circuit a bit more? Why does the output state need to change the reference voltage? Is it not possible to get the hysteresis you want without that connection? What voltage do you calculate the reference voltage should be when the output goes to ground?Edit: Nevermind.Edit2: The divider is the equivalent of a 50K resistor coming out of a 2.5V rail. So if the comparator output is at ground, the non-inverting input should be at 1.04V. If it's ever lower than that, then something else is physically wrong, like maybe R3 is going open, or R4 is going short.

author: SCSKITS
author_rank: Regular Contributor
timestamp: July 31, 2025, 07:21:32 pm
content: I would start by checking the value of R6 to make sure it is correct. I would also change R3, R4, R8, and R11 to smaller values like 4.99K. maybe even 2.49K. A few milliamps at 5V will not matter. Unless you need a very wide hysteresis band, R6 (36K) is too small compared to R3, R4 at 100K. If reducing the divider resistors it can be left at 36K or maybe 49.9K. I would also reduce R1 and R2 by 10X if the level sensor can drive the lower value. Is the level sensor analog or ON/OFF?

author: iMo
author_rank: Super Contributor
timestamp: July 31, 2025, 07:42:22 pm
content: Quote from: okw on July 31, 2025, 02:18:07 pm..perhaps it would be better to use a professional solution in this case.. messing with a 125C water tank might be dangerous.. also I doubt such simple circuit can master the above "fluctuations"..

author: Zero999
author_rank: Super Contributor
timestamp: July 31, 2025, 08:34:30 pm
content: Could you be exceeding the input voltage range of the LM393? It only extends to 1.5V less than the positive rail.The LM393 will work fine when one input is closer to +V by 1.5V, but when both inputs are too near +V, its output will go low (please someone fact check me on this because I'm not 100% sure).Start with IC1A .The -input will go close to +V, at 4.68V, when nothing is connected to the sensor input.The +input will be at 3.94V, when its output is high.I suspect this has something to do with why it's not working. Either adjust the resistor values or use a comparator with rail-to-rail inputs. If you want to do the former, then start by increasing R6.

author: SCSKITS
author_rank: Regular Contributor
timestamp: July 31, 2025, 11:24:51 pm
content: good point. With the comparator powered from +5V, there is almost no head room for the inputs.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: August 01, 2025, 08:54:37 am
content: Quote from: okw on July 31, 2025, 02:18:07 pmA quick Spice 3 resistor solution gives the voltages there1.0465117V~3.9534883V 100k 36k2.195122V~2.804878V 10k 36kThe 1.04V is between your Fluke and scope, which is as expected. That's not 'pulled low' at all, it is an expected voltage level.To unset that state, the probe needs to be lower than 1.04VThe other issue is 3.95V is above the common mode range, so your 10k change has fixed two issues.Common mode now has more headroom, and the minimum probe Z has increased.

author: okw
author_rank: Frequent Contributor
timestamp: August 01, 2025, 09:28:16 am
content: Quote from: PCB.Wiz on August 01, 2025, 08:54:37 amThanks.Since a floating level sensor results in 4.682V on the non-inverting output, should I adjust the divider to max out at 3.5, then lower the non-inverting divider to swing around the new point?

author: Zero999
author_rank: Super Contributor
timestamp: August 01, 2025, 09:46:40 am
content: Quote from: okw on August 01, 2025, 09:28:16 amThe LM393 will still work correctly, with one of its inputs outside the input voltage range.Start by increasing R6 to 100k. That will reduce the maximum voltage on the non-inverting input to 3.3V. The circuit should then work properly. If not, try increasing R1 to 470k.

author: okw
author_rank: Frequent Contributor
timestamp: August 01, 2025, 10:16:02 am
content: Quote from: Zero999 on August 01, 2025, 09:46:40 amI'm just worried about decreasing the hysteresis band. The pump is already stuttering a little bit right around the desired water level.Local humidity (and hence resistance) around the probe tip is fluctuating a bit with temperature, and if the pump stops when the probe is right at the surface of the water level, these local variations makes the pump stutter, or fire for short times. It of course stops after 2-5 times, but it's not so professional.When I went from a 100k to 10k divider, I solved the stuttering to some degree by increasing the the RC filter on the input, but it seems not sufficient.I'm not sure if I should additionally decrease the hysteresis band and increase the RC time constant?Or are there other tricks?Could a stronger divider on the inverting output solve some of the probe flluctuations?I'm just worried about galvanic corrosion on the probe if introducing too much current. I think on newer models, both the boiler tank and probe is stainless steel, but older use a copper tank and stainless steel probe.

author: Zero999
author_rank: Super Contributor
timestamp: August 01, 2025, 11:01:17 am
content: Quote from: okw on August 01, 2025, 10:16:02 amFirstly you need to determine the resistance thresholds for the sensor. Secondly calculate the resistor values/ratios. Finally confirm that both inputs don't exceed the input voltage range for the LM393.I've made a spreadsheet to help with this. The goal seek command can be used to select the value for a resistor in the circuit.Comparator resistance hysteresis.odsRefer to the following thread.https://www.eevblog.com/forum/projects/water-leak-detector-schematic-opinions-(comparator-talk)/msg5613773/#msg5613773EDIT: I've just tried opening the spreadsheet with Excel and the schematic doesn't show. I created it with LibreOffice on a Linux machine.Here's the schematic I used in the spreadsheet.And a Excel version, which should show the schematic in Excel, although might not work properly with LibreOffice.Comparator resistance hysteresis.xlsx(12.15 kB - downloaded 7 times.)EDIT:I've had a play with my spreadsheet, adding another resistor in parallel with R_in for the 1M.Going back to your original schematic.Try the following resistor values:R1 = 180kR3 = 220kR4 = 47kR6 = 39kThat should keep the thresholds close to what you already help, as well as keeping the non-inverting input within the input voltage range.Note that your circuit will always start-up with the relay on for a fraction of a second, as C2 charges. Connecting the other side of C2 to +V will make it start in the off state.

author: okw
author_rank: Frequent Contributor
timestamp: August 01, 2025, 06:41:01 pm
content: I replaced the 4 values and I experienced the hysteresis "pulled low" situation again (non-inverting input was 0.5V). I turned off, then back on, and everything was OK (input was 2.831V).I then continued to turn on and off a few times, and it seemed to happen more frequent now than earlier.I attached the screenshots of fault situation and OK situation, but DC values are quite off. So I included a screenshot of no power on any probes.I also supplied each channel with a good 5.00V and I read CH1: 5.29V, CH2: 5.47V, CH3: 4.71V, CH4: 6.09V.

author: Zero999
author_rank: Super Contributor
timestamp: August 01, 2025, 08:00:08 pm
content: Try replacing the level sensor with a variable resistor and removing C2.

author: magic
author_rank: Super Contributor
timestamp: August 06, 2025, 06:00:31 am
content: If the circuit accurately reflects the schematic and there is no measurement error, it looks like the LM393 malfunctions and sinks current through its IN+ pin. If the chip is powered from GND and 5V, its output can't be lower than 0V and the divider on IN+ should still generate ~1V. The input of LM393 shouldsourcea tiny current (<100nA), but not sink enough to pull the divider down to ground.If that's what's happening, the chip isn't working right. Perhaps an internal latchup triggers a parasitic NPN transistor whose collector is the N-base of the input PNP. At any rate, the chip isn't working right.What's the manufacturer of this chip, or is it an AliExpress special?What's the turn-on behavior of the power supply? Is it ramping up quickly, perhaps overshooting 5V by a lot? Do you have no capacitance besides the 100nF? Then power cycle the board 100 times to make sure that you can still reproduce the problem, add an extra electrolytic cap and power cycle 100 times again to check if the problem is gone.

author: magic
author_rank: Super Contributor
timestamp: August 06, 2025, 06:05:43 am
content: Quote from: okw on August 01, 2025, 06:41:01 pmIf the scope shows DC on all pins (and if you know that it isn't completely dead...) then the circuit is stuck in a DC state and you don't need the scope to measure it. A DMM will do a much more accurate job.

author: Peabody
author_rank: Super Contributor
timestamp: August 06, 2025, 01:41:23 pm
content: Quote from: magic on August 06, 2025, 06:00:31 amHe had the same problem with an LM358. So it's unlikely to be a problem with the chip.

author: magic
author_rank: Super Contributor
timestamp: August 06, 2025, 03:41:56 pm
content: The input stage of LM358 and LM393 is similar, so in theory it could still be the chip - maybe both types have the same, little known failure mode.The current has to be going somewhere, so if there is really nothing more connected to IN+ besides a few resistors, and if the values of resistors are as shown on the schematic, it is practically impossible that the current is going anywhere but to the chip, crazy as it sounds. And it is weird that it only takes a power cycle to restore normal operation, which rules out some "obvious" explanations such as blatant PCB error.If the measurements are wrong or the board doesn't match the schematic then there isn't much we can do about it, OP needs to make damn sure that things really are as shown. I would suggest disconnecting the scope and repeating all measurements with a DMM just in case, and also measuring voltages at both ends of all involved resistors to calculates their currents and polarity. To strongly prove or disprove the theory that LM393 is sinking current, the trace to IN+ could be cut right near the pin and a 10kΩ series resistor installed, then trigger the failure again and measure voltage across the resistor.editCan you measure Vcc current of the chip, does it increase when things go bad?And I suppose it could still be an intermittent connection issue, for example R3 or some trace near it going open and coming back when the board is manipulated while power cycling it.

author: Uunoctium
author_rank: Frequent Contributor
timestamp: August 06, 2025, 04:52:17 pm
content: The LM339, LM393, TL331 family isn't latch-up free, as Ti describes in his desing guide. There are several hints related to switched inductors as a causation for occurance of negative voltages (related to substrate = GND) on any pin (-300mV violation).So personally at first for diagnosis i would isolate the relay from common supply to observe if the mystic behavior disapperars.https://www.ti.com/lit/an/snoaa35f/snoaa35f.pdf?