comparator question

Thread Starter

count_volta

Joined Feb 4, 2009
435
Hi, I am building a circuit in which the output of an LM 339 comparator activates the coil of a 5V relay to close the switch. I tested the comparator and it works perfectly by itself. So does the relay, by itself.

In the schematic below you can see that in this state the comparator outputs 5V. The problem is, when I connect the comparator output to the coil of the relay the voltage at the output of the comparator drops from 5V to 0.555V. I would like to know why this is and how can I fix it?



I am thinking it might be because the output resistance of the LM 339 is much higher than the input resistance of the relay coil, and thus a voltage divider is created where most of the voltage is dropped across the comparator and 0.555V is dropped across the relay coil. Am I right?

If so, I could probably use either an emitter follower buffer or an op amp voltage follower to raise the input resistance of the relay.
 
Last edited:

Wendy

Joined Mar 24, 2008
23,429
Given that a LM339 output does not have a Vcc connection, and is strictly open collector (emitter is to ground) I really don't see how this schematic can possibly work. If the coil was going to Vcc it would have a chance, since the two states of a LM339 or LM393 are conduction to ground or open. The norm for this component(s) is to have a 10KΩ pullup resistor to Vcc, max current is somewhere around 16ma.

Lack of a snubbing diode is serious, as the same risk of damage from inductive spikes is the same as always.
 

Thread Starter

count_volta

Joined Feb 4, 2009
435
Yea I'm still confused what the heck open collector output even means. In the experiment we used the 339 for, they told us, add the pullup resistor on the output.

And sorry I forgot to draw it, but when I built the actual circuit I had a 1k pullup resistor going from 5V to the output. I have fixed the schematic I drew now.



So that can't be the reason why it can't drive the relay right, if I have the pullup resistor there.

I can probably add a mosfet switch and have the comparator turn that on, and have the mosfet drive the relay, but I would like to know why the comparator itself can't drive the relay.
 
Last edited:

billnow

Joined Aug 4, 2010
23
The open collector output of the comparator is only capable of sinking current into ground. The 1K resistor limits to current drawn by the relay coil and may not be enough to energize the relay.

A 1k to 10 K resistor is adequate to achieve 0 volt and 5 volt output levels assuming that no additional load (such as the relay) is present.

One approach is to connect the relay coil in series between the comparator output and the +5V supply. When the comparator is off, meaning the open collector output is off, no current will flow. When the comparator output is on, one side of the relay will be at +5V and the other side will be connected to ground through the comparator, which will then activate the relay.

Adding a suppression diode is recommended to protect the comparator. The diode is wired across the relay coil with the cathode goes to the dise of the coil with the higher voltage. In addition, the above assumes the relay coil is specified to activate with 5 Volts.
 

Thread Starter

count_volta

Joined Feb 4, 2009
435
The open collector output of the comparator is only capable of sinking current into ground. The 1K resistor limits to current drawn by the relay coil and may not be enough to energize the relay.

A 1k to 10 K resistor is adequate to achieve 0 volt and 5 volt output levels assuming that no additional load (such as the relay) is present.

One approach is to connect the relay coil in series between the comparator output and the +5V supply. When the comparator is off, meaning the open collector output is off, no current will flow. When the comparator output is on, one side of the relay will be at +5V and the other side will be connected to ground through the comparator, which will then activate the relay.

Adding a suppression diode is recommended to protect the comparator. The diode is wired across the relay coil with the cathode goes to the dise of the coil with the higher voltage. In addition, the above assumes the relay coil is specified to activate with 5 Volts.
For your first post its an excellent one. Welcome to the forum. :)

So when the comparator is on, its output is connected to ground, and when its off its like an open switch?

That is very weird. Not sure why anybody would do something like this. I guess its the inside of the comparator which is pretty complicated I know.

What does the suppression diode do? How does it protect the comparator?
 

billnow

Joined Aug 4, 2010
23
For your first post its an excellent one. Welcome to the forum. :)
Thanks!

So when the comparator is on, its output is connected to ground, and when its off its like an open switch?
Yes.

That is very weird. Not sure why anybody would do something like this. I guess its the inside of the comparator which is pretty complicated I know.
The output of the comparator is a simple NPN transistor. The emitter is connected to ground, the base is driven by the "result" of the comparison, and the collector is brought out to a pin of the device. One advantage of open collector is that you can "wire OR' the outputs of multiple comparators together. Another is that you can sink current from a load that is independent of the supply voltage of the comparator.

What does the suppression diode do? How does it protect the comparator?
The suppression diode snubs inductive kickback when the relay coil becomes de-energized. Without the diode a large voltage could develop which may damage the output transistor of the comparator.
 

Thread Starter

count_volta

Joined Feb 4, 2009
435
Ah I understand. So the rest of the comparator is just a differential op amp?

Vout = (V+ minus V-) * large gain

The suppresion diode can be any diode right. 0.7V voltage drop?

I will go and try to build this and report on the results.
 
Aside from the lm339 being an open collector, you can do put a buffer this is to avoid overloading in LM339. I used to have this kind of circuit before but a bit different, I used AD790 and put omron g6h-5 relay. Well same problem I encountered until I used a buffer then it works fine.
 

Wendy

Joined Mar 24, 2008
23,429
You have to either use a large transistor or a chip with more current. The LM339/LM393 is not meant to drive a lot of current, any more than a TTL chip is. In many ways there are resemblances, TTL has a lot of open collector chips too.
 

billnow

Joined Aug 4, 2010
23
You have to either use a large transistor or a chip with more current. The LM339/LM393 is not meant to drive a lot of current, any more than a TTL chip is. In many ways there are resemblances, TTL has a lot of open collector chips too.
The LM339 is spec'd to typically sink 16 mA; it may be able to drive the relay coil directly IF the relay coil draws less than 16 mA DC. Measure or look at the relay data sheet to determine the DC coil current required to close the relay.
 

Audioguru

Joined Dec 20, 2007
11,248
With the 1k resistor in series with the relay coil from 5V, the coil's voltage was only 0.555V. Then it draws 40mA from 5V. But the minimum output current (to ground) of an LM339 comparator is only 6mA. The LM339 is not powerful enough to activate your relay.
 

billnow

Joined Aug 4, 2010
23
The 1K resistor and the coil act as a voltage divider across the 5 volts. Knowing the voltage at the junction of the resistor and the relay coil allows one to calculate the DC resistance of the coil. 5.0*(R/(R+1000))=0.55 where R is the coils resistance Solving for R gives us a coil resistance of 123.59 ohms Since the voltage drop across the coil is 0.55 volt the coil current is therefore 0.55/123.59 = 4.45 mA. This does NOT mean that 4.45 mA is sufficient to close the relay contacts. The important fact is that we don't know how much current is actually required by the relay coil to actuate the relay. For all we know, the relay may require 200 mA which can't be supplied by the 5 volt supply, no matter how it is wired.
 

Audioguru

Joined Dec 20, 2007
11,248
The LM339 is spec'd to typically sink 16 mA; it may be able to drive the relay coil directly IF the relay coil draws less than 16 mA DC. Measure or look at the relay data sheet to determine the DC coil current required to close the relay.
You cannot buy a "typical" comparator IC anywhere.
Maybe yesterday the yeild was all minimum output current or maybe a big manufacturer bought all the more powerful ones.

The supply is 5V.
The relay coil has 1k resistor in series and it has 0.555V across it.
So the current is (5.0V -0.555V)/1k ohms= 4.45mA.
The relay coil resistance is 0.555V/4.45mA= 124.7 ohms.
Then at 5V the coil draws 5V/124.7 ohms= 40.0mA.
You can't drive a 40mA relay with a wimpy LM339 comparator.
But 5mA relays are available and work fine. (Been there, done that).
 

Thread Starter

count_volta

Joined Feb 4, 2009
435
You have to either use a large transistor or a chip with more current. The LM339/LM393 is not meant to drive a lot of current, any more than a TTL chip is. In many ways there are resemblances, TTL has a lot of open collector chips too.
I don't quite understand what is it inside those chips that dictates how much current can be drawn from them?

Lets take a battery. If the battery is 5V and it was ideal, in theory 5amps can be drawn from it with a 1Ω resistor. The battery is not ideal though and has a power rating before it is destroyed. So when you guys say the 339 can't drive X amps, that means its because of the power rating also, and if it is made to drive so many amps it will overheat and be destroyed?

Or is it something else entirely? Please feel free to explain with Thevenin equivalents and other circuit laws. Remember I'm still a student.
 
I don't quite understand what is it inside those chips that dictates how much current can be drawn from them?
Here is what is inside of them:

Look on page two of this data sheet.

