Using LM393 Comparator to detect the voltage when 120Vdc drop down to 40 Vdc light up a Led.

Thread Starter

andrew74

Joined Jul 25, 2022
102
I receive 120V DC from an inverter which, when it shuts down, starts to decrease until it reaches 0V. When it drops below 40V (Vref) I want an LED to light up.

I would like to realise the application using an LM393 comparator (I have this available) but I have some doubts:

1) On the datasheet of the LM393 I read that the maximum ratings of Input Differential Voltage and Input Common Mode Voltage Range are about 36V .. so I don't think it can directly give these voltages to the comparator. Am I wrong? Have I interpreted those parameters on the datasheet correctly?
If the answer is yes, what can I do? I need to reduce both Vin = 120V and Vref = 40V to something acceptable for the comparator input.

2) How do I create the Vref? Do I use a resistive divider on 120V? Or maybe a pair of Zener in series?

(P.S.: I only want to use Resistors, Capacitors, Diodes and the Comparator)

Thanks.
 

WBahn

Joined Mar 31, 2012
29,978
So what is powering your comparator and LED as the inverter shuts down (and after it's done shutting down).

If you use a resistive divider from the 120 VDC to get Vref, then Vref is going to go down as the inverter voltage goes down. You want to use something like a zener diode. But you need to consider what happens to your reference after the inverter voltage falls below it.

You definitely don't want to put 120 V directly into the inputs. You need to divide them down to something that the chips can always handle.

And, again, how are you planning to power the comparator?

It shouldn't be too hard to use a few resistors, transistors, and zener diodes to make a circuit that will turn the LED on as the output drops below 40 V and keep it on at the same intensity (about) until the voltage drops below about 10 V and then dim from there.
 

BobTPH

Joined Jun 5, 2013
8,813
Is it really 120VDC? An inverter produces AC. So where is the DC coming from? If you rectified and smoothed 12VAC to DC that would be produce 170VDC.
 

Reloadron

Joined Jan 15, 2015
7,501
If you rectified and smoothed 12VAC to DC that would be produce 170VDC.
Pretty sure we mean 120VAC. :)

So what exactly are you planning to do? Yes, it's easy enough but you still need a fixed voltage power supply for your comparator as mentioned. You can derive your reference voltage from that. The LM393B (B Version) will source enough current to drive a LED if that's all you want. Use a voltage divider on your high voltage DC.

Ron
 

AnalogKid

Joined Aug 1, 2013
10,987
I think that is a typo, and Bob meant if you rectify and filter 120VAC, you get 170 VDC.

To the TS: As in #2, what is the power source for the comparator circuit? That determines the components you can use. In general for this type of application, you divide the variable input voltage (your 120 VDC source) with a 2-resistor voltage divider, bringing it down to a voltage range that a common comparator can handle. For example, if you attenuate it by 20:1, this produces a signal that varies from 6 Vdc to 0 V, always in direct proportion to the original input signal. A comparator circuit powered by 12 Vdc can easily handle this.

You need a fixed voltage reference to compare against. Depending on the trip point accuracy you need, this might have to be a reference diode like a zener, or a stabilized voltage reference IC. OTOH, if the required trip point accuracy is not critical, you might be able to derive the reference from the comparator circuit power source through another 2-resistor divider.

ak
 

WBahn

Joined Mar 31, 2012
29,978
So here's something I threw together just now. It's pretty crude, but it gets the idea across.

1664342688127.png

It uses a 4.7 V zener (D1) as the reference. To the right of that is a current source that pulls 1 mA from the Vcc rail. The top current source scales this up to 15 mA, which then feeds D1, the current mirror, and the LED circuit.

The 15 mA is partitioned as follows: 1 mA for the mirror, 10 mA for the LED, and 4 mA for the zener. When the LED is off, that current is shunted to the zener.

The voltage divider on the left divides Vcc by a factor of 10 so that when Vcc falls to 40 V, the voltage at the divider output is about 4 V, which is now low enough to turn on Q2 and drive the LED.

The second zener, D3, is there to prevent the base voltage on Q2 from going too high. It clamps the voltage at the top of R8 to the same 4.7 V at the emitter of Q2 until the Vcc voltage has fallen almost to 40 V, at which point it drops out.

