Comparators, Schmitt Triggers & Window Detectors
Turning analog into a clean yes/no. Learn comparator vs op-amp, open-loop operation, output types (push-pull, open-drain/collector), propagation delay and overdrive, why noise causes chattering, hysteresis with positive feedback (inverting and non-inverting Schmitt triggers), threshold design with a reference, window comparators, zero-crossing detectors, latched comparators, and practical layout/bypassing — with Python designing Schmitt thresholds and pull-up timing.
A comparator decides which of two voltages is larger and outputs a logic level. It is the simplest analog-to-digital converter and appears in over-voltage protection, battery monitors, zero-crossing detectors, PWM generators and the heart of every ADC.
Noise near the threshold makes a simple comparator chatter; positive feedback (hysteresis) creates two thresholds and clean transitions.
An analogy
A Schmitt trigger is like a thermostat with a dead band: the heater turns on at 19 °C and off at 21 °C, so small temperature wobbles around 20 °C don't make it click on and off constantly.
Comparator basics
Output is high when V₊ > V₋ and low otherwise. Comparators run open-loop (or with positive feedback) and are optimised for speed, fast recovery from saturation and logic-compatible outputs. Op-amps can be used as slow comparators but may have slow saturation recovery, phase reversal and input protection diodes that clamp differential inputs.
Output types and timing
Specifications to check:
- Push-pull output — fast, drives logic directly
- Open-drain/open-collector — wired-OR, level translation, needs pull-up
- Propagation delay falls with more overdrive (datasheets specify at 5–100 mV)
- Input offset and bias current shift the threshold
- Latch-enable inputs capture the decision at a clock edge (ADCs)
Hysteresis design
Choose the centre threshold and the hysteresis (larger than peak-to-peak noise, but small enough for the required accuracy). Positive feedback through R₂ sets the hysteresis; the reference and divider set the centre. Hysteresis also speeds up transitions on slow inputs because the feedback regenerates the switching edge.
Practical pitfalls
Fast comparators oscillate during slow transitions without hysteresis, especially with poor layout: keep input traces short, separate output from input, use a ground plane and bypass supplies close to the pins. Remember input common-mode range, the effect of source impedance on hysteresis (it adds to R₁), and metastability in latched comparators for sampled systems.
Formulas
- Inverting Schmitt (with V_REF):
V_TH = V_REF·R₂/(R₁ + R₂) + V_out·R₁/(R₁ + R₂) for V_out = V_OH, V_OL - Hysteresis:
V_H = (V_OH − V_OL)·R₁/(R₁ + R₂) - Non-inverting Schmitt (V_REF = 0):
V_TH± = ∓V_out·R₁/R₂ - Open-drain rise time:
t_r ≈ 2.2·R_pull-up·C_load - Window comparator:
Output true when V_L < V_in < V_H
Worked example: Symmetric Schmitt
Given: Non-inverting, ±12 V output, R₁ 10 kΩ, R₂ 100 kΩ, V_REF 0
Find: Thresholds.
- ±12 × 10/100
Answer: ±1.2 V (2.4 V hysteresis)
Worked example: Hysteresis
Given: Output 0–3.3 V, R₁ 1 kΩ, R₂ 100 kΩ
Find: V_H.
- 3.3 × 1/101
Answer: ≈ 33 mV
Worked example: Pull-up rise time
Given: 10 kΩ, 20 pF
Find: t_r.
- 2.2 × 10k × 20p
Answer: 440 ns
Inverting Schmitt trigger with reference
+5 V
│
V_in ──────────┤− │
│ ▷───┬──── V_out (0 / 5 V)
V_REF 2.5 V ─R₁─┤+ │
10k │ │
└─R₂──┘ 100k (positive feedback → hysteresis)The + input is a divider between V_REF and the output. When the output is high, the threshold moves up; when low, it moves down. The input must cross past the new threshold to switch back — noise smaller than the hysteresis can't cause chattering.
Schmitt thresholds and output timing
# Comparator with hysteresis (Schmitt trigger) thresholds, and response time budget
Vcc, R1, R2 = 5.0, 10e3, 100e3 # single supply, rail-to-rail output
Vref = 2.5
# Inverting Schmitt with reference: thresholds from divider between Vref and output
Vth_hi = Vref * R2 / (R1 + R2) + Vcc * R1 / (R1 + R2)
Vth_lo = Vref * R2 / (R1 + R2)
print(f"inverting Schmitt: upper threshold {Vth_hi:.3f} V, lower {Vth_lo:.3f} V, hysteresis {(Vth_hi-Vth_lo)*1e3:.0f} mV")
# Noise immunity: 50 mV pp noise on a slow ramp -> multiple transitions without hysteresis
print(f"hysteresis {(Vth_hi-Vth_lo)*1e3:.0f} mV > 50 mV noise -> single clean transition")
# Open-drain comparator pull-up: 10 pF load, 4.7k -> rise time
print(f"open-drain rise time 2.2RC = {2.2*4.7e3*10e-12*1e9:.0f} ns with 4.7k and 10 pF")
# inverting Schmitt: upper threshold 2.727 V, lower 2.273 V, hysteresis 455 mV
# hysteresis 455 mV > 50 mV noise -> single clean transition
# open-drain rise time 2.2RC = 103 ns with 4.7k and 10 pFWith R₁ = 10 kΩ and R₂ = 100 kΩ the thresholds sit at 2.27 V and 2.73 V — 455 mV of hysteresis, comfortably more than 50 mV of noise. Open-drain outputs are slow to rise: 4.7 kΩ and 10 pF gives ~100 ns; use push-pull outputs or smaller pull-ups for speed.
Common mistakes
- Wrong: No hysteresis on slow or noisy inputs. — Right: Add positive feedback.
- Wrong: Using an op-amp as a fast comparator. — Right: Use a comparator with proper output and recovery.
- Wrong: Forgetting the pull-up on open-drain outputs. — Right: Add a pull-up sized for speed and current.
Applications
- Battery protection: Under/over-voltage cut-offs.
- Zero-crossing: Triac firing and frequency measurement.
- PWM: Comparing a ramp with an error voltage.
- ADCs: Flash and SAR converters.
Key takeaways
- Comparators are open-loop 1-bit ADCs.
- Hysteresis = positive feedback; prevents chatter.
- Check output type, delay vs overdrive, input range.
- Window comparators detect in-range signals.
Going further
- Latched comparators & metastability: Sampling decisions in ADCs.
- Relaxation oscillators: Schmitt + RC timing.
- High-speed comparators: LVDS/ECL outputs, sub-ns delay.