Visual
Lab intro
A comparator circuit produces a binary output based on the relative magnitudes of two input voltages. When the non-inverting input exceeds the inverting input, the output goes high. When it falls below, the output goes low. This tutorial covers setting up a basic open-loop comparator in the ECExplain simulator, applying a triangular wave to one input and a DC reference to the other, and then extending the circuit to a Schmitt trigger with hysteresis.
What you will learn
- How to place and configure an op-amp in open-loop comparator mode
- How to apply a triangular wave to the non-inverting input
- How to set a DC reference voltage on the inverting input
- How to read the switching threshold from the output waveform
- How to add positive feedback resistors to create a Schmitt trigger and observe hysteresis
Prerequisites
- Basic understanding of op-amp inputs and output rail behavior
- Familiarity with DC voltage sources and signal generators in the simulator
- Awareness that an ideal comparator output swings between the supply rails
Step-by-step
- Step 1: Place the op-amp blockOpen the Comparator lab from the Analog section. The canvas will have an op-amp symbol with the non-inverting input (V+) at the top left pin and the inverting input (V-) at the bottom left pin. Connect the positive supply rail to +15 V and the negative rail to -15 V using the supply voltage controls in the left panel.Tip: Do not confuse the supply rails with the signal inputs. The rails power the op-amp. The signal inputs carry the waveforms you want to compare.
- Step 2: Connect a triangular wave to V+From the sources panel, drag a Signal Generator onto the canvas and connect its output to the V+ pin of the op-amp. Click the signal generator to open its settings. Set waveform type to Triangle, frequency to 100 Hz, amplitude to 5 V (peak), and DC offset to 0 V. This gives a waveform that swings between -5 V and +5 V.Tip: Set the amplitude to peak value, not peak-to-peak. A peak amplitude of 5 V means the waveform reaches +5 V and -5 V. Entering 10 V as amplitude doubles the swing to +10 V and -10 V.
- Step 3: Set a DC reference on V-Drag a DC Voltage Source from the sources panel onto the canvas and connect it to the V- pin. Click the source and set its voltage to 2 V. This means the comparator will switch its output every time the triangular wave crosses 2 V.Tip: To invert the comparison, swap the connections: put the DC reference on V+ and the signal on V-. The output will then be high when the signal is below 2 V.
- Step 4: Add output probes and runPlace a voltage probe on the output pin of the op-amp and a second probe on the V+ input. Click Run. The waveform panel will show two traces: the triangular input wave and the rectangular output wave. The output should switch between +15 V and -15 V each time the triangular wave crosses 2 V.Tip: If only one trace appears, open the probe manager from the View menu and confirm both probes are listed and checked. Probes that are not connected to a node do not generate a trace.
- Step 5: Measure switching pointsUse the crosshair tool to click on the rising edge of the output waveform. The x-axis value shows the time at which the output switched high. Move the crosshair to the corresponding point on the triangular input trace to read the voltage value there. It should be very close to 2 V. Repeat for the falling edge. Both crossing points should equal the reference voltage.Tip: Small deviations from 2 V at the crossing point are normal because of the finite simulation time step. Reduce the time step in simulation settings to increase crossing accuracy.
- Step 6: Add hysteresis: build a Schmitt triggerAdd two resistors from the components panel. Connect R1 (100 kOhm) between the output pin and the V+ input node. Connect R2 (10 kOhm) between the V+ node and ground. This positive feedback creates two switching thresholds: one for the rising input and one for the falling input. Re-run the simulation and observe that the output now switches at two different voltage levels on the triangular wave.Tip: The upper threshold is V_ref multiplied by (1 + R1/R2) divided by (R1/R2 + 1) adjusted by the output voltage. Use the simulator's parameter sweep feature to see how changing R1 or R2 widens or narrows the hysteresis window.
- Step 7: Observe hysteresis on the output waveformWith the Schmitt trigger configured, run the simulation again. The output waveform should switch from low to high at a voltage higher than 2 V and from high to low at a voltage lower than 2 V. The difference between these two thresholds is the hysteresis width. Use the crosshair on both edges and subtract the two input voltage readings to calculate this width.Tip: Noise immunity in a real system improves when the hysteresis window is wider than the expected noise amplitude. In this simulation there is no noise, but you can add a noise source to the input signal to test how well the Schmitt trigger rejects it.
Expected output
For the basic comparator: the output waveform is a square wave that switches between +15 V and -15 V. Both switching transitions occur exactly where the 100 Hz triangular input wave crosses 2 V. The output duty cycle is less than 50% because the reference is above 0 V, so the input spends less time above 2 V than below it. For the Schmitt trigger with R1 = 100 kOhm and R2 = 10 kOhm: the rising threshold is above 2 V and the falling threshold is below 2 V, producing a visible horizontal separation between the two switching edges on the time axis.
Troubleshooting tips
- Output stays flat at +15 V and never switches: the triangular wave amplitude is lower than the reference voltage. Verify the signal generator amplitude is set to peak, not RMS, and that the peak value exceeds 2 V.
- Output switches but rail voltage is wrong (for example, output only reaches +5 V): the supply rail is set to +5 V instead of +15 V. Click the supply source block and correct the voltage value.
- Output switches at the wrong voltage, not at 2 V: a stray wire is connecting the V- pin to a different node. Check the netlist view to confirm V- is connected only to the 2 V DC source.
- Schmitt trigger does not show two different thresholds: the resistor connections are inverted. R1 must connect output to V+, and R2 must connect V+ to ground, not to V-. Rewiring R1 to V- creates negative feedback, which is an inverting amplifier, not a Schmitt trigger.
- Waveform shows chattering (rapid repeated switching near the threshold): the simulation time step is too large relative to the transition speed. Reduce the maximum time step in the solver settings to below 1 microsecond.