Once the voltage has fallen below 40 V and the LED is on, it is able to maintain that voltage across D1, and hence keep the LED on, until the Q4/Q5 transistors start going into saturation, which happens at somewhere around 7 V. Can't ask for much better than that.

1664343246820.png

The circuit has some issues. The total current draw when Vcc is at 120 V is 19 mA. So the quiescent power of the circuit is about 2.25 W. This can be reduced quite a bit by choosing an LED that only needs a couple of mA and turning down all of the programmed currents accordingly. With a 2 mA LED current, the D1 zener base current can be brought down to perhaps 1 mA (depends on the zener used, can perhaps be quite a bit less) and the bottom current mirror can probably be brought down to perhaps 0.1 mA and scale that up in the top mirror to perhaps 3 mA. Q2 can probably be turned into a Darlington (or similar) to let the impedance of that divider go up an order of magnitude. Right now it alone draws 4 mA. I think you can get the entire circuit to pull less than 4 mA, reducing it's idle power consumption to under 500 mW.

My components choices were dictated by what was available in LTSpice. In particular, the PNP transistors were chosen for high Vce breakdown values (200 V, I think).
 

WBahn

Joined Mar 31, 2012
29,978
I did some tweaking and got to this:
1664344991871.png

The data sheet for the 1N750 indicates that it really wants a lot more current than the ~1 mA I'm giving it, but this is the only 4.7 V zener model I have in LTSpice (I just have the basic install).

1664345104092.png

The current in the LED is set for ~1 mA. I have no idea what this particular LED would do, but there are LEDs out there for which this is a decent indicator current.

The total current of 3.5 mA at 120 V gives a power consumption of only 420 mW, which isn't bad.

One thing I don't understand is that when I change Q2 and Q6 to 2n3906 transistors, Vref is killed (as in taken down to about 300 mV) even when Vsense is at about 4.5 V. I can't see anything that would cause it. Of course my first thought is that something is wrong with the model, but I have a real hard time believing that the model for a ubiquitous transistor like this would be seriously off. I'll need to play with that some more.
 

WBahn

Joined Mar 31, 2012
29,978
One thought that came to mind about this circuit is that I don't know that it will start properly. If everything is at zero, then as the voltage comes up, there's no reason for the top transistors to conduct anything, which means that there's no reference at the bottom to get the bottom current source working to get the top current source working.

I'm thinking that a pilot resistor in parallel with Q5 might be sufficient to get things moving.
 

WBahn

Joined Mar 31, 2012
29,978
Yup. It didn't start when I ramped the voltage up from zero. I put a 1 MΩ pilot resistor across Q5 and that was all it took
 
I receive 120V DC from an inverter which, when it shuts down, starts to decrease until it reaches 0V. When it drops below 40V (Vref) I want an LED to light up.
I would like to realise the application using an LM393 comparator
Assuming it's a 120VDC supply as stated and you have an LM393 how about:
1664359660434.jpeg
A 10V Zener is fairly arbitary, higher would be fine, lower probably okay. R2 = R3 so the comparator sees a 5V voltage on the (+) input. R4 and R5 selected to produce 40 x R5/(R4 + R5) = 5 for the (-) input. I'm guessing the LED (maybe green) is to show when the output is safe to touch?

Presumably you have a red LED connected via a resistor to the supply via an LED, maybe 12K for 10mA to show the power is live? This will obviously just get dimmer as the voltage drops. Since the LM393 comes with 2 comparators how about using the other to invert the output of the first as an "on" LED (maybe red)?

I haven't quite got me head around what happens when the voltage drops below 15V - probably still functions correctly for a while, need to check that the negative input doesn't somehow go above the positive, but I don't think it does.
 

Thread Starter

andrew74

Joined Jul 25, 2022
102
I receive 120V DC from an inverter which, when it shuts down, starts to decrease until it reaches 0V. When it drops below 40V (Vref) I want an LED to light up.

I would like to realise the application using an LM393 comparator (I have this available) but I have some doubts:

