FAQ
TL;DR: “An ideal IC to use for a window comparator is the LM393,” which runs on 2–36 V; add hysteresis to stop chatter. Build two thresholds at 2 V and 3 V, then invert for an outside-band alert. [Elektroda, Anonymous, post #21681598]
Quick Facts
- LM393: dual comparator, open-collector outputs for wire‑OR, typical 2–36 V single-supply operation. [Elektroda, Anonymous, post #21681598]
- Add hysteresis when using op‑amps as comparators to prevent oscillation at the threshold. [Elektroda, Anonymous, post #21681602]
- Comparators are faster and suited to on/off decisions; op‑amps have higher gain but slower response. [Elektroda, Anonymous, post #21681605]
- Protect inputs that may exceed VCC with a ~5.2 V zener to ground and a series resistor (inputs draw nA). [Elektroda, Anonymous, post #21681598]
- LM339/LM393 outputs are current‑limited, allowing direct drive of a large capacitor without a series resistor. [Elektroda, Anonymous, post #21681600]
What is a window comparator (aka window detector)?
A window comparator uses two comparators to signal when a voltage is inside a defined range. You can also keep the two outputs separate to indicate below‑window and above‑window states. Choose the polarity you want by swapping inputs or inverting outputs. [Elektroda, Anonymous, post #21681596]
How do I detect if my signal is outside 2–3 V with a 5 V supply?
Set two thresholds at 2 V and 3 V using a resistor ladder and two comparators. To flag outside‑band, swap each comparator’s +/− inputs or invert the combined in‑window output. This yields separate under‑ and over‑voltage indicators if needed. [Elektroda, Anonymous, post #21681598]
Can I get two separate outputs for <2 V and >3 V?
Yes. Treat them as two independent comparators with separate outputs. Decide whether each output should be active‑high or active‑low by selecting input polarity or adding an inverter stage. [Elektroda, Anonymous, post #21681596]
Which comparator IC is recommended for this job?
Use the LM393 dual comparator. It operates from about 2–36 V, supports open‑collector outputs for wire‑OR, and is well suited to single‑supply designs. “An ideal IC to use for a window comparator is the LM393.” [Elektroda, Anonymous, post #21681598]
Can I use an op‑amp like the MCP602 as a comparator?
You can, but op‑amps are slower and optimized for linear feedback, not threshold detection. Comparators are built for clean on/off decisions and often integrate open‑collector outputs for easy logic combining. Op‑amp outputs usually cannot be wire‑ORed without extra parts. [Elektroda, Anonymous, post #21681605]
Why do my LEDs flicker or chatter near the setpoint?
You are likely seeing oscillation and noise pickup at the threshold. Adjusting presets can inject mains hum, causing rapid toggling. Add hysteresis to introduce a small switching gap and stabilize the transition. “Hysteresis is the way to overcome this.” [Elektroda, Anonymous, post #21681605]
How do I add hysteresis to each comparator?
Add positive feedback from the output to the non‑reference input through a large resistor. This shifts the effective threshold slightly on each transition and eliminates chatter. If the pot network interacts, buffer the pot with a unity‑gain stage before the comparator. [Elektroda, Anonymous, post #21681602]
How should I set the divider for 2 V and 3 V thresholds?
Use a three‑resistor ladder from 5 V to ground to define reference points. For example, pick 2 kΩ, 1 kΩ, and 2 kΩ to create mid‑points matching a 2–3 V window. Feed these nodes to the comparator references and swap inputs to invert logic. [Elektroda, Anonymous, post #21681598]
Do I need input protection if my source might exceed 5 V?
Yes. Clamp the sensed input to ground with an approximately 5.2 V zener and add a series resistor. Comparator inputs draw nanoamp currents, so high‑value series resistors are acceptable and reduce stress during overvoltage. [Elektroda, Anonymous, post #21681598]
Can I wire the outputs together for a single “in‑window” signal?
Yes, with LM393 open‑collector outputs you can tie them together and use a single pull‑up for an in‑window indication. To get an outside‑window signal, invert that line or swap the comparators’ input polarities during design. [Elektroda, Anonymous, post #21681598]
Can LM393/LM339 drive capacitive loads or combine outputs safely?
Their open‑collector outputs are current‑limited, so they can directly charge a large capacitor without a series resistor. This helps with output filtering or simple timing without extra current‑limit parts. It also supports safe wire‑OR logic combining. [Elektroda, Anonymous, post #21681600]
Why did my op‑amp test rig oscillate even with decoupling?
Zero hysteresis invites oscillation near the switching point. Layout and decoupling help, but the fix is intentional hysteresis. Buffer the pot if the feedback perturbs your reference node, then re‑measure the switching levels. [Elektroda, Anonymous, post #21681602]
Can I wire‑OR with op‑amp outputs like with LM393?
Not directly. Op‑amp outputs are push‑pull and will fight each other. Use diodes or resistors to combine, or switch to an open‑collector comparator designed for wire‑OR behavior. [Elektroda, Anonymous, post #21681605]
Do I need rail‑to‑rail inputs for a 5 V window detector?
LM393 inputs handle near‑rail sensing in single‑supply use, which suits a 2–3 V window on a 5 V rail. This eases threshold placement without dual supplies or input shifting networks. [Elektroda, Anonymous, post #21681598]