# How does this overcurrent detection circuit work?

This is a overcurrent protection circuit. It'll triggered when it's more than 2Amps. I'm wondering how does that LM339 works related to the circuit. On the datasheet of LM339 page 11-13, it says:

– If IN– is higher than IN+ and the offset voltage, the output is low and the output transistor is sinking current

– If IN– is lower than IN+ and the offset voltage, the output is high impedance and the output transistor is not conducting.

I'm trying to figure out how does the output go to short detection when IN- is higher than IN+, and the output will go to 3.3V when IN- is lower than IN+ (based on my spice simulation). Like how does the current flow in the high impedance mode and how does the current flow to the short detection node? The short detection node is a digital input to a microcontroller.

• Where did this circuit come from? Commented Nov 22, 2019 at 18:34

The LM324 'measures' the current through R9 by producing a proportional current through R6.

Voltage dividers R1/R2 and R3/R5 lower the input voltages from sense resistor R9 to get within the op amp's common mode input range. Negative feedback is applied through Q1 and R4 producing a current of ~2.5uA/A at the Collector of Q1, which produces a voltage of ~830mV/A across R6.

The LM339 compares the voltage across R6 to a reference voltage of ~1.87V, set by R11 and R12. if current exceeds ~2.25A the voltage across R6 is higher than the reference voltage so the LM339 pulls its output down and SHORT_DETECTION goes from logic 1 to logic 0.

I'm trying to figure out how does the output go to short detection when IN- is higher than IN+, and the output will go to 3.3V when IN- is lower than IN+ (based on my spice simulation). Like how does the current flow in the high impedance mode and how does the current flow to the short detection node?

The LM339 has an 'Open Collector' output. When IN+ is higher then IN- its output transistor is turned off to become 'high impedance', so it does not draw significant current from R13. The MCU input probably also has very high impedance, so current through R13 will be very small and the voltage will be close to 3.3V. When IN- is higher than IN+ the LM339's output transistor is turned on and becomes a 'short' to ground, causing a current of ~0.33mA to flow through R13.

Such analog concepts as "high impedance" and "low impedance" are inappropriate for explaining simple digital configurations like "open collector" to beginners. Instead, simple and clear electrical concepts such as "open switch" and "closed switch" should be used.

A typical example of inappropriate use of "high impedance" are devices with 3-state output. Instead of saying "their outputs go into high impedance state" (whereby beginners look at us with misunderstanding but with "respect":), it would be much better to just say "their outputs disconnect... switch off from the bus". Then they imagine something familiar - an electrical switch. Another example: To turn off the lamp, people say "turn off the switch" and not "set the switch in high impedance state".

So a comparator with an open-collector output stage is a comparator with an internal output switch (n-p-n transistor here) which can be either ON or OFF. One of its terminals (the emitter) is internally connected to ground while the other (the collector) is outed... and it is figuratively named "open collector".

Since the "switch" is connected to ground, it can directly drive loads (LED, relay, motor, etc.) that are connected between the output and positive rail. When the comparator turns-on the "switch", the load will be supplied... and will shine, switch, rotate. Figuratively speaking, the switch "pulls down" the lower end of the load. When the comparator turns-off the switch, the load "pulls up" the upper end of the switch (the open collector).

Only, the input of our load - the microcontroller, is grounded... and it needs to be driven by grounded voltage... by a source. If we connect the open collector to the input, nothing will happen since there is no output voltage... there is only a short connection or open circuit. We have somehow to convert these two states into voltages... and we connect a "pull-up" resistor to the positive rail. Now, when the transistor is ON, the open collector is connected to ground and the input voltage is zero; when the transistor is OFF, the positive supply voltage is applied through the pull-up resistor to the input.

Why the pull-up resistor is not internally connected to the collector? That would be very convenient in this case... there would be no need for all these explanations because everything would be hidden for us. This gives advantages in other applications such as the above where it allows another power supply (higher voltage) to be used. An interesting opportunity is also to connect several open collectors together in the so-called "wired OR"... but this is another topic...

Open-collector circuits also have a major drawback - it is very easy to inadvertently apply +V to the open collector. I remembered for a lifetime what a colleague told me in the early 90s: "If you use an open collector circuit, always someone will connect it to +V".

There seems to be an error in the logic of this schematic.

I1 seems to represent some 2A current sensor yet if it were interpretted as a variable resistor it would draw 24V/2R = 12 Amps.

So rather than a shunt sensor, it may be a series sensor. Thus the differential voltage across R2 & R5 ought to reflect the current sense in mV/R but attenuated by 100k/120k.

when IN- is lower than IN+ (based on my spice simulation).

• Something is wrong with your simulation.

• The voltage above R1 is always lower than R3 (V1=24V) which feeds into IN-.
• thus IN- is always higher.
• this method is very sensitive to R tolerance errors so laser trimmed inside current sense IC's are preferred.

• I1 is a 2A load. So it's like 2A across R9 with a 0.1V drop across it. R9 works as a current sense resistor. Commented Nov 22, 2019 at 17:45
• Then the problem symbol is a current sink arrow. Also why show Op Amp symbol but only pin numbers for comparator? This is a bad practice. Commented Nov 22, 2019 at 18:04
• My bad. Because both op amp has a different pin number configuration in the spice model. And if I change one of the op amp symbol, the other will get affected too. I tried to change the model pin number but it doesn't work, so I think the fastest way to do is just use the custom pin number symbol Commented Nov 22, 2019 at 18:23

You asked how does it work. It works rather badly unless you use very closely matched and stable resistors. A +/-1% mismatch in the 20K/100K resistors will result in a ~+/-40% error in the detection point. Vos of the LM324 contributes as much as 9% more error.

It would be better to use a precision RR input amplifier and avoid the dividers, however high voltage RR input amplifiers with low Vos such as the OPA192 will be considerably more than 10x more expensive than an LM324. There are current measurement chips that use the same principle and may be more economical.