Maker Pro
Maker Pro

LM339/LM339N can't get output high

MScMech

Aug 4, 2009
4
Joined
Aug 4, 2009
Messages
4
Hi,

I am starting out a project and I don't have a lot of experience in this. I want to compare voltages with LM339N in this project. The circuit is wired as in attached photo. The input is at 3.3V (red, yellow) and the wire between the variable resistors is set to 1.6V (blue). With 3.3V on pin 5 and 1.6V on pin 4 I expected to get an output on pin 2 (since 3.3>1.6), but there is nothing. Also tried switching the yellow and blue wires to switch the comparison, but with same result.

I have checked that there is correct voltage on all inputs and there is about 4 ohms to ground. The capacitor is 0,1 microF.

What am I doing wrong?
 

Attachments

  • Lm339n my setup 2.jpg
    Lm339n my setup 2.jpg
    100.5 KB · Views: 17
  • Lm339 pins.jpg
    Lm339 pins.jpg
    41.7 KB · Views: 14

Audioguru

Sep 24, 2016
3,656
Joined
Sep 24, 2016
Messages
3,656
The photo of wires all over the place in a breadboard is not a schematic.
The datasheet of the LM339 and LM393 comparators show that the outputs ore NPN transistors with open connectors for you to attach together and/or with a load to the positive supply.
You should always look at the datasheet.
 

Attachments

  • comparator.png
    comparator.png
    28.8 KB · Views: 6

AnalogKid

Jun 10, 2015
2,884
Joined
Jun 10, 2015
Messages
2,884
Please post a real schematic for your circuit. Be sure to use a symbol for each comparator, not a box with a bunch of lines. Also, include reference designators so we can discuss the components individually.

ak
 

Bluejets

Oct 5, 2014
6,901
Joined
Oct 5, 2014
Messages
6,901
Hi,

I am starting out a project and I don't have a lot of experience in this. I want to compare voltages with LM339N in this project. The circuit is wired as in attached photo. The input is at 3.3V (red, yellow) and the wire between the variable resistors is set to 1.6V (blue). With 3.3V on pin 5 and 1.6V on pin 4 I expected to get an output on pin 2 (since 3.3>1.6), but there is nothing. Also tried switching the yellow and blue wires to switch the comparison, but with same result.

I have checked that there is correct voltage on all inputs and there is about 4 ohms to ground. The capacitor is 0,1 microF.

What am I doing wrong?

As pointed out, the output will be open collector....so turn your LED around and place the anode of the LED to the positive supply and the cathode to the resistor.

Do not see why the unused inputs and outputs are at ground, just leave them.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
Do not see why the unused inputs and outputs are at ground, just leave them.
I beg to disagree: floating inputs are not a good option. This will work with bipolar inputs, but there is always a chance that some stray EMC noise couples into a floating input. Even if the circuit connected to this input is unused, that stray coupled EMC can cause unexpected effects, worst case would be a latch-up of the chip.
The effect becomes worse with MOS (CMOS) inputs. Better get used to not leaving any inputs open (unless they are internally pulled up or down, of course).
Connecting unused inputs to a defined potential is imho always good practice.
 

AnalogKid

Jun 10, 2015
2,884
Joined
Jun 10, 2015
Messages
2,884
Yeah, I was gonna mention that. In this particular circuit, shorting unused outputs to GND will not harm anything because they are open-collector. But as generic advice it is *terrible*.

And, in this particular case shorting the inputs to the negative rail is not a problem because these inputs are designed for that. But again, as generic advice it is bad. For most opamps and many comparators, the input common mode range does *not* include the negative rail, so tying any inputs there is not recommended.

ak
 

Bluejets

Oct 5, 2014
6,901
Joined
Oct 5, 2014
Messages
6,901
This was taken from the LM339 data sheet.......

5.1.1 Do Not Connect Inputs Directly to Ground For both used and unused comparators, the inputs must not be connected directly to ground or any other low impedance node. Always add some resistance to limit the current to less than 10 mA, regardless of any possible fault condition. All the input pins have a diode from the input to the device’s GND, or V–, pin. In dual supply applications, the GND pin will be negative. However, during power up, power down, or supply faults, the GND pin may become positive. If this occurs then a grounded input pin will have potentially damaging current flow due to the input diode. Even if the GND pin is also grounded, such as in single supply applications, there is a possibility that the input ground will be negative relative to the op amp’s internal ground node. Ground differences occur when there is poor layout or high current transients, ∆I/∆t. Adding 1-kΩ to 10-kΩ series resistors to the input pin is acceptable in most applications
 

Martaine2005

