In my experience, window detection is a common requirement in embedded systems, particularly sensor-based devices. The general idea is as follows: You have an analog signal that is constantly monitored by interface or control circuitry. The state of this signal is evaluated according to a range. In some cases, the signal is considered normal if it is within a specified range. In other cases, the signal is normal when it is outside of the range. In either case, the range is referred to as a window, and these two scenarios could be described, respectively, as “in-window” and “out-of-window.”
An example of a window detection system incorporated into an MCU's ADC module, from this datasheet.
An example of an “in-window” system is temperature sensing. Human beings, animals, and even equipment usually prefer temperatures that are not too high or too low. Thus, temperature-monitoring systems often need to take some sort of action when the temperature exceeds a maximum value or drops below a minimum value. In other words, the control circuitry must be alerted when the temperature is not in the specified window. Another example is a supply-voltage monitor that takes some sort of action when a supply goes above the maximum allowable voltage or below the minimum allowable voltage.
“Out-of-window” implementations are less common, and I’m having a bit of trouble thinking of a good example. Ordered systems—biological systems, chemical systems, mechanical systems, etc.—are typically sensitive to extremes rather than to parameters that fall into a limited range. One possibility is discrimination, i.e., eliminating irrelevant data because it clearly is not produced by something that the system is concerned about. I’m thinking here of something like a scale that only needs to analyze the weight of certain types of objects. If the measured weight is outside of the specified window, the object is assumed to be irrelevant and no further analysis is performed. Another idea is a system that must attenuate a variable-frequency signal if it approaches a certain frequency. Maybe this frequency is present elsewhere in the system and must be protected from any kind of interference. A frequency-to-voltage converter in conjunction with a window detector could be used to alert the system whenever the signal’s frequency is not outside of the specified window.
Analog vs. Digital
I am very familiar with microcontroller-based window detection because I have frequently used MCUs that offer this feature. It is integrated conveniently into the ADC module and can fire an interrupt when the digitized value exceeds the user-defined upper or lower threshold. I imagine that this functionality is present in numerous mixed-signal microcontrollers, and even when it is not you could easily accomplish the same thing via firmware.
There is certainly nothing wrong with this approach, especially if you already have a microcontroller in the design. But the endless drive to reduce size, cost, and power consumption requires engineers to be flexible and to consider new (or old) ways of meeting system requirements. Window detection can be easily accomplished with two op-amps, a few passives, and two diodes. This is a compact, inexpensive implementation that could come in handy in designs that 1) don’t need a microcontroller or 2) have a bare-bones microcontroller that lacks the necessary functionality.
Here is the basic circuit:
This one won’t win any complexity awards, but as we’ll see later it might not be quite as straightforward as you think. Basic operation is as follows: The detection window has an upper threshold and a lower threshold, as indicated in the diagram. If the input voltage is greater than the upper threshold, U1’s output saturates at the positive supply rail. If the input voltage is less than the lower threshold, U2’s output saturates at the positive rail. If the input voltage is between the two thresholds, both op-amp outputs saturate at the negative rail. Thus, we have a logic-high output whenever the input voltage is outside the window and a logic-low output when it is within the window.
The diodes provide the required logical-OR functionality: If either output is logic high, current can flow through the diode (and the load) to ground, and the diodes also block the short-circuit current that would otherwise flow from one output to the other when the two op-amps have different output states (this occurs whenever the input voltage is outside the window).
Here is the LTspice implementation:
I’m using rail-to-rail op-amps, but considering that this is a comparator circuit, not an amplifier, you could certainly use comparators instead.
Here’s an output waveform:
As expected, the output is logic low only when the input voltage is between the two thresholds.
One thing to keep in mind is that the output voltage applied to the load is significantly lower than the supply voltage, as you can see in the plot. This is, of course, due to the diode’s voltage drop. You could mitigate this problem by using a diode with lower forward voltage, but if you really need an output voltage that swings all the way to the positive rail, you could use a typical CMOS two-input OR gate instead of the diodes.
Also, with this circuit the input-to-output relationship is fixed—i.e., the output is always low when the input is within the voltage window. If the downstream circuitry requires the opposite behavior, an inverter is called for.
The third complication is somewhat subtle. The diode arrangement on the output is fundamentally different from a typical CMOS push-pull output stage. The latter drives the output by using a FET to establish a low-impedance connection to VDD or ground, whereas the former relies upon current flowing through a forward-biased diode. This leads to troublesome behavior in two situations. First, the circuit doesn’t work properly when a very high load impedance leads to very low diode current. If I change the load impedance to 10 MΩ, the output looks like this:
Second (and this is related to the first point), when the op-amp outputs are low, the diode doesn’t provide a low-impedance connection to ground. Rather, it becomes an open circuit. This means that the output is floating rather than grounded, and consequently the output needs a pull-down resistor if the downstream circuitry doesn’t provide a resistive path to ground.
In this article we discussed a pleasant little circuit that, though simple, can potentially eliminate the need for a microcontroller (and its related support circuitry and development software). The circuit has some limitations, but these are easily remedied. Even with the addition of an OR gate or inverter, the overall solution size could be quite small.
If you want to save yourself a few minutes by downloading my LTspice schematic, feel free to click on the orange button.