# OpAmp comparator

I need some help with understanding the OpAmp comparator in making a DC signal digital.

This is not the actual circuit i'm testing with SPICE. But i can't seem to get even the basics right. What am i doing wrong. From everything i've read, for a simple comparator circuit this should be it more or less. Connect to the right terminals. If the non-inverting terminal has a higher potential than the inverting one, then the output should be a positive value. Otherwise it should be zero? If i put R1 to say 500ohm, the output says it's 2V. I'm really baffled.

I hardly doubt the issue is with the software, i'm probably missing something.

Any ideas? Thanks

You are right, with R1 = 500, output should go high

An OpAmp is an OpAmp. A comparator is a comparator.

When you are designing something, you should select the appropriate component, either a OpAmp or a comparator.

What is VS1 ? Does it generate a volatage ? but the "+" is connected to ground, and the other side is connected to the power supply. Normally, you would have a voltage divider (two resistors) to ground and power supply and the middle is a certain voltage for the comparator. The VS1 should go into the other input of the comparator.

If you don't put some + feed back in your circuit you will eventually find yourself in problems. Google hysteresis. Google Compactor. Look at a the compactor LM339 data sheet, there are typical examples in the document you can follow.

@Peter

The voltage generator is 12V. The voltage drop on R1 should be 7.2V. Which is higher than 6V. To which "+" are you referring to? The voltage divider from what i can tell should be working. I'm not sure for the last part though. Should i be connecting the positive Vin to the inverting terminal of the OpAmp?

@Larry

Yes, i want to put some hysteresis, but i can't seem to get even the simple circuit to work. But it's on the list yes.

Single supply = 12V
The virtual ground is at 6.0V
Output voltage swing = 2V to 10V (typical) LM318

The + terminal is at 7.2V (input voltage), R1 = 1.5K
The + terminal is at 4.0V (input voltage), R1 = 500Ω

The - terminal is at 6.0V (reference voltage)

When the input > reference voltage, the output swings to 10V. (R1 = 1.5K)
When the input < reference voltage, the output swings to 2V. (R1 = 500Ω)

Everything looks OK to me.

EDIT: If we change what’s considered input and reference, then the circuit operates as an inverting comparator.

The + terminal is at 7.2V (reference voltage), R1 = 1.5K
The + terminal is at 4.0V (reference voltage), R1 = 500Ω

The - terminal is at 6.0V (input voltage)

When the input < reference voltage, the output swings to 10V. (R1 = 1.5K)
When the input > reference voltage, the output swings to 2V. (R1 = 500Ω)

@dlloyd

Aha, that is what was missing. So it's not 0V to something, but 2V to 10V.

The datasheet says output voltage swing +-13V. I'm having some trouble interpreting this value. How did you get the 2V to 10V?

Peter_n: An OpAmp is an OpAmp. A comparator is a comparator.

When you are designing something, you should select the appropriate component, either a OpAmp or a comparator.

What is VS1 ? Does it generate a volatage ? but the "+" is connected to ground, and the other side is connected to the power supply. Normally, you would have a voltage divider (two resistors) to ground and power supply and the middle is a certain voltage for the comparator. The VS1 should go into the other input of the comparator.

Why are opamps and comparitors always drawn as an opamp on every schematic I see? Never made much sense.

The lm386 I guess is not an opamp or comparator either yet, as a schematic it is!

But I can use an opamp as an audio amplifier...

And I can use an opamp as a comparator to sense voltages..

Right?

The ±13V swing is when the connected supply is ±15V. So the output can only swing to a range that's ±2V less than the supply rails. With a single supply 0-12V, the output can only swing from 2-10V.

Note that there is no true ground connection on this IC. With a dual supply, the internal circuit establishes a virtual ground that's somewhere very close to 0V.

With a single supply (in this case with 0V and 12V terminals) the virtual ground internal to the IC will be somewhere very close to 6V (midway point).

@cjdelphi, I found this link to be quite good because it saves me a lot of typing...

Op amp vs comparator

The two input pins are label V+ and V- (not to be confused with Vcc and Vee (power pins)

comparator

If i put R1 to say 500ohm, the output says it’s 2V.
I’m really baffled.

It’s not that complicated. The concept of a voltage divider is straight forward. The two resistors determine
a ratio (upper resistor to lower resistor) (we can’t use R1/R2 because you didn’t)

Vout = [Vin x (lower resistor)/(lower resistor +upper resistor)],

obviously if RU=RL then the output is 1/2 input.
If RL= 1/10th RU, then the output would be 1/10th the input. It’s really simple.

But I can use an opamp as an audio amplifier…

Yes but then you need to add all the components that are built into the audio amplifier.
It is really not a good idea to get in the habit of using things for applications they weren’t designed for.
Using an op amp as a comparator is not a problem because it falls into the category of applications it was
designed for. You could use a comparator LM319 or an op amp. You will not be able to tell the difference
other than the cost.

far_1: I need some help with understanding the OpAmp comparator in making a DC signal digital.

This is not the actual circuit i'm testing with SPICE. But i can't seem to get even the basics right. What am i doing wrong.

Why wouldn't you show the "actual circuit" (or the actual virtual circuit)? Is "VS1" backward on that one, too?

SPICE "circuits", like actual, physical circuits require all of the connections, networks, to be set right. You have to get the nodes right, you have to get the wires right.

dlloyd: The ±13V swing is when the connected supply is ±15V. So the output can only swing to a range that's ±2V less than the supply rails. With a single supply 0-12V, the output can only swing from 2-10V.

Note that there is no true ground connection on this IC. With a dual supply, the internal circuit establishes a virtual ground that's somewhere very close to 0V.

With a single supply (in this case with 0V and 12V terminals) the virtual ground internal to the IC will be somewhere very close to 6V (midway point).

Aha. I understand. Thanks for the explanation.

@Pancake

I'd wanted to first see how it works with the bare minimum and troubleshoot from there.

Why are opamps and comparitors always drawn as an opamp on every schematic I see?

Because that’s not an op amp schematic symbol. That is an amplifier schematic symbol and both comparators and op amps are amplifiers. A comparator is usually used as an open loop amplifier but
generally has a hysteresis feedback component (resistor etc)

Go back an look at the amplifier symbols from pre-op amp days. There is a + input and - (feedback)
input. In the op amp and comparator , they have been brought out to pins. In the early analog computer
days, (when analog computers were made using vacuum tubes, the amplifier symbol was basically the]
same only the triangle was slightly different. It had a + input and a - input.

See “Definition for the fledgling op amp” (second paragraph)

"The very first op amps weren’t even called such, nor were they even called “Operational Amplifiers”
The naming of the device came after the war years (1947).

Op amp history/Black’s Amplifier

ANALOG COMPUTERS

Typical electronic analog computers contain anywhere from a few to a hundred or more operational amplifiers (“op amps”), named because they perform mathematical operations

Mk-1 Fire Control Computer

The design of the post war Mark 1A may have been influenced by the Bell Labs Mark 8, Fire Control Computer which was developed as an all electrical computer, incorporating technology from the M9 gun data computer as a safeguard to ensure adequate supplies of fire control computers for the USN during WW2.[2] Surviving Mark 1 computers were upgraded to the Mark 1A standard after World War II ended. Digital fire control computers were not introduced until the age of minicomputers in the mid-1970s.

The Mk 8 computer used all electric methods of computation, in contrast to the Mk 1, which performed most computations via mechanical devices. The Mk 8 was found to be more accurate than the Mk 1 and substantially faster in reaching a fire control solution,[2] but by the time it was developed and tested in 1944, supplies of the Mk 1 were found to be sufficient in quantity.

First op amp

Differential Analyzer

There is really no way to distinguish between a generic feedback amplifier symbol and an op amp symbol as the
op amp symbol is the generic feedback amplifier symbol.

In short. There is no such thing as an op amp symbol.
It is simply a feedback amplifier symbol. Which brings us to the question of what would happen if you got your comparator chips and you op amp chips mixed up and tried to build an integrator using a comparator ?

So, if very little appears to be different in the schematic symbol or the internal workings, what is
the difference? The difference is in the output stage. An op amp has an output stage that is optimized for linear operation, while the output stage of a comparator is optimized for saturated operation.

Operational amplifiers (op amps) and comparators look similar; they even have very
similar schematic symbols. This leads a lot of designers to think they are interchangeable.
There is a strong temptation to use a spare section of a multiple op amp package as a
comparator to save money. This application note will explain why designers should not do
this.

comparator vs op amp

Now does it make sense ?

Sorry to bother you again guys.

I got the thing working as dlloyd explained it. But the trouble is that i'm stuck on how to actually get a useful digital output signal. Arduino needs below 1.5V for a LOW signal (on the op amp output). My input on the op amp is a photodiode, so that means not an AC signal.

I'v tried lot's of silly things, but don't really know how to get clear LOW and HIGH signals from the op amp, to use on the arduino. Any pointers would be much appreciated. Thanks again.

Thanks, i'll look into it. This op amp vs comparator stuff is kinda confusing.

Have you tried 2 resistors in series to make a voltage divider?

``````10V ⊙----10K----⊙ 5V ⊙----10K----⊙ GND
2V ⊙----10K----⊙ 1V ⊙----10K----⊙ GND

10V ⊙----10K----⊙ 4.3V ⊙----7.5K----⊙ GND
2V ⊙----10K----⊙ 0.86V ⊙----7.5K----⊙ GND

10V ⊙----10K----⊙ 3.3V ⊙----5K----⊙ GND
2V ⊙----10K----⊙ 0.67V ⊙----5K----⊙ GND
``````

Voltage Divider Calculator

dlloyd: Have you tried 2 resistors in series to make a voltage divider?

``````10V ⊙----10K----⊙ 5V ⊙----10K----⊙ GND
2V ⊙----10K----⊙ 1V ⊙----10K----⊙ GND
``````

10V ⊙----10K----⊙ 4.3V ⊙----7.5K----⊙ GND 2V ⊙----10K----⊙ 0.86V ⊙----7.5K----⊙ GND

10V ⊙----10K----⊙ 3.3V ⊙----5K----⊙ GND 2V ⊙----10K----⊙ 0.67V ⊙----5K----⊙ GND

``````

[Voltage Divider Calculator](http://www.calculatoredge.com/electronics/voltage%20divide.htm)
``````

I admit it once crossed my mind but i kinda dismissed it, since i though i must be doing something wrong with the op amp for not getting a 0V. But i see now, yes. Thanks. That would also work.

I'm playing now again with the threshold detector circuit with some success. The main issue i have currently is how to get the ground and sources connected properly. I'll post some examples.

You need to lose the LM318, its not 5V logic compatible. There are plenty of modern opamps with rail-to-rail outputs, which can drive towards the -ve rail, but the LM318 is not one of them.

But more importantly use a comparator, not an opamp, to do the job of a comparator. Many opamps drawn significant input currents when their two input terminals are more than a volt or so different, since opamps are designed to operate with negative feedback.

Comparators drawn low input currents whatever the input voltages and more usefully have open-collector outputs that can be interfaced to logic of any voltage conveniently (use a pull-up, built in or otherwise).

The LM339 has 4 comparators in one package for next to no money, just buy a bunch!

The Arduino has a comparator built in, BTW, you can find out about it in the datasheet.

Whenever using a comparator (or opamp as a comparator) think about adding external positive feedback to provide some hysterysis to prevent multiple transitions.