Hello, I'm having trouble getting the analog comparator interrupt to work on the ATmega328. In the real circuit the program works and the interrupt is executed, but in SimulIDE apparently the interrupt never occurs.
The test circuit used is attached and has only one adjustable voltage source at the input of the comparator (PD7).
Pin PB5 should change state depending on whether the external voltage is greater or less than the internal reference voltage.
I tested it with an external reference and that didn't work either.
The program used is:
The test circuit used is attached and has only one adjustable voltage source at the input of the comparator (PD7).
Pin PB5 should change state depending on whether the external voltage is greater or less than the internal reference voltage.
I tested it with an external reference and that didn't work either.
The program used is:
- Code:
#include <avr/io.h>
#include <avr/interrupt.h>
int main(void)
{
DDRB |= (1<<PB5);
ACSR = (1<<ACBG) | (1<<ACIE);
DIDR1 = (1<<AIN1D) | (1<< AIN0D);
sei();
while (1)
{
}
}
ISR(ANALOG_COMP_vect)
{
if (ACSR&(1<<ACO))
{
PORTB &= ~(1<<PB5);
}
else
{
PORTB |= (1<<PB5);
}
}
- Attachments
- Analog.zip
- You don't have permission to download attachments.
- (1 Kb) Downloaded 4 times