I am working with an Arduino Mega 2560. When I was looking to the subreddit for Arduino, I came across some projects which used the ISR(PCINT1_vect).
FYI, I have been working with the PIC16F1829 microcontroller so I have experience with microcontrollers and interrupts.
The appearance of this interrupt service routine made me wonder if the way of doing interrupts using attachInterrupt() and detachInterrupt() is the only way using the Mega2560. As I have (will have) around eight ping sensors, I want to handle them using interrupts (and so keeping my loop a bit cleaner). I found out that I can not attach an interrupt on both the rising and falling edge at the same time.
So I decided to first attach the rising edge interrupt, when I handled that interrupt, I detach it and attach the falling edge interrupt, and vice versa. This way I am able to measure the length of an pulse and thus get the time.
I can do this for one, and for more when I use a multiplexer (74HC238). But I was wondering if using the ISR(PxINTx_vect) routine I could use more pins with interrupts than the documentation suggests?
That solves at least the ugly code of detaching-attaching
You can use pin change interrupts on any pin that supports them, to increase the number of interrupts that you can deal with. The SoftwareSerial reference page shows the pins on the Mega that support pin change interrupts (and the SoftwareSerial code shows how they can be used).
So. The pins listed in the AttachInterrupt() documentation and the pins in the SoftwareSerial are the pins available for interrupts. The SoftwareSerial documentation describes the pins I can use for the CHANGE interrupt handle type.
In what situation do I use the ISR(..) { ... } routine then?
mbeentjes:
So. The pins listed in the AttachInterrupt() documentation and the pins in the SoftwareSerial are the pins available for interrupts. The SoftwareSerial documentation describes the pins I can use for the CHANGE interrupt handle type.
In what situation do I use the ISR(..) { ... } routine then?
The problem is (/was) that I have multiple ping sensors which I have connected to the Mega. I want to use interrupts to measure the length of the returning pulse (which corresponds to the measured distance). And as I am planning to work to use around eight ping sensors.
But with the use of ISR I see that I will have enough with one interrupt vector. With that said, using the ISR solve the problem.
And to get my head clear: I can use the ISR and corresponding vectors in my code to use every pin.