Pages 336-344

Comparator Circuits

Sometimes, you don't want to amplify a signal, but rather just test if it is above or below some threshold.  For instance, you might want an exhaust fan to either be on or off depending on if the particle count in the air is above a threshold.  Indeed, quite a few devices don't work well at low voltages (e.g. motors need to overcome friction).  Thus, there can be a need to make a circuit that compares a voltage to a reference value and outputs specific voltages according to some logic.  These circuits are know as comparators.

Op-amp comparators

Op-amp comparator circuits are simpler than amplifier circuits, as they don't even incorporate negative feedback.  Consider the circuit below:

A Comparator circuit made with an operational-amplifier. You should use the LF411 here; another dedicated comparator will come up later in the lab.

You'll notice that there's no way that the circuit's output can affect the non-inverting input in this instance.  Thus, we have to fall back on what is called the op-amp's open-loop gain G, which is on the order of $10^6$.  Without negative feedback, the op-amp's output will be equal to:

$V_{out} = G \cdot (V_+ - V_-)$

This is subject of course to the limitations that the output can't exceed the connected power supply.  (This rule is still technically true when the Golden Rules are being obeyed, but when the difference between inputs is fractions of millivolts the distinction is often unimportant.)

Keeping the output limitations in mind, we can instead frame this as:

$V_{out} = V_{CC}\; \textrm{if}\; (V_+ > V_-)$
$V_{out} = V_{EE}\; \textrm{if}\; (V_+ < V_-)$

where $V_{CC}$ is the positive power supply voltage (15 V) and $V_{EE}$ is the negative power supply voltage (-15 V)


Practical Detour: Probe Compensation

Up until now, we've just sort of used our oscilloscope probes without considering their effects on the circuit we're measuring.  They act like very large resistances, so they shouldn't have any effect, right?  Well, now that we're looking at some faster signals, the fact that the cables and probes have a small (but finite) capacitance will make a difference, and may distort our signal.  Thus, we need to measure a known signal with our probe and adjust its capacitance so that our measurement matches what we'd expect.

To start, connect your probe to the scope and locate the Probe Comp connections on the front of your oscilloscope.  Connect the alligator clip to ground (the lower one) and the probe tip to the other connection. 

Connecting to the built-in function generator. These terminals are on the bottom-right corner of your scope. The adjustment screw for tweaking probe capacitance

Depending on how your probe is configured currently, you'll either see a square wave (no changes needed) or you'll see a distorted square wave that overshoots or undershoots at the start of the signal. 

Too much probe capacitance, cutting off quick transitions Properly compensated probe Too little probe capacitance, causing signal over-shoot

To fix this, locate the hole on the BNC side of your probe that lets you adjust its capacitance.

