InterruptIn response time control

29 Apr 2010

hello everyone:

 

   void flip() {
    pc.printf("0 ");
}

int main() {
    button.rise(&flip); 
    while(1) {          
        flash = !flash;
        wait(0.25);
    }
}

    i use InterruptIn on button.but when i click button one time the flip() always do servals times.I don't konw how to control it. I only want to do only once when i click button once.

29 Apr 2010

sorry my poor english .hope some can help me .

29 Apr 2010

Hmm, probably the bounce of the button.
create a routine, that after 25 mS asks if the state of the button is correct, then start the timer.
Thats the best software debounce I've created so far.

29 Apr 2010

Yes, I think so too.
You may need debounce mechanism. It may be looked like this.

#include    "mbed.h"

BusOut            leds( LED4, LED3, LED2, LED1 );
char              count;

InterruptIn       button( p16 );   //  interrupt instance for the button
Timer             t;               //  To manage debounce by menchanical switch

#define DEBOUNCING_INTERVAL  100   //  Debouncing interval (in mili-seconds)

void isr_buton( void ) {
    
    if ( t.read_ms() > DEBOUNCING_INTERVAL ) {
        leds    = (count++) & 0xF;
    }
    
    t.reset();  //  timer reset
}

int main() {
    count   = 0;

    t.start();  //  timer start
    button.rise( &isr_buton );

    while ( 1 ) {
    }
}

For the debounce, you can find more information here.
http://mbed.org/users/chris/notebook/switch-debouncing/