1) On the datasheet of the LM393 I read that the maximum ratings of Input Differential Voltage and Input Common Mode Voltage Range are about 36V .. so I don't think it can directly give these voltages to the comparator. Am I wrong? Have I interpreted those parameters on the datasheet correctly?
If the answer is yes, what can I do? I need to reduce both Vin = 120V and Vref = 40V to something acceptable for the comparator input.

2) How do I create the Vref? Do I use a resistive divider on 120V? Or maybe a pair of Zener in series?

(P.S.: I only want to use Resistors, Capacitors, Diodes and the Comparator)

Thanks.

Update: 120V DC comes from a battery and 12V power supply.

Thank you all for your answers! @Jerry-Hat-Trick @WBahn @BobTPH

I have a lot of questions about different parts of the circuit, for example: the output of the comparator, the zener, the inverting input, etc., so slowly I would like to deal with one part at a time. I hope this is not a problem.


For now, let's try to find a ZENER with a 40V reverse voltage so we can create the Vref:

I connect the 120V directly on a resistor in series with the zener like @Jerry-Hat-Trick has done in his circuit.
The series resistor certainly limits the current that would circulate on that branch and I know that it must be sized so that the current flowing in the zener is higher than Iz(min) and lower than Iz(max).

I found the UZ5840 online, is it good? which zener do you recommend?
As soon as we have chosen the zener (let me know what you choose for this application), we size the series resistor
R = (120 - 40) / Iz right?

I enclose a picture of the datasheet of the zener I found (UZ5840) and ask you what current value I should take into account when calculating the resistance.

Immagine 2022-09-28 140222.png
Thanks again to everyone
 

WBahn

Joined Mar 31, 2012
29,978
Assuming it's a 120VDC supply as stated and you have an LM393 how about:
View attachment 277221
A 10V Zener is fairly arbitary, higher would be fine, lower probably okay. R2 = R3 so the comparator sees a 5V voltage on the (+) input. R4 and R5 selected to produce 40 x R5/(R4 + R5) = 5 for the (-) input. I'm guessing the LED (maybe green) is to show when the output is safe to touch?

Presumably you have a red LED connected via a resistor to the supply via an LED, maybe 12K for 10mA to show the power is live? This will obviously just get dimmer as the voltage drops. Since the LM393 comes with 2 comparators how about using the other to invert the output of the first as an "on" LED (maybe red)?

I haven't quite got me head around what happens when the voltage drops below 15V - probably still functions correctly for a while, need to check that the negative input doesn't somehow go above the positive, but I don't think it does.
Don't forget that the LM393 has open-collector outputs! So you need to sink the current from the LED when the voltage drops below the threshold and power the LED from the zener node.

The only other problem I see is the sizing of R1 and the capacitor.

Without the capacitor, R1 has to be small enough so that it can feed everything at whatever minimum supply voltage you want the circuit to still work at. Say this is the 15 V that you mentioned. That has 5 V across it at that point. Then at 120 V, it has 110 V across it, or 22x the voltage and 22x the current.

If the capacitor is large enough, then R1 can be made small enough so that it trickle charges the cap (though it still has to be small enough to feed everything at 120 VDC in steady state) and the cap is relied upon to power everything. But for how long is that? If the rate at which the supply voltage drops is known then that can be taken into account. But even drawing a few milliamps for a few seconds is going to require a pretty large cap.
 

MrAl

Joined Jun 17, 2014
11,389
I did some tweaking and got to this:
View attachment 277192

The data sheet for the 1N750 indicates that it really wants a lot more current than the ~1 mA I'm giving it, but this is the only 4.7 V zener model I have in LTSpice (I just have the basic install).

View attachment 277193

The current in the LED is set for ~1 mA. I have no idea what this particular LED would do, but there are LEDs out there for which this is a decent indicator current.

The total current of 3.5 mA at 120 V gives a power consumption of only 420 mW, which isn't bad.

One thing I don't understand is that when I change Q2 and Q6 to 2n3906 transistors, Vref is killed (as in taken down to about 300 mV) even when Vsense is at about 4.5 V. I can't see anything that would cause it. Of course my first thought is that something is wrong with the model, but I have a real hard time believing that the model for a ubiquitous transistor like this would be seriously off. I'll need to play with that some more.
Q2 ,Q6, different betas perhaps?
 

