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 comparator circuits are simpler than amplifier circuits, as they don't even incorporate negative feedback. Consider the circuit below:
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)
As noted last week, the outputs will likely be lower than the power voltage rails by some amount. This is normal and expected, and is dependent on the specific model of op-amp used. It's possible to make rail-to-rail op-amps that obey this more closely, but they make other performance tradeoffs in the process.
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.
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.
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.
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.
For a 10x probe, the capacitance is on the order of 10 pF or so acting in parallel with a large (~9 MΩ) resistor. 1x probes tend to have higher capacitance, and are typically worse for looking at higher speed signals. For a bit more info about 10x probes, see here: https://blog.teledynelecroy.com/2018/10/secrets-of-10x-passive-probe.html
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:
What is the output of the circuit in this instance? How does it relate to the input?
The output should be essentially a square wave that is $180^\circ$ out of phase with 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)
The changeover will be pretty quick, but since it takes a little while for the input to change over from negative to positive, that will be reflected on the output. I found it took around 30 $\mu$s when testing.
One of the 'measurement' options is for rise time or fall time; these measure the time taken for the signal to get from 10% of to 90% of the start/stop levels. This might be a good thing to direct students to if they're stuck thinking about what to do. The cursors also work well for estimating times in this part.
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?
The changeover should be substantially quicker here, maybe an order of magnitude quicker. The reason is in the next question.
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?
The op-amp will be slew rate limited for the square wave, but not for the sine wave for these inputs.
The typical slew rate of $13 \textrm{V}/\mu\textrm{s}$ is literally the first thing listed on the third page, so finding it shouldn't be difficult at all.
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.
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.
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? (i.e., does the output stay stable after switching if the input doesn't change too much?)
You'll be using your op-amp again later, so you may want to leave it set up.
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.
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:
Construct the circuit on your breadboard
There's a lot of stuff to unpack here, but the circuit that's being set up will consist of just one chip and one resistor, along with power connections.
We'll once again revert to a sinusoidal signal with the following properties:
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.
The changeover here will be pretty similar to the op-amp, as before we're in a situation where the rate of change in the signal itself is the limiting factor.
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 changeover here is much, much quicker than an op-amp. Orders of magnitude so.
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?
Hopefully this will be the case; on the first page it also lists an output switching time of a few hundred ns.
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? (i.e., does the output stay stable after switching if the input doesn't change too much?)
The output does what it should do (changes whenever the input changes from positive to negative voltage), but we'd probably prefer it not to do so as often as it does in practice here.
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:
What voltages do you observe at the non-inverting input $V_{+}$ ?
When $V_{out}$ is at +15V, the resistors form a voltage divider to make it so that $V_+$ will be $15V \times\dfrac{2.2}{2.2+100} \approx 300 mV$ Similarly, when the output is -15 V, $V_+$ will be $\approx-300$.
Observe $V_{out}$ and $V_{in}$ for this new circuit
For what thresholds of $V_{in}$ does $V_{out}$ start to change?
The thresholds should be the aforementioned +0.33 and -0.33V. In practice, we can use whatever resistors we want to set up how large of a change is needed for the output 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? (i.e., does the output stay stable after switching if the input doesn't change too much?)
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)
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 $V_{cap}$?
What determines the rate of change?
Predict how long will it take for the capacitor to charge to +7.5 V
The voltage across the capacitor will begin to increase, as there will be a current from the $10k$ resistor through the capacitor to ground.
The rate of change is determined the resistor (larger ⇒ slower charging) and the capacitance (again, larger ⇒ slower charging)
We can use our capacitor charging equation here; in this instance it will be $V_C = 15V(1-e^{-1/RC})$
From this, we need to figure out when $e^{-1/RC} = 0.5$. Taking the natural log, this is when $-\ln(0.5) = tRC$ or $t = .69RC \approx 0.7ms$
Let's build our circuit and test it now.
Was the time constant what you predicted? (i.e. does $V_{cap}$ behave as you expected, and does $V_{out}$ change with the same frequency? This clarification added 4/21/2025)
Hopefully the time constant will be close, people shouldn't worry as long as it's within a factor of 2. Remember, components will differ from their nominal values by a few percent most of the time.
Also note that we're only looking at the time to change from zero to charged, after the first cycle the capacitor will have a larger voltage change before the output flips again.
Obviously changing the resistor or capacitor on the top part of the diagram will change the frequency, as it will change the charging and discharging time.
However, if the bottom voltage divider is altered it will also change the frequency, since the threshold voltage for change is dependent on that voltage divider. If we reduce the value of the 10k resistor between $V_{out}$ and $V_+$, the oscillator should speed up. Going all the way to $0\Omega$ will result in behavior that depends on the op-amp, but likely won't be pretty or reliable.
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.