Positive Voltage Comparator

Thread Starter

haroldjclements

Joined Nov 8, 2017
9
Hi, I am trying to teach an old dog new tricks (trying to educate myself) and I am having issues with what seems to be a very basic concept. If you guys could point me in the right direction, I will be very grateful.

opamp-opamp105.gif

Using the illustration above as a guide, if +Vcc = 5v then VRef = 2.5v through the voltage divider provided by the two resistors. This sets the Inverting input of the comparator to have a threshold of 2.5v.

Therefore, if VIn > VRef then VOut is High (Vcc) else (VIn is < VRef) vOut is LOW (0v).

So I tried to put this into practice using a LM311 Voltage Comparator. Below, is my schematic.

Screenshot 2021-12-05 115026.png
Within this circuit, as pin 2 (the non inverting input) is tied to Vcc (+5v), I would have thought that the output on pin 7 (VOut) would be HIGH (+5v), after all, 5v > 2.5v which is in accordance with the first illustration.

One element that I am not too sure of and I may have wrong on this drawing is GND. I am using GND to mean 0v. However I *think* ground might actually be the point between the resistors.

However, when measuring the voltage between VOut and GND (with 5v going to the non inverting input - pin 2) I only get 1.39v. If I pull pin 2 to 0v I get 0.32v ... where the difference is ~ +1v it's not what I am expecting. Also, if pin 2 is left floating, it also reads 1.39v.

I am not sure if I have my theory wrong, if I am using the wrong device (LM311), if I am just wiring it up wrong or I am taking the measurements from the wrong place. As I say, I am trying to educate myself so I apologise in advance if I have miss some basic step or principle, but I would really appreciate this forums help.

Regards,
Harold
 

Jony130

Joined Feb 17, 2009
5,316
But LM311 is an open collector type comparator. So you need a pull-up resistor (10k) from Vcc to pin7 ). And the input voltage should be less than Vcc by 1.2V or more.
LM311.GIF
 

ronsimpson

Joined Oct 7, 2019
2,011
old dog new tricks
New tricks are hard when you get tricked by a LM311.
As Jony130 said. This Voltage Comparator has a uncommitted transistor on the output so you have more options. (or to trick you)
Also most Voltage Comparator have a "open collector" output that needs a pull up resistor to work.
There are some Voltage Comparators that have "normal" outputs. (pull up and pull down)
 

crutschow

Joined Mar 14, 2008
29,521
The open-collector output has a couple useful features:
  1. The output resistor can connected to a higher voltage level than its power supply, allowing level shifting of the signal.
  2. Two or more outputs can be wired "AND" (all inputs must be high for an output high). This is useful for certain types of circuits, such window comparators.
 

Thread Starter

haroldjclements

Joined Nov 8, 2017
9
First off... Thank you all for your responses. They are all very much apprecieated...

So understanding that output pin is the open-collector of an internal transistor, I included the pull-up resistor (10k) as per @Jony130 suggeston and moved pin 4 back to GND (as per @Alec_t's comment). - At least I hope I understand! I guess I thought the output pin was supply was provided internally from pin 8.

Screenshot 2021-12-05 194912.png
Mesuring the voltage across the two probe positios - When pin 2 is pulled to GND the output (pin 7) is 0v. When pin 2 is pulled Vcc (5v), pin 7 is 5v. This is what I was expecting.

Screenshot 2021-12-05 203244.png
I though I would go one step further and add a pull-up resister and a switch to pin 2 so the high and low is stable. I also added an LED to add a bit of visual aesthetics. I change the R11 from 10K to 160R to increase the currnet to LED2 (brightness).

So now I have an elaborate switch, but I "hope" I have learned something from the exercise. I guess I can change the switch for a LDR or something to "jazz" it up...

Thanks again for your time and help...
Harold
 

dl324

Joined Mar 30, 2015
14,332
I though I would go one step further and add a pull-up resister and a switch to pin 2 so the high and low is stable.
You need to read the datasheet.
1638739243887.png
1638739259142.png
1638739273952.png

The guaranteed input voltage range is VEE+0.5V to VCC-2.0V; or 0.5V to 3V in your case.
EDIT: corrected minimum input voltage.

If you plan to breadboard circuits, I'd suggest that you use LM393 (2 in a DIP8) or LM339 (4 in DIP14). These comparators were designed for single supply operation and the input voltage range includes ground; but not VCC.

I guess I thought the output pin was supply was provided internally from pin 8.
You don't need to guess if you read the datasheet.

The original comparators were all open collector. Only some of the newer comparators have active pull-ups.
 
Last edited:

MisterBill2

Joined Jan 23, 2018
11,624
For more education, use that second circuit in post #6, and connect the inverting input, pin #2, to the wiper of a potentiometer connected between V+ and common. I use the term common because it does not need a "ground" connection, while common is the power source return connection. You will discover that the LED brightness will vary as the pin 2 voltage passes by the value of the pin 3 voltage. That is because the LM311 will be oscillating when the voltages are close.
 

Thread Starter

haroldjclements

Joined Nov 8, 2017
9
That is because the LM311 will be oscillating when the voltages are close.
Hi @MisterBill2, I gave your educational suggestion a try (I only get weekends to play about) and yes, at the "biting point" of the pot switching the LM311, the LED is dimmer.

Is this oscillating by design?

I have looked at the datasheet, but I am not sure what I would be looking for (being dyslexic does not help... that's not an excuse, it just makes it a bit harder for me ... you might say that I have high impedance between by eyes and my brain!).

As always I am grateful for all your patience, time and effort in guiding me in the right direction...
 

MisterBill2

Joined Jan 23, 2018
11,624
For more education, use that second circuit in post #6, and connect the inverting input, pin #2, to the wiper of a potentiometer connected between V+ and common. I use the term common because it does not need a "ground" connection, while common is the power source return connection. You will discover that the LED brightness will vary as the pin 2 voltage passes by the value of the pin 3 voltage. That is because the LM311 will be oscillating when the voltages are close.
YES, without a bit of hysteresis (positive feedback), the comparator will certainly oscillate as the threshold is crossed. So very high value resistor from the output to the positive input will assure that the switching is clean, like the drawings in post#1. This is a very important thing to understand about comparators.
 
Top