level sensitive interrupt trigger

21 Jul 2010


I'd like to use interrupt routine to monitor an input signal, for example:

if (input)

    led =1;


     led = 0;


I try to use both rising edge and falling edge trigger to flag a high or low (assuming input is low to begin with):




void trigger1()


    input = 1;


void trigger2()


   input = 0;


Somehow it's not very reliable, probably due to bouncing. Is there a better level sensitive interrupt solution?


I usually set something like  10ms timer; which I keep resetting; and if it goes through you know the last value was stable for at least 10ms.

t1.rise(&trigger); t1.fall(&trigger); void trigger() { input = XX; resetTimer(10ms) };

onTimeOut() { // We're 10ms stable - so trust value in input };

If it is more critical; consider shifting the value into an 8 or 16 bit integer - so you can look at its history and take it from there. (And you reset the history to the current value once it is stable for your timeout period).

22 Jul 2010 . Edited: 22 Jul 2010



I did some de-bouncing as shown in the attached code (which I copied from http://mbed.org/forum/mbed/topic/716/?page=1#comment-3544)


The "counter" inside still keeps on increasing, which means the program catches more rising edge than falling edge. That's not going to work as a level sensitive trigger.


And here is another attempt. Am I allowed to do this:

InterruptIn input(p8);

DigitalIn check(p8);


which use p8 both in InterruptIn and DigitalIn instance.



15 Oct 2010

Hi Zhe, just to let you know I have the same problem. I posted a similar problem about this in this thread. I am monitoring an IN/OUT port and am having the exact same problem in which i am getting one too many rising edge triggers.