I would like to use the analog comparator without interrupts. In other words, I want to poll the output at a time of my choosing. In the sketch below, that would be each time through the loop. However, I can't seem to get the comparator output to toggle. Can you tell me what I am doing wrong?
void setup()
{
// Turn off ADC, turn on Analog comparator and select the mux
PRR &= ~(1<<PRADC);
ACSR &= ~(1<<ACD) & ~(1<<ACIE) & ~(1<<ACIC);
ACSR |= (1<<ACBG) | (1<<ACO);
ADCSRB |= (1<<ACME);
ADCSRA &= ~(1 << ADEN);
// 0000 selects ADC0 channel
ADMUX &= ~(1<<MUX3) & ~(1<<MUX2) & ~(1<<MUX1) & ~(1<<MUX0);
DIDR0 |= (1<<ADC5D)|(1<<ADC4D)|(1<<ADC3D)|(1<<ADC2D)|(1<<ADC1D);
DIDR1 |= (1<<AIN1D) | (1<<AIN0D);
DDRD=0xFF;
PORTD=0xFF;
}
void loop()
{
if (ACO)
PORTD=0xFF;
else
PORTD=0x00;
}
I am using an ATMEGA328p in a standalone application.