WBahn

Joined Mar 31, 2012
29,978
Update: 120V DC comes from a battery and 12V power supply.
So the 120 VDC comes from a battery, not an inverter?

If so, why would this voltage "shut down"? If it is coming from an inverter that is being powered by a battery (perhaps the same battery that you are referring to as your 12 V power supply?), then the question asked earlier is very relevant -- are you sure that the inverter output is 120 VDC and not 120 VAC, since the purpose of most inverters is to produce AC output and that seems particularly likely if the voltage happens to be 120 V.

Plus, you have a separate 12 VDC power supply available that is unrelated to the battery?

If so, things just got a whole lot simpler.

Power the LM393 from the 12 V supply, use a resistor/zener off the 12 V supply to set a reference voltage that is no more than 1/3 of 12 V, so perhaps 3.3 V, and connect this to the inverting input of the comparator. Then set up a voltage divider to the 120 V supply that produces the reference voltage at 40 V and connect this to the comparator's non-inverting input. The reason for the 1/3 of 12 V limit is so that the voltage out of the sensing divider doesn't exceed 12 V when the supply is at 120 V. Put the LED and current limiting resistor between the 12 V supply and the comparator output. Add a 0.1 uF capacitor between the comparator supply rails and you are pretty much done.

I have a lot of questions about different parts of the circuit, for example: the output of the comparator, the zener, the inverting input, etc., so slowly I would like to deal with one part at a time. I hope this is not a problem.

For now, let's try to find a ZENER with a 40V reverse voltage so we can create the Vref:
Remember that to get that 40 V reference, the supply but be above 40 V (by enough to feed the zener and whatever else is drawing current from that node). As soon as your supply voltage drops below that, your reference voltage is going to fall as well (the zener becomes essentially an open circuit).

What are you going to do with this 40 V reference? Don't apply it to one of your comparator's inputs.

I connect the 120V directly on a resistor in series with the zener like @Jerry-Hat-Trick has done in his circuit.
The series resistor certainly limits the current that would circulate on that branch and I know that it must be sized so that the current flowing in the zener is higher than Iz(min) and lower than Iz(max).

I found the UZ5840 online, is it good? which zener do you recommend?
It looks like that zener wants 30 mA to set the voltage correctly. I don't know how far below that you can go and still get a voltage acceptably close to 40 V. But let's use Iz(min) as 30 mA and Iz(max) as the 105 mA given in the table.

As soon as we have chosen the zener (let me know what you choose for this application), we size the series resistor
R = (120 - 40) / Iz right?
You need to pick a value of R that results in no more than Iz(max) at 120 V and no less than Iz(min) at whatever supply voltage you still want this thing to provide your reference voltage. Don't forget to take into account any other current, in addition to the zener current, is flowing through this resistor.


If the 120 V actually is 120 VAC coming out of an inverter, then it needs to be rectified to DC for this purpose. But do yourself a big favor and use a small signal transformer take it from 120 VAC down to something much safer and more manageable, such as 12 VAC or even 6 VAC.

Interfacing high voltage circuits with low voltage circuits in the manner that we all have been discussing here has risks that can quickly turn lethal and extra care must be taken when working with them.
 
Last edited:

WBahn

Joined Mar 31, 2012
29,978
Q2 ,Q6, different betas perhaps?
I don't think that accounts for it. It's killing Vref even with a base voltage high enough to put them firmly into cutoff.

Now it is working with the 2n3906. The circuit where it was failing with them (and working with the others) had different Vsense resistor values and I don't remember what they were. I should have made a note of them so that I could come back and explore things. I suspect that it might have been a power-up issue and the circuit wasn't starting, which might have been a simulation issue. But I think adding the pilot resistor should solve it.
 
Last edited:
Don't forget that the LM393 has open-collector outputs! So you need to sink the current from the LED when the voltage drops below the threshold and power the LED from the zener node.

The only other problem I see is the sizing of R1 and the capacitor.
Thanks, I did overlook the open collector outputs! I have a box full of LM358s so I use them whenever I need a comparator....

