Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

ATmega328 analog comparator interrupt does not work

2 posters

Go down  Message [Page 1 of 1]

RicardoKers



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:

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
ATmega328 analog comparator interrupt does not work AttachmentAnalog.zip
You don't have permission to download attachments.
(1 Kb) Downloaded 4 times

arcachofo

arcachofo

You are right, interrupt is not triggered in this case.
I will have a look.

RicardoKers likes this post

arcachofo

arcachofo

RicardoKers



Thanks for the help, I will do tests.

arcachofo likes this post

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum