Go Down

Topic: Analog Comparator on Mega 2560 (Read 2064 times) previous topic - next topic

RobertMatania

Mar 14, 2013, 12:24 pm Last Edit: Mar 14, 2013, 01:02 pm by Bob95 Reason: 1
I've been successfully testing the analog comparator on an Arduino Uno  using pin 7 (AIN1) and setting the positive input of the comparator to use the internal voltage:
Quote
pinMode(7,INPUT);
ACSR = B01011011; // comparator interrupt enabled and tripped on falling edge.


Quote

ISR(ANALOG_COMP_vect)
{
// Interrupt code here
 }
}


I now want to move this code to a Mega 2560.  Looking at the pin mapping of the ATmega2560 it appears to use pin 5  for AIN1.

Will the comparator work the same with the Mega 2560 by just changing the input pin from 7 to 5?

Thanks in advance

pylon

Quote
Will the comparator work the same with the Mega 2560 by just changing the input pin from 7 to 5?


Yes, I would expect that.

Code: [Select]
ACSR = B01011011; // comparator interrupt enabled and tripped on falling edge.

According to the datasheet your comment is wrong. The combination of 1 1 for ACIS0 and ACIS1 triggers an interrupt on a rising (and not falling) edge.

RobertMatania

Ok thanks. I'm going to try it this weekend.
Your'e right about the comment. The code was modified during trials but not the comment.

Go Up