The output stage is a BJT with the base driven by 100 microAmps. With this output stage, the device is not able to sink much current, because the transistor is limited to passing the base current X the gain factor.

To do what you want, I would do it like this...

* pull up the output of the comparator with a 10K or 50K resistor. (A 1K uses too much power when the comparator output is conducting, and it's not necessary.)

* put that output into the gate of an N-channel logic-level MOSFET that is suitable for whatever current you need for the coil of the relay.

* add a snubber diode to collect the kickback from the coil, as Bill Marsden suggested (unless it is built into the relay as sometimes it is).

* connect the low side of the relay coil to the drain of the MOSFET and the source to the ground.

Or, if you want to switch the relay by the high-side then you can use a P-channel FET and reverse the inputs into the comparator.

Either way, you could also add a 100K resistor in the path to the gate of the MOSFET, to slow the switching. It would help to control any flyback, too. Flyback occurs when the coil is switched off quickly, as the coil is an inductor that will react to the change in current flow.
 

Thread Starter

count_volta

Joined Feb 4, 2009
435
Here is what is inside of them:

Look on page two of this data sheet.

The output stage is a BJT with the base driven by 100 microAmps. With this output stage, the device is not able to sink much current, because the transistor is limited to passing the base current X the gain factor.

To do what you want, I would do it like this...

* pull up the output of the comparator with a 10K or 50K resistor. (A 1K uses too much power when the comparator output is conducting, and it's not necessary.)

* put that output into the gate of an N-channel logic-level MOSFET that is suitable for whatever current you need for the coil of the relay.

* add a snubber diode to collect the kickback from the coil, as Bill Marsden suggested (unless it is built into the relay as sometimes it is).

* connect the low side of the relay coil to the drain of the MOSFET and the source to the ground.

Or, if you want to switch the relay by the high-side then you can use a P-channel FET and reverse the inputs into the comparator.

Either way, you could also add a 100K resistor in the path to the gate of the MOSFET, to slow the switching. It would help to control any flyback, too. Flyback occurs when the coil is switched off quickly, as the coil is an inductor that will react to the change in current flow.
Ok I understand. So the current through the base of the output NPN BJT is always 100 uA. Then lets say the gain of the transistor β = 200 for example (a typical value). Then the max collector current can be:

β = ic/ib
200 = ic/ 100uA
ic = 20mA

I can't seem to find the max output current on the data sheet for the LM339. It says the sink current, but I'm not sure how to read that. http://www.national.com/ds/LM/LM139.pdf

Here is how I want to use the comparator:

My power supply to the 339 is 5V. The voltage at the + terminal will be about 2-3volts. The voltage at the - terminal will be 5V or 0V.



Also again, here is the data sheet for the relay I'm using

http://www.helishun.com/hls-4078.html

Not exactly sure where it says what the minimum current to close the switch is. I can see the minimum voltage though.
My relay is rated 5V DC.

I am having trouble understanding how to read the part of the data sheet that says: COIL DATA: (@20 ℃ )
 
Last edited:

billnow

Joined Aug 4, 2010
23
Ok I understand. So the current through the base of the output NPN BJT is always 100 uA. Then lets say the gain of the transistor β = 200 for example (a typical value). Then the max collector current can be:

β = ic/ib
200 = ic/ 100uA
ic = 20mA

I can't seem to find the max output current on the data sheet for the LM339. It says the sink current, but I'm not sure how to read that. http://www.national.com/ds/LM/LM139.pdf

Here is how I want to use the comparator:

My power supply to the 339 is 5V. The voltage at the + terminal will be about 2-3volts. The voltage at the - terminal will be 5V or 0V.



Also again, here is the data sheet for the relay I'm using

http://www.helishun.com/hls-4078.html

Not exactly sure where it says what the minimum current to close the switch is. I can see the minimum voltage though.
My relay is rated 5V DC.

I am having trouble understanding how to read the part of the data sheet that says: COIL DATA: (@20 ℃ )
The LM139 data sheet guarantees that the part will sink (as in switch to ground) at least 6 mA from its output into ground. The typical number is the performance that you can "usually" get from the part, but is not guaranteed and is not something that you can rely upon.


The relay spec sheet is, IMHO, pretty poor. As near as I can tell, they do not specify the minimum current needed to activate the relay. If you know the the coil resistance and the voltage that activates the relay then you could calculate the minimum current; the data sheet is less than clear in this respect.
 
Top