Due Pin Interrupt

Hi.

One problem and two questions. :slight_smile:
Problem:
If I call detachInterrupt(Pin) and after some time attachInterrupt(Pin, ISR, FALLING) the ISR is called immediately. (I have a Pin Falling event in the mean time). It looks like that the interrupt register is not cleared by calling attachinterrupt. It seems that this is only a problem on the DUE...

Question one:
Does anybody have a explained C Code for direct programming of a Pin Change Interrupt ? Because i only need 2 Interrupt inputs and so no need for the slow scanning over 32 Pins, and my C skills are far to bad to understand the WInterrupts.c/.h

Question two:
Is it true that there is only one ISR that can be called with one timer ? (TC4_Handler() for example)
On a Uno it was possible to call 3. (2 with the ORCA and ORCB and one with the timer overflow)

Thx alot for helping / explaining....

Guard your ISR with a volatile boolean, so that you can inhibit its effects when you re-enable
interrupts, then after re-enabling and a short delay set the boolean so that it will work again.

The hardware for pin change/rise/fall detects a change in the internal line (which is not
connected to the pin when the interrupt is disabled - enabling the interrupt connects this
line again, thus a change may be seen even if the pin hasn't changed. This is because
the hardware sensing change is powered down when not in use.

In general using a boolean to guard the body of an ISR is simpler and less error-prone
than enabling/disabling interrupts. However frequently active ISRs affect system
throughput and are best enabled only when needed.

By guard I mean:

ISR .....
{
  // (you might need something here to acknoledge the hardware)
  if (! guard)
    return ;
  // Here is the real code of the ISR
  ...
  ...
}

Hi MarkT.

Thx for the fast reply. The Problem with your solution is, that the two ISR ("connected" to two Pins) might occure at the same time, but the time measurement should be at accurate as possible (I try to make a Stereo Ultrasonic "ears"). , and calling the ISR takes alot of time because of the scanning through the 32 Pins.

The Problem with the high latency is allready discussed (but no realy nice solution...) here:

http://forum.arduino.cc/index.php?topic=157135.0

Because of the Puls the ears are listening to are periodically i switch between the "ears" by disabling the int for the right an listen to the left than disable the left and listing to the right. Because of the unwanted firing after attaching i throw away the first Event, But this is how should I say.... not a nice solution. :slight_smile: (and if the ISR for some reason is not fired after attaching, i ll loose the Event) Is it possible to avoid the powering down ? Or might the pin Change Interrupt implementation be changend with a new Arduino Version or is this a Due Hardware issue that must be accepted as it is ?

Thx for the fast reply. The Problem with your solution is, that the two ISR ("connected" to two Pins) might occure at the same time, but the time measurement should be at accurate as possible (I try to make a Stereo Ultrasonic "ears"). , and calling the ISR takes alot of time because of the scanning through the 32 Pins.

Tough, that's interrupts for you, they queue up for the processor....

I believe you can set Due timer unit(s) to record the timer count when an input changes, which
will give the best resolution - have a search around.