push button with denouncing implemented

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

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

 Hi there,

   

I have gott switch connected to Psoc5 and would like to turn on LED, whenever button is pressed, looking for project how to actually do it. I also would like to implement with debouncing circuit, so not sure how could I do that in cypress.

   

I tried something like this but doesn't work

   

 

   

#include <device.h>

   

volatile uint8  switchFlag = 0u;

   

CY_ISR_PROTO(SW_ISR_Handler);

   

 

   

int main()

   

{

   

    CyGlobalIntEnable;

   

    Isr_SW2_StartEx(SW_ISR_Handler);

   

    for(;;)

   

    {

   

        if(switchFlag)

   

        {

   

            LED_Write(1);          

   

            switchFlag = 0u;

   

               CyDelay(5000);

   

        }

   

    }

   

}

   

 

   

CY_ISR(SW_ISR_Handler)

   

{

   

    switchFlag = 1u;

   

}

   

 

   

Top Design is attached.. If any mistake then let me know.

   

Any help woud be great .

   

 

   

Thanaks 

   

AK

0 Likes
4 Replies
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Use the debouncer component -

   

 

   

   

 

   

There is an example project you can look at, start page, "Find Example project" link

   

 

   

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

Hi Dana,

   

Thanks for your reply.

   

I did use debouncer as you can see schematics in attachment, I used example code, but it doesn't work , you can see in above thread, my connections are on top design are right. Just would like to confirm that I have applied 3.3 V to switch and connected to one of pin and set as input, will that work as input interrupt ?

   

So, I am not sure what is wrong , Is above code and schematics right ? 

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Post a project archive -

   

 

   

    

   

          

   

“File”                                                             Creator

   

“Create Workspace Bundle”

   

  

   

Regards, Dana.

0 Likes
RaAl_264636
Level 6
Level 6
50 sign-ins 25 sign-ins 10 solutions authored

Hi AK,

   

 

   

it depends on how your input pin is configured. You wrote that the switch is connected to 3.3V. So your input pin must be configured for input with pull-down enabled, otherwise you wouldn't get the low voltage value when the button is not pressed.

   

To be compatible with other MCUs it's recommended to connect the switch to GND, because pins are configured for input with pull-up resistor on most MCUs.

   

 

   

Regards,

   

 

   

Ralf

0 Likes