Water Level Comparator

Thread Starter

ac_dc_1

Joined Jan 27, 2013
74
Thank you. Was that so hard?
To be strict, this wasn't exactly what we asked you. Also, the blue line at some point is both below 30cm and 90cm which doesn't make much sense but we get your point.
The transfer function we wanted you to plot, was the following:
View attachment 51574
See how different this transfer function is compared to the one from the hysteretic comparator?

I 'd like to make sure you understand why a comparator with hysteresis wouldn't be suitable for your problem. If you don't please ask for clarification.

Now, about the dual comparators.
Yes, this is a good choice, especially with the LM339 OpAmps; Since they are open collector type (which means that they only sink current, they can't source any), they can't short circuit their outputs, in case they want to show a different result.

You will need to tweak the circuit you posted, though. Remember, a comparator, will go to Voh when V+>V- and to Vol when V+<V-. Based on that, in which pins do you think that you should connect the limit reference voltages and in which the sensor output?

You should also consider your output specifications. You mentioned Vol=4V and Voh=10V. Where did you get those numbers from? These should reflect some requirements for your load (buzzer, light etc). You should also justify this choice.

Finally, the LM339 needs to operate with a large resistor from Vcc to its output (thousands of ohms). This will constrain its drive capabilities. Consequently, you will need another driver stage after the comparators, which will depend on the load.
Remember, a comparator, will go to Voh when V+>V- and to Vol when V+<V-. Based on that, in which pins do you think that you should connect the limit reference voltages and in which the sensor output?
Vol =4 V aND Voh=9V,you say above the output will go to Voh and Vol when V+>V- and V+<V-..These Vol and Voh were not the reference voltages?I thougth the output of the comparator would go to +VCC if the input tensions were >Voh and <Vol...

I would conect Vol to pin 4 Voh to pin 7 and output to pin..I mentioned that on the circuit

You should also consider your output specifications. You mentioned Vol=4V and Voh=10V. Where did you get those numbers from? These should reflect some requirements for your load (buzzer, light etc). You should also justify this choice.
No i mentioned Vol=3V and Voh=9V.I got these numbers through the function that gives output tension of sensor in order of the water level..

Consequently, you will need another driver stage after the comparators, which will depend on the load.
I already knew that.The driver could be somehting like this
 

Attachments

Georacer

Joined Nov 25, 2009
5,182
Vol means Voltage output low and
Voh means Voltage output high.

They are bot quantities that refer to your comparator stage output. They have nothing to do with the water level sensor voltage output or the comparator inputs.

The comparator inputs and voltage thresholds should be referred to as Vil/Vih (Voltage input) or Vtl/Vth (Voltage threshold).

Did you draw the window comparator circuit yourself? If so, I will assume that the voltage source refers to the water level sensor. I will refer to that signal voltage source as Vs.
Your Vih is 10V and Vil is 4V as you specified in post#1.

If Vs=3V (level<30cm) then for the upper comparator you have V+>V- and it outputs Voh. For the lower comparator you have V+<V- and it outputs Vol. The total output of your circuit is Vol.

If Vs=5V (30cm<level<90cm) then for the upper comparator you have V+>V- and it outputs Voh. For the lower comparator you have V+>V- and it outputs Voh. The total output is Voh.

If Vs=11V (level>90cm) then for the upper comparator you have V+<V- and it outputs Vol. For the lower comparator you have V+>V- and it outputs Voh. The total output is Vol.

The resulting transfer function is completely opposite than the desired. An input pin reordering is in order. Take a second look.

If you have a better understanding of your circuit now, you should consider again your output specifications. The 3V and 9V selections are not justified. You can select the Vcc and Vee voltages of your comparators to suit your comparator stage needs.

The best way to select the output voltage limits and its driver circuit is to decide on your load first. It is not a good practice to propose driver circuits before stating your load.
 

Thread Starter

ac_dc_1

Joined Jan 27, 2013
74
Vol means Voltage output low and
Voh means Voltage output high.

They are bot quantities that refer to your comparator stage output. They have nothing to do with the water level sensor voltage output or the comparator inputs.

The comparator inputs and voltage thresholds should be referred to as Vil/Vih (Voltage input) or Vtl/Vth (Voltage threshold).

Did you draw the window comparator circuit yourself? If so, I will assume that the voltage source refers to the water level sensor. I will refer to that signal voltage source as Vs.
Your Vih is 10V and Vil is 4V as you specified in post#1.

If Vs=3V (level<30cm) then for the upper comparator you have V+>V- and it outputs Voh. For the lower comparator you have V+<V- and it outputs Vol. The total output of your circuit is Vol.

If Vs=5V (30cm<level<90cm) then for the upper comparator you have V+>V- and it outputs Voh. For the lower comparator you have V+>V- and it outputs Voh. The total output is Voh.

If Vs=11V (level>90cm) then for the upper comparator you have V+<V- and it outputs Vol. For the lower comparator you have V+>V- and it outputs Voh. The total output is Vol.

The resulting transfer function is completely opposite than the desired. An input pin reordering is in order. Take a second look.

If you have a better understanding of your circuit now, you should consider again your output specifications. The 3V and 9V selections are not justified. You can select the Vcc and Vee voltages of your comparators to suit your comparator stage needs.

The best way to select the output voltage limits and its driver circuit is to decide on your load first. It is not a good practice to propose driver circuits before stating your load.

They are bot quantities that refer to your comparator stage output. They have nothing to do with the water level sensor voltage output or the comparator inputs.
Then there has a been a misunderstood,because what i intended and what the problem states is that when the output tension COMING FROM THE SENSOR is equal to 4V that means water level <=30cm and therefore i want Vout=Vcc and when the tension coming from the sensor is equal to 9V that means water level >=90cm and therefore Vo=VCC


If Vs=3V (level<30cm) then for the upper comparator you have V+>V- and it outputs Voh. For the lower comparator you have V+<V- and it outputs Vol. The total output of your circuit is Vol.

If Vs=5V (30cm<level<90cm) then for the upper comparator you have V+>V- and it outputs Voh. For the lower comparator you have V+>V- and it outputs Voh. The total output is Voh.

If Vs=11V (level>90cm) then for the upper comparator you have V+<V- and it outputs Vol. For the lower comparator you have V+>V- and it outputs Voh. The total output is Vol.

The resulting transfer function is completely opposite than the desired. An input pin reordering is in order. Take a second look.
So the voltage source which in fact refers to the water level sensor should go in the non inverting inputs ?


The best way to select the output voltage limits and its driver circuit is to decide on your load first. It is not a good practice to propose driver circuits before stating your load.
My load will just be a circuit that turns on a lamp ,so i can have some sort of relay(normaly open) that will be closed when the input tensions of the comparator were equal to 4v or 10v
 

Georacer

Joined Nov 25, 2009
5,182
You keep interchanging values for Vs(90cm) between 10V and 9V. Given post #1, 10V is the correct value. Please pay more attention when you write. Making such typographic errors makes your posts very hard to understand.
That, or you are trying to convey something that I don't understand.

So the voltage source which in fact refers to the water level sensor should go in the non inverting inputs ?
I made an error there. The circuit you gave with the LM339 comparators is the one that should be used, even if its output is inverted. Let me show you what would happen if you switched the input pins of the two comparators:
Water Level|h<30cm|30cm<h<90cm|h>90cm
High Comparator Output|LOW|LOW|HIGH
Low Comparator Output|HIGH|LOW|LOW
Total Circuit Output|LOW|LOW|LOW

The resulting function is a constant LOW, which is obviously wrong. This is caused by the fact that the LOW output of the LM339 is a strong signal while the HIGH output is a weak one. This cannot be changed.

What you can do is drive your load with an active LOW state and turn it off when the comparator output is HIGH.


Other than that, you insist on not telling us what the load is. Is it a 220V lamp? Is it a 6V one? This affects the relay choice. In turn, the relay choice dictates the Vcc value you should pick. Don't turn your back on advice.

Since you mentioned a relay to bridge the comparators with the driver, what could you do to activate the driver with a LOW signal?
Hint: Relays come with a normally open and a normally closed output.
 
Last edited:

WBahn

Joined Mar 31, 2012
29,976
Then there has a been a misunderstood,because what i intended and what the problem states is that when the output tension COMING FROM THE SENSOR is equal to 4V that means water level <=30cm and therefore i want Vout=Vcc and when the tension coming from the sensor is equal to 9V that means water level >=90cm and therefore Vo=VCC
Well, if you had supplied a sketch of what you needed, like was asked in the very first response in this thread, there wouldn't have been a misunderstanding or, if there had been, we could have got it cleared up right away. But you wouldn't take the five minutes to produce a sketch similar to the one attached, which only took me three minutes. Yet now, perhaps, you can appreciated how much time it would have saved.

You also need to be more precise in your descriptions. An output from the sensor of 4V does NOT mean that the water level is <=30cm. It only means that the water level is equal to 30cm. A sensor output of <=4V means that the water is <=30cm. Similar for the high side.

So the voltage source which in fact refers to the water level sensor should go in the non inverting inputs ?
NO!!!!!!

It has been stated several times that the output of the comparator goes LO whenever the voltage at the V- input is greater than the voltage at the V+ input and that the output goes HI (or, in the case of a 339, look like an open circuit) if V+ is greater than V-.

So pick a sensor output voltage level in the middle of your range (say, for water at 60cm) and determine which signals need to go where to get the desired outout.

My load will just be a circuit that turns on a lamp ,so i can have some sort of relay(normaly open)
What sort of relay? The output of the comparator circuit has to be compatible with this, as yet undefined, relay circuit.

that will be closed when the input tensions of the comparator were equal to 4v or 10v
Now you are talking about 10V and not 9V. Which is it?!

And you don't want the relay to be closed only when the input voltage to the comparator is "equal" to 4V or 10V, you want it closed when the input voltage to the comparator is "less than or equal to 4V" or "greater than or equal to 10V". Otherwise, you are saying you want it closed for 4V, but not 3.95V.
 

Attachments

Thread Starter

ac_dc_1

Joined Jan 27, 2013
74
You keep interchanging values for Vs(90cm) between 10V and 9V. Given post #1, 10V is the correct value. Please pay more attention when you write. Making such typographic errors makes your posts very hard to understand.
That, or you are trying to convey something that I don't understand.

I made an error there. The circuit you gave with the LM339 comparators is the one that should be used, even if its output is inverted. Let me show you what would happen if you switched the input pins of the two comparators:
Water Level|h<30cm|30cm<h<90cm|h>90cm
High Comparator Output|LOW|LOW|HIGH
Low Comparator Output|HIGH|LOW|LOW
Total Circuit Output|LOW|LOW|LOW

The resulting function is a constant LOW, which is obviously wrong. This is caused by the fact that the LOW output of the LM339 is a strong signal while the HIGH output is a weak one. This cannot be changed.

What you can do is drive your load with an active LOW state and turn it off when the comparator output is HIGH.


Other than that, you insist on not telling us what the load is. Is it a 220V lamp? Is it a 6V one? This affects the relay choice. In turn, the relay choice dictates the Vcc value you should pick. Don't turn your back on advice.

Since you mentioned a relay to bridge the comparators with the driver, what could you do to activate the driver with a LOW signal?
Hint: Relays come with a normally open and a normally closed output.

Other than that, you insist on not telling us what the load is. Is it a 220V lamp? Is it a 6V one? This affects the relay choice. In turn, the relay choice dictates the Vcc value you should pick. Don't turn your back on advice.


I did not tell because its not specified.The problem just talks about triggering a lamp.It does not say what kind of lamp it so lets assume its a 220V lamp.


Since you mentioned a relay to bridge the comparators with the driver, what could you do to activate the driver with a LOW signal?
Hint: Relays come with a normally open and a normally closed output.
My idea was to choose a normally open contact that close when the output is high.To trigger the relay with a low signal i could put a inverter intergrate(NOT) but that would imply to have a specific voltage in the output...
 
Last edited:

Georacer

Joined Nov 25, 2009
5,182
Do you have to build the circuit? If not, we can have a hypothetical load that will submit to our vices. If not, we have to submit to his, if we want it to work.

As you stated, a inverter gate isn't a very good choice. But a relay that has a NO and NC contact can double as a NOT gate.

What will happen if you connect your load to the NC contact in regard to the water level? Assume that the relay secondary coil is connected directly to the comparator stage output which is capable of driving it.
 

Thread Starter

ac_dc_1

Joined Jan 27, 2013
74
Well, if you had supplied a sketch of what you needed, like was asked in the very first response in this thread, there wouldn't have been a misunderstanding or, if there had been, we could have got it cleared up right away. But you wouldn't take the five minutes to produce a sketch similar to the one attached, which only took me three minutes. Yet now, perhaps, you can appreciated how much time it would have saved.

You also need to be more precise in your descriptions. An output from the sensor of 4V does NOT mean that the water level is <=30cm. It only means that the water level is equal to 30cm. A sensor output of <=4V means that the water is <=30cm. Similar for the high side.
What i intend to do is exactly what you have posted in your sktech,and yes the light will have to still on if water is <= 30 cm or >=90 cm





NO!!!!!!

It has been stated several times that the output of the comparator goes LO whenever the voltage at the V- input is greater than the voltage at the V+ input and that the output goes HI (or, in the case of a 339, look like an open circuit) if V+ is greater than V-.

So pick a sensor output voltage level in the middle of your range (say, for water at 60cm) and determine which signals need to go where to get the desired outout.
If i had a water level of 60 cm then the output tension from the sensor would be V(0.60 m )=1+10*0.6=7 V.What i want in thsis case is Vout=LOW.So in my circuit we have Vin=6V so the output of the first comparator is LOW and of the second one is HIGH so we get LOW in the output since LOW wins over the HIGH(because its like an open circuit has you said)



What sort of relay? The output of the comparator circuit has to be compatible with this, as yet undefined, relay circuit.


Now you are talking about 10V and not 9V. Which is it?!
The values are te ones in the first post.Its just applying the V=1+10*L

And you don't want the relay to be closed only when the input voltage to the comparator is "equal" to 4V or 10V, you want it closed when the input voltage to the comparator is "less than or equal to 4V" or "greater than or equal to 10V". Otherwise, you are saying you want it closed for 4V, but not 3.95V.
That sounds like i am going to need a transistor operating in two points and what would define the transistion between those points would be the output tensions (10 V and 4V if i am not confusing the values anyway so its better just compute 1+10*0.9m=10 V and 1+10*0.3m=4v

Thanks
 

WBahn

Joined Mar 31, 2012
29,976
First, a mea culpa is in order on my part.

In my last post (post #26) I suggested something off the top of my head and it turns out this is wrong. It also turns out that Georacer had made the same mistake and had caught it and wrote it up in post #25, which I didn't see while I was writing my response (and tending to the dogs and a few other chores).

If you want the output to be LO within the window and HI on either side of it, then a simple LM339-based window comparator won't work. The reason, as Georacer points out, is that in the outer regions where you want the output to be HI, at least one of the comparator outputs will be LO. You can make it work with some minor adjustments, but an easier way is to redefine the output so that it is HI within the window and LO outside of it. That way, each comparator is only asserting a LO on it's side of the window. Within the window, neither is asserting a LO and the resistor can pull it to a HI. If you need the original output polarity, simply follow the window comparator with an inverter.
 

Thread Starter

ac_dc_1

Joined Jan 27, 2013
74
First, a mea culpa is in order on my part.

In my last post (post #26) I suggested something off the top of my head and it turns out this is wrong. It also turns out that Georacer had made the same mistake and had caught it and wrote it up in post #25, which I didn't see while I was writing my response (and tending to the dogs and a few other chores).

If you want the output to be LO within the window and HI on either side of it, then a simple LM339-based window comparator won't work. The reason, as Georacer points out, is that in the outer regions where you want the output to be HI, at least one of the comparator outputs will be LO. You can make it work with some minor adjustments, but an easier way is to redefine the output so that it is HI within the window and LO outside of it. That way, each comparator is only asserting a LO on it's side of the window. Within the window, neither is asserting a LO and the resistor can pull it to a HI. If you need the original output polarity, simply follow the window comparator with an inverter.
So i can either reorder the pins of my circuit so that the output is HI within the window and LO outside of it or put an inverter following the comparator.But if the ouput in the middle of the windows limits wont my output be also high with an inverter?

Thanks
 

WBahn

Joined Mar 31, 2012
29,976
So i can either reorder the pins of my circuit so that the output is HI within the window and LO outside of it or put an inverter following the comparator.But if the ouput in the middle of the windows limits wont my output be also high with an inverter?

Thanks
If it is HI within the window and LO outside the window, and inverter will flip these so that it is LO within the window and HI outside the window. That's what an inverter (the logic type, not the power type) does.
 

Thread Starter

ac_dc_1

Joined Jan 27, 2013
74
First, a mea culpa is in order on my part.

In my last post (post #26) I suggested something off the top of my head and it turns out this is wrong. It also turns out that Georacer had made the same mistake and had caught it and wrote it up in post #25, which I didn't see while I was writing my response (and tending to the dogs and a few other chores).

If you want the output to be LO within the window and HI on either side of it, then a simple LM339-based window comparator won't work. The reason, as Georacer points out, is that in the outer regions where you want the output to be HI, at least one of the comparator outputs will be LO. You can make it work with some minor adjustments, but an easier way is to redefine the output so that it is HI within the window and LO outside of it. That way, each comparator is only asserting a LO on it's side of the window. Within the window, neither is asserting a LO and the resistor can pull it to a HI. If you need the original output polarity, simply follow the window comparator with an inverter.
So i can either reorder the pinns in order to get the output HI within the window and LO outside of it or i can add an inverter to the output of the comparator ,but in this in case wont i get a LO output if the input voltage is inside the limits of comparator(lets say 6V)


Thanks
 

WBahn

Joined Mar 31, 2012
29,976
So i can either reorder the pinns in order to get the output HI within the window and LO outside of it or i can add an inverter to the output of the comparator ,but in this in case wont i get a LO output if the input voltage is inside the limits of comparator(lets say 6V)


Thanks
Draw a picture and think about it!!!

First, ordering the pins so that you have a LO within the window and a HI outside of it (from the basic 339-based window comparator circuit) is not an option. Won't work.

So ordering the pins so that you have a HI within the window and a LO outside of it is not a case of "I can either ...", it is a case of "I have no option but to ...."

Once you have done that, you have two options: You can live with that result, and since you have never defined what the behavior of the circuit is that is going to light your light, that may or may not be acceptable. Or you can invert the output so that you get what you originally wanted, which is a signal that is LO within the window and HI outside of it.
 
Top