Debounce logic for a tactile switch with 10ms max ON/OFF bouncing

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
TaH_4345166
Level 2
Level 2
5 likes given First like received First like given

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.

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

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

000-schematic.JPG

pin list

001-pin-list.JPG

SW config

002-SW-Config.JPG

003-SW-Config-input.JPG

SW_INT config

004-SW-INT_config.JPG

LED Config

005-LED-Config.JPG

moto

View solution in original post

2 Replies
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

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

000-schematic.JPG

pin list

001-pin-list.JPG

SW config

002-SW-Config.JPG

003-SW-Config-input.JPG

SW_INT config

004-SW-INT_config.JPG

LED Config

005-LED-Config.JPG

moto

odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

TaH,

You can use this component for processing ON/OFF switch events with debouncing

ButtonSw32: button switch debouncer component

/odissey1