AVR analog comparator and avr-gcc example
An Analog comparator is a pretty simple peripheral, but it can give big benefits. Comparator module is included in all Mega series of AVR microcontrollers. Simply speaking, Comparator allows comparing voltage values applied to two pins of microcontrollers. The comparison results are a logical level, which can be read by the program(ACO- Analog Comparator Output bit). There is also the ability to generate an interrupt, which depends on the comparator resulting level. And more- timer T1 can capture this level what allows measuring the signal length of analog signals. To use pins as comparator inputs, they must be prepared and configured as input(DDRx=0), and pull-up resistors must be disconnected (PORTx=0). In some models like Atmega48x/88x/168x, Atmega165x, Atmega325x,3250x,645x/6450x, and Atmega640x/128x/1281x/2560x/2561x, there is the ability to disconnect digital buffers of AIN0 and AIN1 pins that allows the use of these pins only for analog signal input – this minimizes overall power consumption.