I have the same question about nested interrupts. Is there a stack? If so, how deep is it? If not a stack, is there a queue?
On your pulse problem, I'm doing something similar, but made my own "counter". Set a "ticker" up to call back every 5 us. This callback just increments a counter. Now set another interrupt based on the pulse train level (rising or falling). The callback for this one gets the current counter value and resets it. The advantage is that you're not resetting the timer, so you never miss a pulse. The disadvantage is that the maximum (minimum?) resolution is 5 us.
I put in some code to make sure the counter didn't ovrerun (not needed - it takes forever using a unsigned ctr), and some more code to make sure that the increment didn't get stomped by a reset or vice versa. However, the interference never seems to happen. Also, If you decrease the call back to below 5 us, it gets lost inside the counter increment routine. Based on these behaviors, I suspect that an interrupt routine can't get interrupted by another, but they queue up somehow.
Perhaps someone else knows how nested interrupts actually behave.
--stephen
I have been trying to measure the time between 2 pulses on a serial pulse train. see code below...
#include "mbed.h"
Serial pc(USBTX,USBRX);
Timer timer;
InterruptIn event(p16);
int end;
void trigger() {
end = timer.read_us();
timer.reset();
timer.start();
}
int main() {
event.rise(&trigger);
while(1){
pc.printf("Time = %d us \r",end);
wait(0.2);
}
}
This works fine, until the point where the time between pulses <90 us. At this point the whole thing falls apart. Is this something to do with the IRQ handler's recovery time?
Is there a way round this?