Analog Comparator Interrupt on Arduino

Thread Starter

sirch2

Joined Jan 21, 2013
1,037
Hi,


I've had a read around this subject and want to confirm that my understanding is correct, I am using an Arduino board that has an ATMega 1280 chip.

The ATMega datasheet seems to indicate that the Analog Comparator can be set up to trigger an interrupt when the voltage on the A1 pin exceeds the voltage on the A0 pin. So presumably if I connect a potentiometer to A0 I can set the trigger voltage to a suitable threshold (I'm looking at something that swings from around 2.5v to 1v)?

Is a pot. the best way of setting the threshold voltage or is there a better way?

I always struggle converting what the datasheet says into practical ARDUINO code. Any hints as to what the actual codes looks like would be greatly appreciated.
 

tshuck

Joined Oct 18, 2012
3,534
Hi,


I've had a read around this subject and want to confirm that my understanding is correct, I am using an Arduino board that has an ATMega 1280 chip.

The ATMega datasheet seems to indicate that the Analog Comparator can be set up to trigger an interrupt when the voltage on the A1 pin exceeds the voltage on the A0 pin. So presumably if I connect a potentiometer to A0 I can set the trigger voltage to a suitable threshold (I'm looking at something that swings from around 2.5v to 1v)?

Is a pot. the best way of setting the threshold voltage or is there a better way?

I always struggle converting what the datasheet says into practical ARDUINO code. Any hints as to what the actual codes looks like would be greatly appreciated.
What you want depends on how stable of a reference you need. A potentiometer is fine for most hobbyist projects, but be aware that this will change with supply voltage, temperature, among others, so don't expect a solid 1V reference. The other route is that of a voltage reference, a device designed to give 1V always, well, provided the supply voltage is greater than the set voltage reference.

As far as the Arduino code goes, I'm afraid I can't help. I'm sure there are sources out there that can help, though...
The Arduino website appears to be down right now, but here's a link to peruse:
http://www.bot-thoughts.com/2010/09/arduino-avr-analog-comparator.html
This is done with a 328p, so the registers will, probably, be different, but the idea's there....
 
Top