30.3.2.7 Window Comparator Mode
The ADC can raise the WCMP flag in the Interrupt and Flag (ADCn.INTFLAGS) register and
request an interrupt (WCMP) when the result of a conversion is above and/or below certain
thresholds. The available modes are:
- The result is under a threshold
- The result is over a threshold
- The result is inside a window (above a lower threshold, but below the upper one)
- The result is outside a window (either under the lower or above the upper threshold)
The thresholds are defined by writing to the Window Comparator Threshold (ADCn.WINLT and ADCn.WINHT) registers. Writing to the Window Comparator mode (WINCM) bit field in the Control E (ADCn.CTRLE) register selects the conditions when the flag is raised and/or the interrupt is requested.
Assuming the ADC is already configured to run, follow these steps to use the
Window Comparator mode:
- Choose which Window Comparator to use (see the WINCM description in the ADCn.CTRLE register), and set the required threshold(s) by writing to ADCn.WINLT and/or ADCn.WINHT register(s).
- Optional: Enable the interrupt
request by writing a ‘
1
’ to the Window Comparator Interrupt Enable (WCMP) bit in the Interrupt Control (ADCn.INTCTRL) register. - Enable the Window Comparator and select a mode by writing a non-zero value to the WINCM bit field in the ADCn.CTRLE register.
When accumulating multiple samples, the comparison between the result and the threshold will happen after the last sample was acquired. Consequently, the flag is raised only once, after taking the last sample of the accumulation.