Hi guys, I have a problem about switch debouncing and I know what switch debouncing used for. But, can you guys briefly told me how switch debouncing work ?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi guys, I have a problem about switch debouncing and I know what switch debouncing used for. But, can you guys briefly told me how switch debouncing work ?
if ( events & SWITCH_DEBOUNCE )
{
if ( SW3 == 0 )
{
//Confirm SW3 is pressed and you can do what you want when SW is pressed here
}
return ( events ^ SWITCH_DEBOUNCE );
}
Sorry for disturbing AGAIN Yikai. I know that the osal timer will execute only once when I pressed SW3 but now I want to repeat this process over and over again. Any method to do this? If I used infinite loop ( while or for ) means it won't clear the event right?
I want to repeat the debounce event every time when I press the switch. Now when I pressed the switch, the LED only ON for a while then it will completely OFF after few secs and when I press the switch again, it won't perform the switch debounce again.
Then, you should create another event to turn off led.
if ( events & SWITCH_DEBOUNCE )
{
if ( SW3 == 0 )
{
Led_On( LED_PORT_1 , ( LED_RED_PIN | LED_BLUE_PIN ) );
}
osal_start_timerEx ( keyfobapp_TaskID, LED_OFF_EVT, LED_OFF_DELAY );
return ( events ^SWITCH_DEBOUNCE );
}
if ( events & LED_OFF_EVT )
{
Led_Off( LED_PORT_1 , ( LED_RED_PIN | LED_BLUE_PIN ) );
return ( events ^LED_OFF_EVT );
}
You misunderstood my meaning sir. Now I want to repeat the switch debounce step each time when I press the switch.
1. I set a timer for 50 ms for the switch debounce
2. When it >50ms which means someone press the switch and perform the next task( here is open LED ).
3. As long as the switch is pressed, the LED will go ON till the user release the switch.
My idea is like that. But what I expected is the above step will be repeat when someone press the switch AGAIN. Means each time someone press the switch, it must go through this event .