Comparator circuit help

I am using LM339 quad comparator to compare two signals but it is not giving its output as it is suppose to be.

i am using voltage divider circuit to out 6v on + terminal of comparator and 3v to the - terminal of the comparator.

as it can be seen in the diagram too but instead of variable resistor i am using a fixed voltage out by voltage divider circuit.

what wrong am i doing which is not helping me achieve what i want to which is the comparator output to be high when + terminal voltage is higher then the - terminal.

The input voltages must be between 0V and 4.5V if the chip is powered with 6V. The input range goes from
the negative supply rail to 1.5V less than the positive supply rail.

It is not a rail-to-rail device.

I believe because your LEDs are in sinking mode,they need to be sourced from the comparator to work that way

MarkT:
The input voltages must be between 0V and 4.5V if the chip is powered with 6V. The input range goes from
the negative supply rail to 1.5V less than the positive supply rail.

It is not a rail-to-rail device.

This is the circuit, i am using 48V on the input but then using voltage divider too,
ignore the other blank resistors as i have to make 2 other circuits to compare too, but as you can see comparator is not showing anything

bastjan:
I believe because your LEDs are in sinking mode,they need to be sourced from the comparator to work that way

Completely incorrect. The LM339 cannot source any current at all. It also cannot sink much current without a volt or so of headroom, so the green LED might not light very bright.

Mark248:

This is the circuit, i am using 48V on the input but then using voltage divider too,
ignore the other blank resistors as i have to make 2 other circuits to compare too, but as you can see comparator is not showing anything

They make sure the output of the divider is at least 1.5V below the LM339 supply voltage at all times.

You have forgotten the pull-up resistor to 5V on the output.

MarkT:
They make sure the output of the divider is at least 1.5V below the LM339 supply voltage at all times.

You have forgotten the pull-up resistor to 5V on the output.

a pull-up is a must for every output ?
what do you mean by the output of the divider is below 1.5v?

Mark248:
a pull-up is a must for every output ?

If you use that output as an input for another device, yes. Not for your LEDs.

what do you mean by the output of the divider is below 1.5v?

Do read the rest of the sentence as well. Especially the "the LM339 supply voltage" part.

wvmarle:
If you use that output as an input for another device, yes. Not for your LEDs.

does that mean that it can essentially only output ground? and if you want it to provide HIGH voltage 5v etc then you always have to provide it with pull up resistor?

Mark248:
does that mean that it can essentially only output ground? and if you want it to provide HIGH voltage 5v etc then you always have to provide it with pull up resistor?

The output stage of the LM339 is an open collector transistor so it can only sink current, not source. Any situation where you need voltage to drive an input, based upon the output from the LM339, you must fit a pull-up resistor to provide the voltage.

Ten seconds reviewing the LM339 datasheet very clearly shows this fundamental information about the part.

Nearly all comparators are like this, it means the comparator can be powered at 30V and yet talk to 5V or 3.3V logic without any problem. Comparators are always interfacing between analog and digital so this is the commonest use-case.

Ten seconds reviewing the LM339 datasheet very clearly shows this fundamental information about the part.

It's amazing how many people can't spare 10 seconds....

Based on your questions it appears you do not realize that your leds would only light if the Comparator
output was zero volts (NOT 5V) , which brings us to Marks comment that it cannot sink very much current.
It would be better to use a pullup resistor to get a 5V output to drive a transistor or mosfet.
LM139 SCHEMATIC
Also, it is not clear whether or not you understand how a comparator works.
Please post an simple explanation of the operation of a comparator so we can find out if your on the same
page:

Op Amp Equivilent: Vout=AOL*[(V+)−(V−)]

Fill in the blanks

if V+>V− then Vout=___

if V−>V+ then Vout=___

Also, your schematic is hard to follow .
Can you just post the V+ and V- input values for all four comparators and name the comparators after
their respective led color ?

ie:
Fill in the blanks:

RED

V+ = ______Vdc
V- = ______Vdc

YELLOW

V+ = ______Vdc
V- = ______Vdc

GREEN

V+ = ______Vdc
V- = ______Vdc

ORANGE

V+ = ______Vdc
V- = ______Vdc

Here's an example of how to use a comparator to drive a led:
lm358_comparatorth.png

lm358_comparatorth.png

raschemmel:
Here's an example of how to use a comparator to drive a led:
lm358_comparatorth.png

Won't work as a comparator can only sink current, it's an open collector output. Turn around the LED, connect the resistor to +12V instead of GND, and it'll light up when Vin < Vref. At 12V you may also need a larger resistor, by the way.

Sorry, I didn't notice it was an op amp so it doesn't apply to the OP's case since he is using an LM339 open-collector op amp (as indicated in the LM139 schematic link)

Good catch.

My bad.

OpAmp and comparator are different things - you can use an OpAmp as comparator (for slow signals - experience taught me a 1 MHz OpAmp as comparator may just be able to handle a 10 kHz signal) but not the other way around.

wvmarle:
Won't work as a comparator can only sink current, it's an open collector output. Turn around the LED, connect the resistor to +12V instead of GND, and it'll light up when Vin < Vref. At 12V you may also need a larger resistor, by the way.

Is not open collector.

LM358

The Slew Rate of the Linear LT1215 is 50V/uS. (compared to the LM741 with a slew rate of 0.5V/uS)
which is 100 times faster than the LM741 , so your guide of 10khz becomes 1 Mhz.

The schematic I posted by mistake used a LM358 which, like the LM741 has an SR of 0.5V/uS but
the GPB is 1.5 Mhz.

The LT1215 Gain Bandwidth Product is 23Mhz.

So, yeah , I would have agreed with you back in the day but today, I would say the LT1215 will work
just fine in most comparator applications. (but it was still a mistake to post an op amp circuit in a
post about comparators...)

Half year or so ago I tried to shore up a 0.8-1 MHz signal, to turn it into a block wave making it easier for the Arduino to count the frequency.

The 1 MHz MCP6002 didn't do it. Nor did the 10 MHz MCP6022. At the time I was told this has to do with saturation of the output stage of the OpAmp making it slow to recover.

A 74HC04 had no problem at all with this speed, giving me a great block wave. A basic comparator would have worked as well.

A 74HC04 had no problem at all with this speed

And the price was right....

wvmarle:
Half year or so ago I tried to shore up a 0.8-1 MHz signal, to turn it into a block wave making it easier for the Arduino to count the frequency.

The 1 MHz MCP6002 didn't do it. Nor did the 10 MHz MCP6022. At the time I was told this has to do with saturation of the output stage of the OpAmp making it slow to recover.

The MCP6002 has a full-swing bandwidth of 30kHz, the MCP6022 has a full-swing bandwidth of 400kHz or so,
the small-signal gain-bandwidth product is irrelevant here, neither device can drive a 1MHz full-swing signal at all.

You typically want 100 to 1000 times more bandwidth than your signal when using an opamp if only to keep distortion from being horrendous. Audio opamps typically have 30MHz or more bandwidth, and 200kHz or more of full-swing bandwidth.

Using an opamp as a comparator is fraught with problems, usually causes grief, and some opamps will just fry if you try it as the inputs are strapped with anti-parallel diodes.

A 74HC04 had no problem at all with this speed, giving me a great block wave. A basic comparator would have worked as well.

74HC family has rise/fall times measured in nanoseconds, ie a full-swing bandwidth up near 50 -- 100MHz