My thinking is that you only need to see the green "safe to touch" LED for a brief time, after which, unless you have a completely separate power supply, there is no power anyway so the LED will turn off. I picked a 10V zener although on reflection a lower value might be better as the LM358 is happy with a 3V supply and the LED will draw most of the current, maybe 15mA overall. Mainly, it's to make sure that the LED comes on for the time it takes the power supply voltage to drop from 40 to say 20V (with a 5.6V zener). Agreed, the capacitor needs to be large in value but physically quite small if it's a lower voltage one. It would indeed be useful to start with knowing how quickly the supply voltage drops, presumably when not connected to anything other than the circuit described - it should have a path via a resistor to ground so it does discharge.

A 2,200uF should drop about a volt in 0.1s at 20mA. If the LED is bright enough at 3mA so the circuit needs only 5mA maybe you can squeeze 0.5s out of it. For the 5mA to come from the supply without the capacitor at 20V - say 15V above the zener - R1 would need to be a 5W 3K ohm resistor. Not brilliant, but it satisfies the comparator, zener, resistors, capacitor only requirement!
 

Thread Starter

andrew74

Joined Jul 25, 2022
102
So the 120 VDC comes from a battery, not an inverter?

If so, why would this voltage "shut down"? If it is coming from an inverter that is being powered by a battery (perhaps the same battery that you are referring to as your 12 V power supply?), then the question asked earlier is very relevant -- are you sure that the inverter output is 120 VDC and not 120 VAC, since the purpose of most inverters is to produce AC output and that seems particularly likely if the voltage happens to be 120 V.

Plus, you have a separate 12 VDC power supply available that is unrelated to the battery?

If so, things just got a whole lot simpler.

Power the LM393 from the 12 V supply, use a resistor/zener off the 12 V supply to set a reference voltage that is no more than 1/3 of 12 V, so perhaps 3.3 V, and connect this to the inverting input of the comparator. Then set up a voltage divider to the 120 V supply that produces the reference voltage at 40 V and connect this to the comparator's non-inverting input. The reason for the 1/3 of 12 V limit is so that the voltage out of the sensing divider doesn't exceed 12 V when the supply is at 120 V. Put the LED and current limiting resistor between the 12 V supply and the comparator output. Add a 0.1 uF capacitor between the comparator supply rails and you are pretty much done.



Remember that to get that 40 V reference, the supply but be above 40 V (by enough to feed the zener and whatever else is drawing current from that node). As soon as your supply voltage drops below that, your reference voltage is going to fall as well (the zener becomes essentially an open circuit).

What are you going to do with this 40 V reference? Don't apply it to one of your comparator's inputs.



It looks like that zener wants 30 mA to set the voltage correctly. I don't know how far below that you can go and still get a voltage acceptably close to 40 V. But let's use Iz(min) as 30 mA and Iz(max) as the 105 mA given in the table.



You need to pick a value of R that results in no more than Iz(max) at 120 V and no less than Iz(min) at whatever supply voltage you still want this thing to provide your reference voltage. Don't forget to take into account any other current, in addition to the zener current, is flowing through this resistor.


If the 120 V actually is 120 VAC coming out of an inverter, then it needs to be rectified to DC for this purpose. But do yourself a big favor and use a small signal transformer take it from 120 VAC down to something much safer and more manageable, such as 12 VAC or even 6 VAC.

