I am having an issue with correct interrupt behaviour on a Teensy 4.1. I have boiled it down to a small piece of code.
Basically I am attaching an interrupt to a RISING edge of a pin. Using a function generator I send a block of 10 pulses to the pin. I have confirmed with an oscilloscope that the pin sees 10 pulses. However, the interrupt routine is called 16 times!
Aldr,
thanks for the reply. Unfortunately I do not believe this to be the case. One of the scope images is from the actual pin on the teensy and as you can see it is essentially a perfect waveform (which I would expect given it was a signal generator source). Also the underlying issue has appears on all of the 15 or so systems we have built with this hardware. So virtually certain this is a software issue.
In the near-term I did exactly what you suggested which is to change the interrupt to "CHANGE" rather than "RISE" and added debounce code.
However I believe this may be a fundamental issue in the underlying library this I would prefer to make sure Paul sees it.
Yes, intersting idea. When I did the triangle waveform I got a huge number of interrrupts, as I modified the duty cycle to give a sharper rising edge the number of interrupts decreased roughly in proportion.
Based on this my guess is that the low level interrupt gets released and immediately fires again if the slope is still rising. Wonder if this is a hardware issue in the iMX or a driver problem.
Aldr,
Generally on-board with making ISR's as short as possible, but in this case its almost the opposite where the ISR is so fast that the edge of the signal is still rising which causes another interrupt to fire because the first one finishes while the signal edge is still rising. See the discussion below on the triangle wave form.