14B: Comparator#

Goals:

  • Function of Comparators: Comparators are circuits that determine if a voltage is below or above a specified threshold. They typically use an OPAMP, but not in a linear manner. The output of a comparator has only two states: maximum positive or maximum negative, depending on the input voltage.

  • Dealing with Noise Sensitivity: In its basic form, a comparator circuit is very sensitive to signal-line noise. This can be improved by adding hysteresis.

  • Demonstration: The experiment will demonstrate how to implement hysteresis and observe the resultant behavior of the circuit.

Structure of the practical assignment 14B:#

  • Background + Predict + Simulate (45 min): per person. This is homework and should be finished before you start your 4 hours practicum session

  • Build + Measure (40 min): with your partner (group of 2)

  • Evaluate (10 min): with a group of 4 (per table)

BACKGROUND#

⏳ Estimated time: 15 min

1. Exploring OPAMP as a Comparator#

In this segment, we delve into the use of an Operational Amplifier (OPAMP) in a unique role—as a comparator. This setup is intriguing because it leverages the OPAMP’s high gain without requiring negative feedback. Essentially, the OPAMP’s output oscillates between two extremes, clipping against either its positive or negative supply rail, indicating a binary state: either fully positive or fully negative.

2. Comparators vs OPAMPs#

It’s important to highlight that there are specialized Integrated Circuits (ICs) designed as comparators. While bearing a resemblance to OPAMPs with differential inputs and high gain, comparators are distinctly engineered to output just two levels: high or low. Unlike OPAMPs, they are unsuitable for linear amplification tasks.

3. Comparator Circuit Analysis#

The comparator circuit employs one input for reference and another for the signal. When the reference voltage (Vd) is connected to the inverting input and the signal voltage (Vi) to the non-inverting input, the circuit operates in the following manner: If Vi is less than Vd, the output is negative (since Vi - Vd yields a negative result). Conversely, if Vi exceeds Vd, the output turns positive.

Above is the circuit diagram and its typical behavior.

What would change if we would swap both inputs? So Vi to the inverting input and the reference (Vd) to the non-inverting input?

4. Dealing with Noisy Signals#

In an ideal world, signals are noise-free, but reality presents us with noisy signals that can lead to erratic behavior in the circuit, as shown below.

Noise-induced fluctuations, or ‘bouncing’, can be problematic. It depends on the applications, but especially in scenarios where the comparator feeds into a counter, “bouncing” will lead to counting errors. To mitigate this, we introduce hysteresis into the circuit, altering the switching threshold based on the current output state.

Changing of the switching levels, the hysteresis, is achieved via positive feedback where the output is connected back to the non-inverting input through a set of resistors.

Note: this is not a linear circuit! So we cannot assume that inverting and non-inverting input have the same potential. However, we still assume that no current is flowing into the OPAMPs inputs.

The diagram above showcases a non-inverting comparator. The output is positive when the input signal surpasses the threshold and negative otherwise.

5. Calculating the Switching Levels#

To determine the switching levels, recognize that:

  1. The OPAMP compares the voltage on the non-inverting input to the potential on the inverting input (GND).

  2. The potential on the inverting input is stems from the resistive divider R1 and R2, which are connected between the input voltage and the output voltage.

  3. At the moment of switching, the potential on the non-inverting input is exactly 0V, meaning that the voltage drop over R2 is equal to Uout, and so the current is Uout/R2.

  4. The current through R2 flows through R1, creating a voltage drop over R1: $\frac{U_{out}}{R2} \cdot R1$

  5. Thus, the switching levels are calculated as ± \(U_{out} \cdot \frac{R_1}{R_2}\).

ANTICIPATE: Switching Levels in a Comparator with Hysteresis#

⏳ Estimated Time: 15 min

Understanding the Schmitt-Trigger Comparator#

This section focuses on calculating the switching levels of a comparator circuit with hysteresis, commonly known as a Schmitt-trigger. The circuit diagram below illustrates the comparator in question. For this calculation, assume the following:

  • The positive output voltage of the OPAMP is +12V.

  • The negative output voltage of the OPAMP is -12V.


Figure: Comparator with Hysteresis, featuring resistances Ra = 10kΩ and Rc = 3.4kΩ.

Your task is to determine the specific points at which this comparator switches its output state, considering the given resistor values and the OPAMP’s output voltage limits. This exercise is crucial in understanding how hysteresis impacts the behavior of comparators in real-world applications.

### TO DO="write your answer for comparator switching-levels " 

SIMULATE: Building and Analyzing a Comparator without Hysteresis#

⏳ Estimated Time: 15 min

Constructing the Comparator Circuit#

Your task in this section is to construct a comparator circuit in LTSpice using an LM741 operational amplifier (opamp). To ensure accurate simulation results, remember to power the LM741 with a ±12V supply. The circuit diagram to guide your construction is provided below:

Simulation#

Once your circuit is built, proceed with a simulation to observe the voltage changes over time.#

  • Input any signal you want.

  • How does the output voltage respond to the input signal?

