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.
9 years, 1 month ago.
InteruptIn pulse
Hello,
There is simple code
#include "mbed.h" Serial pc(USBTX, USBRX); InterruptIn button(p10); void flipUp() { pc.putc('1'); } void flipDown() { pc.putc('0'); } int main() { button.rise(&flipUp); button.fall(&flipDown); while (1) { } }
I am monitoring changes (rise, down) on P10 and print 1 or 0 on port.
When I read in the other side I got for example 11010111101011 How it is possible combination 1111. Always should be 010101010101... or 101010101010101...
Regards, Pranas
1 Answer
9 years, 1 month ago.
How fast are you pressing those buttons? And especially due to switch bouncing it is possible I guess. The issue is that there is only a single hardware interrupt for rising and falling edges. Due to bouncing (or whatever you are doing with it), you can get very fast interrupts after each other (although I wouldn't have guessed that fast). So apparantly the rising edge interrupts are handled first. When it is done handling one interrupt, it checks if there are more interrupts. If the next rising/falling interrupt set is already waiting, it will first handle the next rising edge. After this is done, it will yet again check if there are still other interrupts to be handled, and if there is another rising/falling edge pair, it will again do the rising edge first. Since the hardware only 'stores' a single interrupt in the queue, only a single falling edge interrupt is handled in the end.