6 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 a manual start for each conversion.

For this example, a low threshold is set in the ADC0.WINLT register.
Figure 6-1. ADC-WINLT - Set the Low Threshold
ADC0.WINLT = WINDOW_CMP_LOW_TH_EXAMPLE;
The conversion Window mode is set in the ADC0.CTRLE register.
Figure 6-2. ADC0.CTRLE - Set the 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 6-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.

An MCC generated code example for AVR128DA48, with the same functionality as the one described in this section, can be found here: