Understanding how a comparator works - Page 1
Forum section: electronics / beginners

author: LoveLaika
author_rank: Frequent Contributor
timestamp: March 16, 2022, 09:10:00 pm
content: I'm developing a current sensing circuit, but I have trouble understanding how a voltage comparator works. In this case, I refer to theLM311. The datasheet describes this as the input voltage situations:QuoteTo me, that sounds like the following:If {0 > (IN+ - IN-) }, OUT is S- or VEEIf {0 < (IN+ - IN-) }, OUT is S+ or VCCThis is also mentioned in section 8.4.1 for voltage comparison, either logic low or high impedance (logic high with pull up). However, I'm having trouble understanding the comparator's behavior in my circuit shown in the picture below. Unlike what the datasheet describes, even though it is within the common-mode input voltage range, it doesn't go to VCC in the conditions mentioned above. My circuit is super simple in order to try and better understand this. VCC is 7.5 volts and VEE is ground. The output has a 15. The reference voltage at IN+ is fixed at 2.5 volts, while the voltage at IN- represents a shunt current measurement (from 0 to 5 amps as a voltage). Input common-mode range is -14.7 to 13.8 volts. At the start, when the difference in input voltage is positive, the output doesn't go to 7.5 volts as expected, but it goes to 3.75 volts. At the transition, it rises to VCC, but once the difference goes below 0, the output drops to VEE. I was wondering why it doesn't start at VCC as expected? Could it be due to the pull-up resistor that ties the output/collector to VCC? Removing the pull-up resistor gets more of a behavior that I expected from a comparator (aside from the starting voltage levels), but the collector would be left floating. Is a pull-up even necessary?

author: Zero999
author_rank: Super Contributor
timestamp: March 16, 2022, 10:30:18 pm
content: Something is wrong with you models.The RH111 is LT's version of the LM311, so use that model in LTSpice, rather than messing around with third party models.

author: LoveLaika
author_rank: Frequent Contributor
timestamp: March 16, 2022, 10:37:26 pm
content: Thanks for the suggestion. Yeah, it never occurred to me to see if LT/Analog Devices had models for comparators. I'll definitely check that out. If you don't mind me asking, do you have a link to it on Digikey? I can't seem to find it; all I get is some rocker switch when I search for RH111. I found the LT1011 though. Is that an equivalent part?(Sorry, also...you said that the RH111 is functionally equivalent to the LM311. So, you would use the RH111 in simulation and use the LM311 when designing your circuit?)

author: Zero999
author_rank: Super Contributor
timestamp: March 17, 2022, 09:17:49 am
content: Quote from: LoveLaika on March 16, 2022, 10:37:26 pmYes. Look at the data sheets. There are subtle differences in speed and offset voltage/current, but the two ICs are close enough to be interchangeable in 99% of applicationshttps://www.ti.com/lit/ds/symlink/lm311.pdfhttps://www.analog.com/media/en/technical-documentation/data-sheets/rh111fe.pdfAnother example is the RH117H, which is LT's version of the LM117, the higher grade LM317.Quote from: LoveLaika on March 16, 2022, 09:10:00 pmLooking at your circuit again. You have exceeded the common mode input range. The LM311 is only specified with at input voltages down to 0.5V above the negative rail.