ℹ️ Hint
Look closely where the “switching” happens and what are the max values

Upload screenshot of your simulation results showing the voltage changes over time

### TO DO=" If you input a sine, explain how will the output look like (shape, phase, amplitude) "
 
from ipywidgets import FileUpload
from IPython.display import Image
import os
upload=FileUpload()
upload
file_name="14B_1_comparator_sim.jpg"
if upload.value!={}:
    with open(file_name,"wb") as f:
        try: f.write(upload.data[-1]) # python 3.7 Kernel code
        except: f.write(upload.value[-1]["content"])  # python 3.8 Kernel code

Image(filename=file_name, width="50%")

Modify the Comparator Configuration#

Now modify the comparator circuit by switching the inputs at the opamp.

Question: What differences do you notice in the comparator’s output compared to the previous configuration?

### TO DO=" write your answer: the difference is ..."
 

IMPLEMENT & INVESTIGATE 1: Building a Comparator Circuit with Hysteresis#

⏳ Estimated Time: 40 min

Equipment Required#

To construct and investigate the comparator circuit, gather the following items:

  • Testboard 4

  • Function generator

  • Oscilloscope

  • Coaxial splitter

  • All necessary cables

Circuit#

Build a comparator circuit with hysteresis on Testboard 4.

ℹ️ circuit diagram

Figure 3: Comparator with Hysteresis.

Setting Up the Experiment#

Set the resistances as follows:

  • Ra to 10kΩ (activate switch #3).

  • Rc to 3.4kΩ (turn on switches #2 and #3, paralleling 10kΩ and 5.2kΩ resistors).

ℹ️ Hints

You can use a high amplitude sine wave as your input signal

Questions#

Monitor the input and the output of the circuit simultaneously.

  1. Did you expect this behaviour?

  2. How does it compare to results from SIMULATE?

ℹ️ Hints
You should see a shift in your signal due to these modifications. What parameter was changed by changing the resistor values (think about the anticipate and simulate).

### TO DO=" write your answer"
 

Analyzing Switching Levels Using Oscilloscope’s XY-Mode#

After setting up your comparator circuit, it’s time to analyze its switching levels in a more visual and insightful way:

  1. Switch the oscilloscope to XY-Mode:

    • Locate and press the “main/delayed” button on your oscilloscope.

    • Change the display mode from Y-T (normal) to X-Y.

  2. Investigate and document switching levels:

    1. Examine the oscilloscope screen to determine the comparator’s switching levels.

    2. Make an accurate drawing of the figure displayed on the oscilloscope screen.

      • Ensure that your drawing captures the key features and thresholds of the waveform.

      • Alternatively, you can take a clear photograph of the oscilloscope screen.

### TO DO=" your answer, supported by an image of the scope screen" 
 
from ipywidgets import FileUpload
from IPython.display import Image
import os
upload=FileUpload()
upload
file_name="14B_2_switching_levels.jpg"
if upload.value!={}:
    with open(file_name,"wb") as f:
        try: f.write(upload.data[-1]) # python 3.7 Kernel code
        except: f.write(upload.value[-1]["content"])  # python 3.8 Kernel code

Image(filename=file_name, width="50%")

Studying Low-Speed Comparator Behavior#

Now that you have observed the comparator’s switching levels, the next step involves analyzing its behavior at a significantly lower frequency:

  1. Set the frequency of the signal generator to 0.1 Hz. This change will cause the curve on the oscilloscope to be traced at a much slower pace.

  2. Carefully watch the curve as it slowly follows the input signal.

    • Pay attention to how the comparator reacts at this reduced speed.

    • Try to understand and explain the changes you observe in the circuit’s behavior.

Question: How does the comparator respond to the slower input signal transitions?

ℹ️ Hint 1
If you are having difficulty observing the curve due to its slow movement, consider adjusting the persistence setting of the oscilloscope screen to ‘infinite’. This setting will make the trace remain visible longer, aiding in your analysis.

ℹ️ Hint 2
A comparator circuit has the output reacting to the input. Why would changing the frequency influences the way this happens?

### TO DO=" your answer, what do you see and how can you explain" 
 

COMPARE & CONCLUDE#

⏳ Estimated time: 10 min

  • Wait till all (4) group members finish their observation

  • Compare your results with your other group members.

  • If your results agree, and are in line with all predictions, then talk to a TA and get checked off

  • Otherwise, so if your results do not agree, or your results are not in line with your predictions, then first discuss amongst your group before getting a TA.

to be checked off by a TA:

  1. What are the advantages of using hysteresis in comparator circuits.

  2. exit card:

    1. Write a brief abstract on what you learned (conclusion, useful graph),

    2. Which troubleshooting skills do you want to remember for next sessions,

    3. Which code do you copy for use in next sessions,

  3. How do you think this notebook could be improved

#14B comperator
### TO DO="1. the advantage of hysteresis"
 
### TO DO="2a. abstract"
 
### TO DO="2b. troubleshooting"
 
### TO DO="2c. code"
 
### TO DO="3. what changes would you suggest?"