5 years, 10 months ago.

LPC1114FN28 InterruptIn Callback Execute on Both Falling and Rising Edge and How to Fix it

Dear all, I have tried following code on LPC1114FN28. The InterruptIn callback executes both on falling edge and rising edge. In order to reproduce the problem, use following steps,

1.   Connect TWO debounced push buttons to LPC1114FN28 DIP module with external pullup resistors
2.   Connect THREE active high LED to LPC1114FN28 DIP module
3.   Make sure push buttons generate clean active low pulse when pressed
4.   Download following program to LPC1114FN28 DIP module
5.   Press and hold and release Button2
6.   TWO LED will be on, one is on when press, another one is on when release
7.   Press and hold and release Button1
8.   TWO LED will be off, one is off when press, another one is off when release


#include "mbed.h"

DigitalOut  LedR (dp14);
DigitalOut  LedY (dp17);
DigitalOut  LedG (dp18);

InterruptIn Btn1 (dp26);
InterruptIn Btn2 (dp28);

void ISR_Btn1Rise ()
{
	NVIC_DisableIRQ (EINT0_IRQn);

    volatile uint32_t d = 0;
    volatile uint32_t s = 1;

    for (d = 0; d < 10000; d++) {s = Btn1.read ();}  // Debounce

    if      (s            == 0) {}
    else if (LedR.read () == 1) {LedR = 0;}
	else if (LedY.read () == 1) {LedY = 0;}
	else if (LedG.read () == 1) {LedG = 0;}

	NVIC_EnableIRQ  (EINT0_IRQn);
}

void ISR_Btn2Rise ()
{
	NVIC_DisableIRQ (EINT0_IRQn);

    volatile uint32_t d = 0;
    volatile uint32_t s = 1;

    for (d = 0; d < 10000; d++) {s = Btn2.read ();}  // Debounce

    if      (s            == 0) {}
    else if (LedR.read () == 0) {LedR = 1;}
	else if (LedY.read () == 0) {LedY = 1;}
	else if (LedG.read () == 0) {LedG = 1;}

	NVIC_EnableIRQ  (EINT0_IRQn);
}

int main ()
{
	LedR = 0;
	LedY = 0;
	LedG = 0;

	Btn1.mode (PullNone);
	Btn2.mode (PullNone);

	Btn1.rise (&ISR_Btn1Rise);
	Btn2.rise (&ISR_Btn2Rise);

    while (1)
    {
    }
}

The correct behavior should be only ONE LED on, one LED off, both TWO. Any help is appreciated.

Thank u

What happens if you connect a DigitalOut to the InterruptIn and use that to trigger it? Since you would get the same behaviour if your debounced buttons are not sufficiently debounced: Your software debouncing doesn't work for starters! So if you rely just on that, then your result is correct.

posted by Erik - 15 Jan 2016

Yes, you are absolutely right. DigitalOut is much cleaner then external debounced push button. I have modified the code, added debounced loop. The result is pretty promising and consistent

posted by WAI YUNG 16 Jan 2016
Be the first to answer this question.