May 12, 2015
4,932
Joined
May 12, 2015
Messages
4,932
The data sheet says “don’t connect directly to ground”. “Add resistance “.
Hence pull up/down resistors.

Martin
 

MScMech

Aug 4, 2009
4
Joined
Aug 4, 2009
Messages
4
As pointed out, the output will be open collector....so turn your LED around and place the anode of the LED to the positive supply and the cathode to the resistor.

Do not see why the unused inputs and outputs are at ground, just leave them.

Thanks for checking my photo. I got it to work straight away by doing that. I understand now that the output is a collector, I thought an "output" was defined as binary, either positive or 0 voltage. Or maybe that is still correct... that it is always high and then 0 when the signal is on? I intended to use that to connect to an Arduino (I am yet quite unfamiliar with that too). But if I connect this output collector to an input on e.g. Arudino, then does it mean it will be pulled low when the led lights up?

Thanks, Adam
 

Bluejets

Oct 5, 2014
6,901
Joined
Oct 5, 2014
Messages
6,901
Thanks for checking my photo. I got it to work straight away by doing that. I understand now that the output is a collector, I thought an "output" was defined as binary, either positive or 0 voltage. Or maybe that is still correct... that it is always high and then 0 when the signal is on? I intended to use that to connect to an Arduino (I am yet quite unfamiliar with that too). But if I connect this output collector to an input on e.g. Arudino, then does it mean it will be pulled low when the led lights up?

Thanks, Adam

It depends on how you have your inputs as to what happens when one input or the other goes to a higher level. The output still works the same but the LED will be on either when the "+" is higher or the "-" is higher level.
You will notice one is marked "-" and the other "+".
If the "+" input goes higher than the "-" input, the output is turned on, (1), which pulls the open collector to ground and give a low out.
If this is wrong for you, simply swap the two inputs over.

Connecting to an Arduino, you would normally use internal pullup resistor in your sketch e.g. pinMode (10,INPUT_PULLUP);
This will pull the pin to ground when the "+" goes higher than the "-".
One then writes the sketch to match or , if this does not suit for some reason, use an inverting transistor or small mosfet (2N7000) easier.

If your load is connected as you have now, ie where the LM339 is "sinking" your load, a higher "+" will connect the LED to ground and obviously it turns on.

And yes, if the cathode of the LED is then connected to an input pin (as is........no internal pullup resistor required as the pullup is already there in the form of you LED and it's current limit resistor) then the signal to the Arduino will be low and the LED on.
 

Attachments

  • LM339.jpg
    LM339.jpg
    9.2 KB · Views: 5
Last edited:

Audioguru

Sep 24, 2016
3,656
Joined
Sep 24, 2016
Messages
3,656
If the "+" input goes higher than the "-" input, the output is turned on, (1), which pulls the open collector to ground and give a low out.

This will pull the pin to ground when the "+" goes higher than the "-".

If your load is connected as you have now, ie where the LM339 is "sinking" your load, a higher "+" will connect the LED to ground and obviously it turns on.

And yes, if the cathode of the LED is then connected to an input pin (as is........no internal pullup resistor required as the pullup is already there in the form of you LED and it's current limit resistor) then the signal to the Arduino will be low and the LED on.
Sorry to say you are wrong, you say the logic backwards that is very confusing to new people.
The datasheet shows that it is the same as an opamp that has an output pullup resistor: When the + input has a higher voltage than the - input then the output goes high. It inverts and the output goes low when the - input voltage is higher than the + input.

Also it is wrong for you to say that the LED and its pullup resistor can make a logic high output because the output "high" voltage will be minus the LED voltage that might have a 3.6V white or blue LED and a 5V supply. Then the output "high" logic voltage will be only +1.4V which is a Cmos logic low. Another separate pullup resistor is needed to make the output produce a valid logic high.
 

Bluejets

Oct 5, 2014
6,901
Joined
Oct 5, 2014
Messages
6,901
there is no pullup on an lm339...it is open collector so I suggest you do some reading
 

Audioguru

Sep 24, 2016
3,656
Joined
Sep 24, 2016
Messages
3,656
there is no pullup on an lm339...it is open collector so I suggest you do some reading
That is why I and everybody else said it needs an output pullup resistor added.
An LM339 has 4 comparators. An LM393 has only 2 of the same comparators.
 

Audioguru

Sep 24, 2016
3,656
Joined
Sep 24, 2016
Messages
3,656
The datasheet for an LM339 comparator does not say if the output has the same polarity as the + input.
The schematic of the same oscillator in both datasheets shows that their output polarities are the same.
 

Attachments

  • comparator and opamp.png
    comparator and opamp.png
    39.6 KB · Views: 2
Top