Interfacing high voltage circuits with low voltage circuits in the manner that we all have been discussing here has risks that can quickly turn lethal and extra care must be taken when working with them.
I have 120V input which drops (I don't know in how long .. ) to 0V .. and once it drops below 40V the LED turns on (before it was off). So the input is supposed to be a ramp from 120V down to 0V.

I cannot understand the functioning of your circuit (which I enclose) ..
I read your answer but it is not clear to me whether the Vref is produced by the 3.3V zener (connected to the 12V) or the 40V resistive divider (connected to the 120V input) ..

Immagine 2022-09-28 173113.png

(the numerical values may not be correct, but first let us think about the functioning)

I would like to simulate it but I cannot change the parameters of the zener diode... I will try shortly to download a 3.3V one from the internet and import the spice model
 
Power the LM393 from the 12 V supply, use a resistor/zener off the 12 V supply to set a reference voltage that is no more than 1/3 of 12 V, so perhaps 3.3 V, and connect this to the inverting input of the comparator. Then set up a voltage divider to the 120 V supply that produces the reference voltage at 40 V and connect this to the comparator's non-inverting input. The reason for the 1/3 of 12 V limit is so that the voltage out of the sensing divider doesn't exceed 12 V when the supply is at 120 V. Put the LED and current limiting resistor between the 12 V supply and the comparator output. Add a 0.1 uF capacitor between the comparator supply rails and you are pretty much done.
Ouch, I hadn't noticed there is a 12V supply available :)WBahn's explanation is very helpful. The comparator gets a reference voltage of 3.3V. The potential divider providing the (+) comparator input needs an output (where you've written 40V) of 3.3V or less to switch the comparator and turn the LED on. So when the output of the supply falls to 40V the voltage where your R3 meets R1 has to be 3.3V. So 40 x R1/(R1 + R3) = 3.3. But it's important that when the supply voltage is 120V which is three times 40V the input does not exceed the positive rail of the comparator. That is why the zener has to be less than 4V. With a 3.3V the maximum will be 9.9V

Maybe try R3 = 56K, R1 = 5K

Personally, I'm not a fan of spice. I've interviewed engineering graduates who use it without having a clue how to work out component values. If I was teaching, I'd ban it. I prefer Ohms Law which I can remember.
 

WBahn

Joined Mar 31, 2012
29,978
I have 120V input which drops (I don't know in how long .. ) to 0V .. and once it drops below 40V the LED turns on (before it was off). So the input is supposed to be a ramp from 120V down to 0V.
What I and others have been trying to get at is whether that 120 V is really, truly, 120 V DC or whether, as is likely if it is the output of an inverter, it is 120 V AC.

PLEASE confirm which it is. This makes a HUGE and FUNDAMENTAL difference in how this problem is tackled.

I cannot understand the functioning of your circuit (which I enclose) ..
I read your answer but it is not clear to me whether the Vref is produced by the 3.3V zener (connected to the 12V) or the 40V resistive divider (connected to the 120V input) ..

View attachment 277259

(the numerical values may not be correct, but first let us think about the functioning)

I would like to simulate it but I cannot change the parameters of the zener diode... I will try shortly to download a 3.3V one from the internet and import the spice model
You are close, but once again you are trying to apply 40 V to the input of the LM393, which is not only well above the 36 V absolute maximum rating for the part, but astronomically above the recommended operating maximum of 1.5 V below the positive supply rail, which is a mere 10.5 V. You are almost certainly going to destroy this part.

The goal is to divide the supply voltage down so that, when the supply voltage is 40 V (not when it is 120 V, but when it is at the point where you want to turn on the LED), the output of the divider matches the 3.3 V reference. This requires a divider whose gain is 3.3 V / 40 V = 0.0825, which in turn requires the top resistor to be about 11 times as large as the bottom resistor. So something like 10 kΩ on the bottom and 110 kΩ on the top. This divider also ensures that when the supply voltage is at it's full 120 V level, that the voltage at the output is only about 9.9 V, so below the 10.5 V recommended max (albeit not by a lot).
 
Last edited:

WBahn

Joined Mar 31, 2012
29,978
Personally, I'm not a fan of spice. I've interviewed engineering graduates who use it without having a clue how to work out component values. If I was teaching, I'd ban it. I prefer Ohms Law which I can remember.
This is a topic for a different thread, but having said that, I sympathize with your position, though I don't totally agree with it.

I see the same problem with labs that have fancy scopes -- many students just want to press the Auto Set button and then accept whatever results, no matter how absurd it is. The same thing happens with programming and using sophisticated IDEs that do things like code completion and, even more so, when students learn programming using languages that do most of the heavy lifting for you, whether it be garbage collection or iteration through a list, or very powerful libraries.

The problem isn't the use of tools, it's teaching the proper use of tools.

Tools shouldn't replace thinking, and that's what is happening so often. Students immediately start out throwing symbols at a simulator schematic and then start making almost random changes hoping that, at some point, something miraculous happens (what one prof I had referred to as "design by happening".

A proper approach (IMHO) is to first teach the basics without tools. Then integrate the tools, but require they be used to verify designs, not craft the designs.
 
Top