Software Debounce for ADuCM3029

Hello guys , i need your help . I have code of interruptions for ADuCM3029 via GPIO ports. However, the interruptions are not regular. so there is the problem of Software debounce. Is there any code of software debouncing ? 

Parents
  • Hello,

    I don't think there is any code for debouncing available, but I can suggest two methods to do software debouncing:

    1. This one is easier, but a bit sloppy. If you don't care to know exactly how much time you debounce you can set up an approximately 1 ms time with a variable going up to 26000 in a 'for' loop. That is, in the interrupt routine for the pin do:

    gpio_isr() {
        int i;
    
        for(i = 0; i < 26000; i++);
        read_gpio();
        if(!gpio_still_asserted)
            return;
        do_gpio_interrupt_routine();
    }

    Just do multiples of this number if you need more miliseconds.

    2. If you need a finer control over the debouncing period you have to set up a timer to interrupt at the specific time interval you want to debounce. After that just start the timer in the GPIO ISR and do the second GPIO read and GPIO routine in the timer ISR:

    gpio_isr() {
        start_timer();
    }
    
    timer_isr() {
        read_gpio();
        if(!gpio_still_asserted)
            return;
        do_gpio_interrupt_routine();
    }
    

    I explained the solutions in pseudocode because there are more constraints to take into account to write a complete solution like if you are using the DFP drivers or not, and which timers you have available. Let me know if you need any more help.

    Regards,

    Andrei

Reply
  • Hello,

    I don't think there is any code for debouncing available, but I can suggest two methods to do software debouncing:

    1. This one is easier, but a bit sloppy. If you don't care to know exactly how much time you debounce you can set up an approximately 1 ms time with a variable going up to 26000 in a 'for' loop. That is, in the interrupt routine for the pin do:

    gpio_isr() {
        int i;
    
        for(i = 0; i < 26000; i++);
        read_gpio();
        if(!gpio_still_asserted)
            return;
        do_gpio_interrupt_routine();
    }

    Just do multiples of this number if you need more miliseconds.

    2. If you need a finer control over the debouncing period you have to set up a timer to interrupt at the specific time interval you want to debounce. After that just start the timer in the GPIO ISR and do the second GPIO read and GPIO routine in the timer ISR:

    gpio_isr() {
        start_timer();
    }
    
    timer_isr() {
        read_gpio();
        if(!gpio_still_asserted)
            return;
        do_gpio_interrupt_routine();
    }
    

    I explained the solutions in pseudocode because there are more constraints to take into account to write a complete solution like if you are using the DFP drivers or not, and which timers you have available. Let me know if you need any more help.

    Regards,

    Andrei

Children