LM393 Comparator - minimum delta between VREF and VCC?  - Page 1
Forum section: electronics / beginners

author: mindcrime
author_rank: Unknown
timestamp: June 19, 2022, 03:08:40 am
content: Hi all, I'm trying to set something up using an LM393 comparator and ran into something I don't totally understand.First of all, for the circuit I'm using, see here:https://www.ti.com/lit/gpn/lm393-nand specifically the diagram labeled "Figure 22. Non-Inverting Comparator With Hysteresis".[ Specified attachment is not available ]I have this set up on a breadboard, and was initially having a TON of frustration because I could not get the output to switch (go HIGH) no matter what I did, and even though the voltage on the non-inverting input was clearly higher than the voltage on the inverting (VREF) input. Specifically, I was testing a scenario with 4.7V on VREF and 6.0V on the NON-INV input. I would naively expect that to send the output HIGH but it wasn't working. This is with VCC on pin 8 at about 5.1V.I kinda figured out what was going on by switching the input to VREF to be another channel on my bench power supply so I could easily play around with the voltage there. I started at 2.5V on VREF, and still with 6V on the NON-INV input and sure enough, I got the HIGH output. OK, so this is good. But if I brought VREF up to 4.7, no bueno. Output went LOW again. I frobbed around a bit and found that I could go up to around 4.5V and see it work, but no higher.So I'm guessing that there's some minimum required delta between VREF and VCC for this to work. At least that appears to be what is happening. My question(s) are:1. Is my understanding correct? Is there really such a required delta?2. If so, what is it referred to in the datasheet? (I'm assuming it would be documented). I read through the "electrical characteristics" section several times and nothing stood out to me as representing such a value.3. If I'm wrong about the required delta between VREF and VCC, what else could explain the behavior I'm seeing?4. Also, if I'm right about the delta business, is there maybe another comparator I could use that would let me supply it with ~5.1V but still test against ~4.7V?Thanks in advance for any and all help!

author: ledtester
author_rank: Super Contributor
timestamp: June 19, 2022, 03:28:06 am
content: When working with op-amps or comparators look for the "Input Common Mode Voltage Range". That the range the inputs should be in.In the case of the LM393 this range is 0 to V+ - 1.5V where V+ is the supply voltage.There is also this footnote:QuoteLM393 datasheet:https://www.ti.com/lit/ds/symlink/lm393-n.pdf?ts=1655526688182

author: mindcrime
author_rank: Unknown
timestamp: June 19, 2022, 03:46:29 am
content: Quote from: ledtester on June 19, 2022, 03:28:06 amThanks, ledtester. That helps a lot.Fortunately I think I have a clear path forward. I think I can just setup a voltage divider to take the voltage I'm trying to test against, and get a lower value that will still tell me what I want to know. So I can make VREF something like 2.3V and the NON-INV input a nominal 2.5V and detect when it drops down to less than 2.3V. That would still solve my original problem, I think.FWIW, if anybody cares, the underlying problem here is detecting when a power supply is "going away". I have a circuit designed to automatically switch a load between two different supplies (say, a USB Powerbank and a mains powered USB charger). It works fine as long as there's a nice hard edge representing the transitions (eg, if I yank the USB cable out of the charger) but unfortunately when you just unplug the USB charger you don't get a nice, crisp edge... the device seems to have some internal capacitance and some current limiting circuitry or something, because in this "unplug it from the wall" scenario the output dwindles down slowly even with a really low resistance connected across the output. And that messes up my switching and causes my load (a Raspberry Pi) to reboot. So my thought was to monitor that rail with a comparator and forcibly do the switching as soon as the voltage drops enough that I can be reasonably sure it's because the power has been disconnected (as opposed to some random fluctuation causing it).

author: ledtester
author_rank: Super Contributor
timestamp: June 19, 2022, 04:01:50 am
content: There are ICs to handle this problem -- for instance the TPS2114A:https://www.ti.com/lit/ds/symlink/tps2114a.pdf(maybe start reading on page 16)For others search for "power mux" in the power management IC category, e.g.:https://www.mouser.com/c/?type=Power%20MUX

author: mindcrime
author_rank: Unknown
timestamp: June 19, 2022, 04:47:37 am
content: Quote from: ledtester on June 19, 2022, 04:01:50 amI should have known. In fact, I suspected such a thing existed, I just wasn't sure what term to search for. That said, working on this project from a much more fundamental level has been so incredibly educational (if frustrating at times) that I can almost say I'm glad I *didn't* know about "power mux" IC's earlier. :-)That said, I will look at ordering a couple of try out. Thanks for the pointer.

author: mindcrime
author_rank: Unknown
timestamp: July 01, 2022, 01:11:52 am
content: For anybody following this little saga, I finally got it all working. I did use the comparator + voltage reference thing to implement a "falling edge detector", and I did use a resistor divider network to bring the one input down into a reasonable range for the comparator with it running on 5.1V (and tuned the voltage reference down to a corresponding voltage just slightly lower than the input voltage).Now when the input drops by about 20 millivolts, the comparator goes low which turns off a 2N2222 that is driving the coil of my SPDT relay. In that configuration, the relay switches fast enough that the battery takes over before the Pi reboots (I had also added another 4700 uf capacitor to the output buffering as part of an earlier experiment. Not sure that was strictly needed, but the net result is something that works).Anyway, now my "USB Power Switcher" thing can handle the case where the USB charger has it's plug ripped from the mains socket, and toggle to the battery supply without my Raspberry Pi rebooting or anything.Unfortunately, getting all this worked out meant building up bits and pieces of this on two separate small protoboards, and then hacking it into the original "power switcher" board with a bunch of bodge wires and alligator clip jumpers. Not exactly something I can deploy into production. Sooooooooo, next step: rebuild this entire thing on one board. Piece of cake. It only took me like 3 days to do all that lead forming, wire stripping, soldering, etc. to build the other board. This version has even more components on the board, so I reckon it should take me about, oh, 37 years to finish building this thing.*sigh*Electronics is hard, let's go shopping.