ADC Window Comparator

In Window Comparator mode, the device can detect if the ADC result is below or above a specific threshold value. This is useful when monitoring a signal that is required to be maintained in a specific range, or for signaling low battery/overcharge, etc. The Window Comparator can be used in both Free Running mode and Single Conversion mode. In this example the Window Comparator is used in Free Running mode, because a monitored signal requires continuous sampling, and the Free Running mode reduces the CPU load by not requiring manual start for each conversion.

For this example, a low threshold is set in the ADC0.WINLT register.
Figure 1. ADC-WINLT - set Low Threshold
ADC0.WINLT = WINDOW_CMP_LOW_TH_EXAMPLE;
The Conversion Window mode is set in the ADC0.CTRLE register:
Figure 2. ADC0.CTRLE - set Window Comparator mode
ADC0.CTRLE = ADC_WINCM_BELOW_gc;
If the ADC result is below the set threshold value, the WCOMP bit in the ADC0.INTFLAGS register is set by the hardware.
Figure 3. ADC0.INTFLAGS - hardware-set WCOMP bit
The user must clear that bit by writing ‘1’ to it.
ADC0.INTFLAGS = ADC_WCMP_bm;
Tip: The full code example is also available in the Appendix section.