- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I have a switch with bouncing of 10ms max (ON,OFF), how to handle a debounce logic with this bouncing time?
In the PSoC4 there are many examples for debouncing but all of them uses some ISR which is called without switch is pressed and also I have seen, for that switch no interrupt is enables. So getting confused with the logic.
please help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
There could be many approaches, but off my head somewhat simple one.
I used CY8CKIT-044.
My approach is just wait 10ms after getting interrupt flag and read the value to check if it's still asserted.
main.c
==============
#include "project.h"
#define SW_PUSHED 0u
volatile int sw_pushed_flag = 0 ;
CY_ISR(sw_isr)
{
SW_INT_ClearPending() ;
sw_pushed_flag = 1 ;
}
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
SW_INT_StartEx(sw_isr) ;
for(;;)
{
if (sw_pushed_flag) {
CyDelay(10) ; /* wait 10ms */
if (SW_Read() == SW_PUSHED) {
LED_Write(!LED_Read()) ;
}
sw_pushed_flag = 0 ;
}
}
}
==============
schematic
pin list
SW config
SW_INT config
LED Config
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
There could be many approaches, but off my head somewhat simple one.
I used CY8CKIT-044.
My approach is just wait 10ms after getting interrupt flag and read the value to check if it's still asserted.
main.c
==============
#include "project.h"
#define SW_PUSHED 0u
volatile int sw_pushed_flag = 0 ;
CY_ISR(sw_isr)
{
SW_INT_ClearPending() ;
sw_pushed_flag = 1 ;
}
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
SW_INT_StartEx(sw_isr) ;
for(;;)
{
if (sw_pushed_flag) {
CyDelay(10) ; /* wait 10ms */
if (SW_Read() == SW_PUSHED) {
LED_Write(!LED_Read()) ;
}
sw_pushed_flag = 0 ;
}
}
}
==============
schematic
pin list
SW config
SW_INT config
LED Config
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
TaH,
You can use this component for processing ON/OFF switch events with debouncing
ButtonSw32: button switch debouncer component
/odissey1