This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Switch Debounce

I have a switch connected on the nRF51DK Board. The switch is connected on PIN25 and PIN 28. I try to read the state of the switch.

My setup:

-nRF51DK

-SDK8.1

-SoftDevice 8.0

I defined PIN 25 and 28 as Inputs(PULLDOWN). The button_event_handler is working, but sometimes I wont get the Interrupt.

So I decided to debounce the switch.

image description

Now I will always get an Interrupt when switch is in UP position. But in the DOWN position I will still miss Interrupts(when I try it 5 times, once the interrupt will not occur).

How is this possible? Should I debounce PIN 28 in the software?

I changed the BUTTON_DETECTION_DELAY from 100ms to 500ms. And I will also miss interrupts. How is this possible? After a half second the switch should be debounced.

static void button_event_handler(uint8_t pin_no, uint8_t button_action)
{
NRF_GPIOTE ->EVENTS_IN[0] = 0;

if(button_action == APP_BUTTON_PUSH)
{
    switch (pin_no)
    {
        case 	Switch_up:
								pwm_start();
								break;

        case 	Switch_down:
								pwm_start();
								break;
        
	    default:
								break;
    }
}		
else if (button_action == APP_BUTTON_RELEASE)
{
    switch (pin_no)
    {
        case 	Switch_up:
								pwm_stop();								
								break;
        case 	Switch_down:
								pwm_stop();
								break;
					
        default:
								break;
    }
}
}
Parents Reply Children
No Data
Related