The simple comparator circuit has one inherent problem: it can only tell
us if one of the input voltages is higher than the other.
But what if you needed a circuit that tells us if a signal is within a
range of values? you would need a circuit that tells you if the signal
is higher than a minimum and if it also is lower than the maximum. The
problem itself hints at the solution.
For a window comparator, we need one simple comparator set up just like
the previous circuit: use the non inverting as reference and the
inverting input as the signal entry. This comparator will set the
maximum; if the signal goes higher than the reference the output will go
negative, signaling an out of range (if we consider positive to be in
range).
Another comparator is set by switching the reference and signal inputs,
connecting the reference to the inverting input and the signal to the
non inverting. If the signal is lower than the reference, the output
will go negative, again indicating an out of range; this comparator sets
the minimum.
When both opamp outputs go positive, it means that the signal is below
the maximum and above the minimum, in other words, the signal is within
the window of voltages you have defined.
There's one thing to consider with this configuration, when the signal
is out of range, one of the opamps will go full negative (virtual
connection to negative supply) and the other will be full positive
(virtual connection to positive supply). This causes a short circuit
condition that needs to be avoided as it could cause damage to the
circuit or the supplies.
One way to protect from this condition is use diodes configured as the
logic AND gate. This simply means to connect two diodes at the opamp
outputs, connect both their anodes together and to the positive supply
via a high value resistor.
What this does is that only when both opamps are at full positive
(diodes' conduction blocked, basically disconnecting the opamps from the
rest of the circuit) will the output be positive, held by the high
value resistor.
When either opamp goes negative, the diode connected to it will be
forward biased, basically connecting the output to ground; the other
opamp is blocked from connecting to the output by the reverse biased
diode (positive opamp output connected to cathode, negative to anode)
and no short circuit condition occurs.