36.4.3.3 Window Mode

Two comparators can be configured to work together in Window mode. In this mode, a voltage range (the window) is defined, and the comparators indicate whether an input signal is within this range or not. Window mode is enabled by writing to the Window n Enable bit in the Window Control register (WINCTRL.WENn).

To operate in Window mode, the two comparators must be configured as shown in the following figure by writing to the Positive and Negative Input Selection bit fields in their respective Comparator n Comparator Control A registers (COMP[n].COMPCTRLA.MUXPOS/MUXNEG). For Window mode n, the even comparator (COMP(2n)) defines the lower limit and the odd comparator (COMP(2n+1)) defines the upper limit of the window. Note that the two comparators must use the same positive input source.

The state of the window function is available in the Window n State bit field in the Status register (STATUS.WINSTATEn). The state can be:
  • Above window - the input signal is above the upper limit
  • Inside window - the input signal is between the lower and upper limits
  • Below window - the input signal is below the lower limit
The Window mode can be configured to request interrupts on one of the following conditions by writing to the Window n Interrupt Selection bit field in the Window Control register (WINCTRL.WINTSELn):
  • Above window - the interrupt is issued on the edge when the input signal goes above the upper limit
  • Inside window - the interrupt is issued on the edge when the input signal goes between the lower and upper limits
  • Below window - the interrupt is issued on the edge when the input signal goes below the lower limit
  • Outside window - the interrupt is issued on the edge when the input signal goes below the lower limit or above the upper limit

The window n interrupt is enabled by writing to the Window n Interrupt bit in the Interrupt Enable Set register (INTENSET.WINn). Once enabled, the corresponding interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG.WINn) will be set when the input signal crosses one of the limits according to the configuration. For example, if WINCTRL.WINTSELn is configured to ABOVE, an interrupt will be generated when the signal exceeds the upper window limit, and INTFLAG.WINn will be set. If the interrupt flag is cleared while the signal remains above the window, the flag will not be set again until the signal falls below the upper limit and then exceeds it once more. The window n interrupt is disabled by writing to the Window n Interrupt bit in the Interrupt Enable Clear register (INTENCLR.WINn).

In addition, the Window mode can generate an event whenever the input signal is inside the window. The window n event has no configuration and is enabled by writing to the Window n Event Output Enable bit in the Event Control register (EVCTRL.WINEOn).

Note: The individual comparator outputs, interrupts and events continue to function normally during Window mode.
Figure 36-3. Comparators in Window Mode n