Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 6 months ago.
Cannot attache ISRs to both rising and falling edges for the same pin
Hello,
I have noticed an issue:
When I attach interrupt service routines to BOTH rising and falling edges on the same pin, none of the service routines get ever called. For reference, the same thing works fine in Nucleo platform.
Having this feature is nice when a simple method for calculating a pulse width is needed. The following code shows an example. A periodic signal is generated using PWM output which can then be physically connected to the interrupt pin (PTC7 in this example).
I have tried it with different pins on Teensy and noticed the same issue. However, if only one of the rising or falling interrupts is used, system works fine.
#include "mbed.h" DigitalOut myled(LED1); void rising() { myled = 1; } void falling() { myled = 0; } int main() { PwmOut mypwm(PTC2); mypwm.period_ms(10); mypwm.pulsewidth_ms(5); InterruptIn interrupt(PTC7); interrupt.rise(&rising); interrupt.fall(&falling); while(true); }
Notice: in the above code I have used 10 ms pulse (i.e. 100 Hz). Blinking at this rate is probably too fast to be easily seen by eye. However, Teensy seems to have another bug that makes PWM outputs two times slower than what they are programmed for so in reality the pulse generated by this code will 50 Hz. Keep it mind in case that problem gets fixed in Teensy!