author: LoveLaika
author_rank: Frequent Contributor
timestamp: March 17, 2022, 02:00:12 pm
content: Quote from: Zero999 on March 17, 2022, 09:17:49 amThanks for your reply. Putting aside what comparator to use, you brought this up because of my IN- voltage? I see now that the datasheet says that the input voltage (assuming that |VCC+| ≤ 15 V) can only go as low as VCC– + 0.5. So, if VCC- is fixed to ground, it can only go as low as 0.5 volts? That would explain why the input voltage common-mode range is a max of |14.5| volts, assuming a supply of +15/-15 volts. In this case, if a comparator requires a positive and a negative supply voltage (whereas I'm working with a single-supply voltage), perhaps it would be better to take a common op-amp and design a comparator with hysteresis around that. I'm trying to use a single-supply voltage because I'm also hoping I can also use the same circuit for negative-voltage current sense/comparison (though at this moment, I'm only focusing on the positive voltage side to work out the bugs). The issue with comparators is that they depend on a fixed reference voltage for resistances, whereas I want to vary my reference voltage. Maybe this comparator is not the appropriate component to use here.EDIT: Actually, looking carefully at the second and third bullet points....maybe this is okay? The voltage that represents my current measurement will either be within or outside of the common-mode voltage (either by being at 0 or within the range). If the reference voltage is kept within the range (by limiting it so it can only go as low as the low end of the common mode voltage), then it should be okay? Although.....I think rail-to-rail is what I need. That way, it should be safe, like the LT1719...EDIT: Perhaps there's still some bugs to work out, but ideally, I think the LT1719 may be what I'm looking for (plus, there's a model for it). It's rated for an input range from (VEE-0.1) up to (VCC-1.2), which makes my input voltage within the common-mode input range when my input voltage goes to zero. Hysteresis voltage seems okay (admittedly, I don't have a set value for what the hysteresis range should be). Plus, they also showcased how it can be used with a single-ended negative voltage supply in Figure 1. The results in the attached images seems to show for themselves.EDIT-2: Well, looking at my images, the max voltage would be 3.8 volts when powered by a 5-volt supply; so again, they're out of range at the high point. I mean, this is a demo circuit. I don't expect my current measurements to go up to 3 volts (representing 3 amps). Taking that into consideration by adjusting my voltage values, it still behaves as expected.

author: LoveLaika
author_rank: Frequent Contributor
timestamp: March 18, 2022, 10:07:28 pm
content: Sorry for the message, but if you don't mind me asking, how would you "shunt" the current when you detect a current draw that's over your set limit? I got the comparator working, so I would like to use the output voltage to act as a signal of sorts. When the load draws too much current (like in a short circuit situation), I would need to cut off the voltage/current to my load somehow.

author: ledtester
author_rank: Super Contributor
timestamp: March 19, 2022, 12:51:54 am
content: Do you mean something that will disconnect the load when an overcurrent event is detected and then requires some external reset signal to have the load reconnected?A key component for this would be a "latching comparator" circuit, such as:https://electronics.stackexchange.com/questions/203766/comparator-latch-circuitThe basic idea is to feed the output of the comparator back to one of the inputs so that it keeps the comparator in the triggered state regardless of what your input signal is.

author: LoveLaika
author_rank: Frequent Contributor
timestamp: March 20, 2022, 03:37:34 am
content: Quote from: ledtester on March 19, 2022, 12:51:54 amThanks for your reply. I think a circuit involving a latch might be what I need. I was kind of racking my head about what to do in an over current situation. Cutting off the load from the voltage through using a MOSFET was one idea, but then the shunt current would drop to 0, the load would connect back to the DC voltage source and draw high current again. Not sure if that was what I wanted. I also thought of shorting the load voltage to ground ,but then I realized how ridiculous it sounded, as then my DC/DC converter would just sink max current to ground, and that would also be bad. I was trying to include something for this overcurrent situation (and maybe over voltage) , but I wasn't sure how, or what solution would work best.I did some digging myself, and I foundGreatScott's videoon over current protection. He seems to use a relay along with a latch like you suggested. Funny how relays seem to solve lots of problems in situations like this. The safest way would be to cut off the load from the voltage source, and I think a latch-relay combo would work. Of course, I'm not a fan of the need of a button, but I can see how it is an appropriate safety measure. Before reconnecting the load again, you would want to see why it made that high current draw.

author: ledtester
author_rank: Super Contributor
timestamp: March 20, 2022, 01:41:26 pm
content: Shunting the power supply to ground is/was a common method to protect a circuit in the event of an overcurrent situation. The idea is to create a huge current draw that would blow a fuse upstream of the power supply and thereby shut everything down. The technique is called "crowbarring" and an SCR was generally used as the crowbar. Of course, the downside is that you have to replace a fuse every time the protection trips. (Btw, using an SCR as the latching element is another design idea.)Here's a related recent forum post of an AC overcurrent protection circuit that you might find interesting for ideas:https://www.eevblog.com/forum/beginners/250v-ac-configurable-current-limiter-or-electronic-fuse/msg4058368/#msg4058368

author: LoveLaika
author_rank: Frequent Contributor
timestamp: March 22, 2022, 02:48:39 pm
content: Thanks for your link. I'm learning a lot of good stuff here. It's just a matter of seeing what issues I need to consider, what I can afford to implement, and what would be the best way to do so. The way I see it, I'm running into five safety considerations (though if there are any that I haven't thought of, I'm always interested in learning about it):Current Limiting/ThresholdOver Current/Short CircuitReverse Voltage PolarityIn-Rush CurrentOver VoltageThe first two cases are tied together, as I would like to typically limit the current that is drawn by a load. If the current drawn is too high, then the load gets cut off from the source voltage, so no more high current draw. Looking at GreatScott's video seemed like one way, but now that I think about it, I'm not sure if it is the best method seeing as how he relied on a DPDT relay. I just felt like going with a big relay like that won't work in my case. Running through his circuit, it wasn't entirely complicated to follow, but it kind of felt like overkill for some reason. Your suggestion of a latch may be what I need (something that can remember state), though I'm trying to see what I can do about that initial start-up/indeterminate state.The third and fourth cases can be handled with MOSFET circuit protections and/or an NTC thermistor before my main components. Relatively simple, nothing fancy.For the fifth case, I'm on the fence about whether to consider it or not. Crowbarring is a good method, but I'm not really sure if I'll run into that situation (well, of course I say that now). My input voltages are fixed, and they're pretty low. Plus, do I have to worry about that if I have reverse-voltage protection?Also, thinking about it, with my wide range of voltages that I am thinking of setting, from 3 to 30 volts, it's also tricky to think of ways in how to make sure they'll work at any voltage level. I think of one solution, but it won't work for other voltages. It's quite perplexing.