Fig. 2: Bit Configuration of SFIOR in Analog comparator of AVR Microcontroller
Fig. 4: Bit Configuration of ADMUX in Analog comparator of AVR Microcontroller
Fig. 5: Bit Setting to select ADC channel as negative input pins in AVR’s Anaog Comparator
Project Source Code
###
//Program to use inbuilt analog comparator of AVR microcontroller #include<avr/io.h> #include<util/delay.h>
int main()
{
DDRD=0x07; // set PD0, PD1 and PD2 as output pin
ACSR=0x00; //to set ACO bit as zero.
ADCSRA&=~(1<<ADEN); // to disable ADC
while(1)
{
SFIOR|=(1<<ACME); // bit is set to select the ADC channel
ADMUX=0x00; // ADC0 channel is selected
_delay_us(1); // delay for synchronization
if(bit_is_set(ACSR,ACO)) // if bit is set to 1
PORTD|=(1<<PD0); // send one to PD0 bit
else // if bit is set to zero
PORTD&=~(1<<PD0);
SFIOR|=(1<<ACME);
ADMUX=0x01; // ADC1 channel is selected
_delay_us(1);
if(bit_is_set(ACSR,ACO))
PORTD|=(1<<PD1);
else
PORTD&=~(1<<PD1);SFIOR&=~(1<<ACME); // to select AIN1 pin as negative input
_delay_us(1);
if(bit_is_set(ACSR,ACO))
PORTD|=(1<<PD2);
else
PORTD&=~(1<<PD2);
}
}
###
Circuit Diagrams
Project Components
Project Video
Filed Under: AVR
Filed Under: AVR
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.