Not all AVR microcontrollers come with built-in ADC. But there is a way of building one using an on-chip comparator and timer counter. The comparator compares voltages on +v (Ain0) and -v (Ain1) inputs. If the Ain0 pin’s voltage is greater than in Ain1, then the comparator ACO is set to ‘1’ otherwise, it is ‘0’. Bellow you see AVR comparator circuit. The working of this ADC is as follows. First, PB0 is set to ‘0’ to discharge the capacitor. Then PB0 is programmed as input with no pull-ups, and Timer is started to count.