Use the flat end of a screwdriver (the other side won't fit) and adjust the signal until you have a nice, flat square wave.  When using a scope to measure things in the lab, this is something that you'll want to do any time you're working with either high frequency signals or square waves with abrupt transitions and you care about the details of the waveform's shape.

I want to know way, way too much about what's going on here!

You're in luck, Doug Ford has you covered with an eight page article about The secret world of Probes. The technical details will be beyond the scope of this class, but you'll still probably gain something from looking over it.


Back to testing

If you haven't already, build the comparator circuit shown earlier.

Let's test our circuit and see how well the op-amp behaves.

Start with a sinusoidal signal with the following properties:

  • 1 kHz frequency
  • 1 $V_{pp}$
  • No offset
What is the output of the circuit in this instance?  How does it relate to the input?

Change the time scale until you can clearly see what happens when the output signal transitions between voltages.

How long does it take for your signal to change, and what is the rate of change? (You'll have to use your discretion to decide the start and stop of the change)

Now change the input waveform to a square wave, with other properties remaining the same

How is the signal's rate of change affected by this setup?

Look at the datasheet to find this chip's slew rate (the rate at which the output voltage can change). It should be around the top of page 3.

Is the op-amp limited by the slew rate for the sinusoidal signal?  For the square wave?
Why doesn't my chip's behavior match the datasheet?

Datasheets often list typical behavior, which isn't guaranteed to hold for any specific device. You'll notice that the minimum rate (under specific test conditions) is about half the typical rate.  This is pretty typical, so if you're designing a circuit that needs a part that has specific properties you should only plan on the minimum/maximum listed.

My square wave from the function generator looks funny

When you zoom in you may see that the square wave from your function generator oscillates a bit after it changes voltage.  This is often dubbed “ringing” as an analogy to the sound of a ringing bell that fades away after it is struck.  The causes of ringing are numerous, from impedance mismatches (probably the case here) to poorly designed circuits.  At the moment, it probably isn't a problem unless it is particularly large or persistent, in which case you might want to try moving/changing cables to see if they're making it worse.

Looking at noisy signals

There's one place where comparators can easily get into trouble: signals with noise around 0V. To observe this, we'll load a saved waveform on your function generator.

Press the Store button, then use the touchscreen to navigate to the C: directory and select the file called Gnarly.RSF. Press the read option to open the file. Your function generator might complain, but it will probably load it anyways.

If this fails, try turning the function generator off and on. That seems to satisfy the machine spirits.

Does the output do what you'd expect?

Does the output do what you'd want?

You'll be using your op-amp again later, so you may want to leave it set up.

Comparator Integrated Circuits


Comparators are useful often enough that there are dedicated chips made specifically for this purpose.  One of the most common, the LM311, will be used in this lab.

A Tortured Analogy

The difference between the LM311 and a comparator built from an op-amp is all about performance.  The op-amp is a family sedan car to the comparator's drag racer: they both can do the job of going quickly better than a person, but the comparator's whole purpose is dedicated to it while the op-amp can do a bunch of other things.  In this case, the comparator chip is designed to change outputs faster and allow for larger currents than a comparator made from an op-amp.

Pin connections for the LM311 comparator. Notice that instead of just having a $V_{out}$ connection, this chip acts like it has a BJT transistor attached to its output.  We'll see the effect this has on design in a moment.

We won't need the balance (BAL) connections for fine-tuning or the strobe (STRB) connection for quickly enabling/disabling the chip here. The LM311 datasheet can be found here.

We'll start with a basic comparator circuit:

A comparator built from the 311 IC.  Note that the grey box represents the chip itself; you don't actually need to add a transistor.  The 10k resistor here is know as a pull-up resistor.  If we had no resistor, there'd be no way for $V_{out}$ to be anything but 15V; with it there then the output is 15V (when there's no current through the resistor) or about -15V (when the transistor is on and saturated).

Construct the circuit on your breadboard

We'll once again revert to a sinusoidal signal with the following properties:

  • 1 kHz frequency
  • 1 $V_{pp}$
  • No offset

Change the time scale until you can clearly see what happens when the output signal transitions between voltages.

How does the output waveform differ from the op-amp circuit?

Depending on how you've constructed your circuit, the edges of the output signal may contain some fast oscillations instead of a single neat transition. We'll address good ways of dealing with this later, but for now you can mitigate the issue by increasing the input signal voltage. This will make the actual signal overwhelm any noise quicker.

Now change the input waveform to a square wave, with other properties remaining the same

How does the output's slew rate (rate of change) compare to the op-amp based circuit?

The 311's output changes are characterized in page 6 of the datasheet (6.7 Switching Characteristics).  While we're not operating under their test conditions, this does give us a general idea of what we can expect.

Does the output change on the right order of time for your circuit?

A Continuing Problem: Noisy Signals

Now that we've got a dedicated comparator, let's test it again with our gnarly signal. Load the signal as before and observe the circuit's output.

Does the output do what you'd expect?

Does the output do what you'd want?

Schmitt Triggers: Back to Op-Amps


As you may have noticed, comparators don't always do what you'd like them to when there's noise on top of the signal you're looking at.  If we're trying to do something like counting how many times our signal gets over a threshold (something that can come up in radiation detection for instance), this can cause a lot of headaches.  To address the problem, let's look at the following circuit

A basic Schmitt trigger circuit. Note that the voltage at the non-inverting input depends on the current output voltage here. This will result in our circuit exhibiting Hysteresis, as the current state depends on the prior state of the system.

You'll notice that in this case, the op-amp's output is connected to its non-inverting input.  This means that instead of having negative feedback (i.e. having the output reduce the difference between inputs) we have positive feedback: when the output changes it increases the difference between inputs!  Instead of discussing what effects this has, we'll have you test it first.

Build the Schmitt trigger using the op-amp on your board. You did remember to keep it in place, didn't you?

Using our good old friend the sine wave, with:

  • 1 kHz frequency
  • 1 $V_{pp}$
  • No offset
What voltages do you observe at the non-inverting input $V_{+}$ ?

Observe $V_{out}$ and $V_{in}$ for this new circuit

For what thresholds of $V_{in}$ does $V_{out}$ start to change?

Now take things back to the Gnarly signal and see how the circuit behaves.

Does the output do what you'd expect?
Does the output do what you'd want?
Who even though of this?

This type of circuit was first designed by Otto H. Schmitt while he was a graduate student.  He was working in biophysics at the time, studying the propagation of signals in squid nerve cells. (https://en.wikipedia.org/wiki/Otto_Schmitt)

Op-amp RC relaxation oscillator

Up until now we've been working only with resistors in our feedback loops, but we can also use other components such as capacitors.  Consider the circuit below:

Let's start with the assumption that $V_{out}$ is +15V, and that the capacitor is uncharged.

What will happen to the voltage across the capacitor?
What determines the rate of change?
Predict how long will it take for the capacitor to charge to +7.5 V

Let's build our circuit and test it now.

Was the time constant what you predicted?

Alter one of the components in your circuit to change the frequency of your signal, and explain how it did so.

You might wonder how it is that this circuit like this can oscillate without us doing anything to set it up in the first place.  We can thank our friend positive feedback for that!  Our oscillator circuit is like a pencil balanced on its point: while technically it could stay that way indefinitely, it is in an unstable equilibrium: any small deviation will cause the system to fall into a lower energy state: falling for the pencil or oscillating for our circuit.  You may also see circuits that you didn't expect to oscillate do so unexpectedly: the culprit is often some sort of unintended capacitance.