Analog Comparator Interrupt on Arduino

Discussion in 'Embedded Systems and Microcontrollers' started by sirch2, Feb 21, 2013.

  1. sirch2

    Thread Starter Well-Known Member

    Jan 21, 2013
    1,008
    351
    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.
     
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    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....
     
  3. sirch2

    Thread Starter Well-Known Member

    Jan 21, 2013
    1,008
    351
    Many thanks tshuck, that's really useful info.
     
Loading...