3

I have an Arduino Uno. I've been reading about pin change interrupts, and one vector covers the analog pins. However, is it possible to trigger interrupts using analog pins as analog inputs (not digital)?

I actually want to analogRead() a potentiometer inside the ISR.

This is my code so far, http://pastebin.com/ykpp78GB

And my circuit is just two potentiometers connected to pin A0 and A1.

  • You can use a pin change interrupt on an analog input, and you can read an analog input inside an ISR. But using the same pin both as an interrupt trigger and an analog input makes little sense, unless you are using the analog comparator (not pin change) interrupt. You should start by telling us what you actually want to achieve. – Edgar Bonet Apr 25 '17 at 12:12
5

It is not possible to trigger an interrupt when an analog input has reached a threshold on any tinyAVR or megaAVR. It is possible to trigger an interrupt when an analog input of an AVR XMEGA with the event system.

It is possible to use the built-in analog comparator on the ATmegaXX8 and ATmegaXXU4 in the Uno, Leonardo, and comparable boards to trigger an interrupt when an internal or external threshold has been met. It is only possible to compare to an internal threshold on the Mega, Mega 2560, or comparable boards since the pin for the external threshold is not broken out, although actual breakout boards for the ATmegaXXX0/1 will have the pin broken out.

In all cases, examine the appropriate datasheet (in particular the "Analog Comparator" section) as well as the pin mappings on the Arduino website for full details.

  • What I want to do is to analogRead() a pot inside the ISR. I have an Arduino UNO. – whitenoisedb Dec 5 '14 at 2:10
  • Well, I'm thinking that maybe I should read those analog values inside a timer interrupt. Considering I'm using some delays inside the loop() function. – whitenoisedb Dec 5 '14 at 2:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.