ANALOG COMPARATOR ON THE ATmega8


INTRODUCTION:

The Analog Comparator is a crazy little thing. It compares the value between the AIN0 (Positive) pin and the AIN1 (Negative) pin. If the voltage on the positive pin is higher then the voltage on the negative pin the ACO bit is set. The Analog Comparator can also be set to fire the Input Capture Unit.

Personally, I don't really see the point in using the Analog Comparator when you could use the ADC ... well aside from the fact that the Analog Comparator is much faster then the ADC.


HARDWARE:
ATmega8 - Analog Comparator

Figure 1: Analog Comparator

Not really much to say hardware wise, According to the datasheet the maximum current between the 2 pins is 40mA. The voltage is also limited to to Vcc +0.5 and Vcc - 0.5 like any other pin on the AVR and the difference between the AIN0 and AIN1 pins is Vcc.


THEORY OF OPERATION:
Analog Comparator ATmega8

Figure 2: Analog Comparator Functional Block Diagram

Remember when I said that the Analog Comparator can be used in order to sense the difference between the positive AIN0 pin and the negative AIN1 pin? Well we could also use the ADC0-ADC7 pins as the negative inputs. AIN0 can also be tied to the band-gap reference voltage. This voltage is typically 1.30 volts and can be used in order to test the Analog Comparator.

7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit
SFIOR - - - - ACME PUD PSR2 PSR10

Special Function IO Register

7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit
ACSR ACD ACBG ACO ACI ACIE ACIC ACIS1 ACIS0

Analog Comparator Control and Status Register

ACME ADEN MUX2-0 Analog Comparator Negative Input
0 x xxx AIN1
1 1 xxx AIN1
1 0 000 ADC0
1 0 001 ADC1
1 0 010 ADC2
1 0 011 ADC3
1 0 100 ADC4
1 0 101 ADC5
1 0 110 ADC6
1 0 111 ADC7

Analog Comparator Multiplexed Input

ACIS1 ACIS0 Interrupt Mode
0 0 Comparator Interrupt on Output Toggle
0 1 Reserved
1 0 Comparator Interrupt on Falling Output Edge
1 1 Comparator Interrupt on Rising Output Edge

ACIS1/ACIS0 Settings

The ACME bit within the SFIOR register is used



Cheers
Q