Push Button

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

Hello,

   

  I have been using PSoC 5 with this new project and I am trying to figure out why every time I pressed the button (General Purpose Switch button) I kept getting more than one message than I need. I expected that every time I press the button, only need one message and not several at a time.

   

Attached is the code I had modified to do the push button but it does not seem right to me. Any suggestions on the coding?

   

 

   

Thanks!

0 Likes
6 Replies
Anonymous
Not applicable

Hi Doacn,

   

 

   

SInce you are using the statements in an infinite loop [ for(;;) ], the UART will send the value it reads continuously.

   

If the value has to be printed via UART only once when the button is pushed, you may use an Interrupt component.

   

Setting it to Rising edge or Falling edge triggered as per your requirement will enable you to send the value on the required edge. Holding the botton for a longer time will not result in sending of more than one value via UART.

   

 

   

This is one way to overcome this issue.

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Have a look at AN60024 - Switch Debouncer/. This should solve your problem.

0 Likes
Anonymous
Not applicable

Awesome! Thanks, I will try both methods and see type of result best suit us. Thanks for your help!!

0 Likes
Anonymous
Not applicable

Hello Dasg,

   

  Do you mean to create a new interrupt component or the interrupt component in UART? More clarification please. Thanks.

   

P.S. I had done both ways and I still get the same result.

0 Likes
Anonymous
Not applicable

Hi Doacn,

   

 

   

My suggestion was to use an ISR Component connected to the Button_Pin. The schematic will look something like this.

   

 

   

   

 

   

 

   

Assume that the Button is connected to ground when pushed, and is left floating when not pushed. Then for this logic, the drive mode of the pin should be configured as Resistive Pull-Up.

   

 

   

0 Likes
Anonymous
Not applicable

In the ISR routine, a flag can be set. In the infinite loop of the main( ) function, the flag can be polled. When the flag is set, data is transmitted through UART and flag is reset. This way, data is transmitted only once upon push of the button.

   

For the data to be transmitted again, the button should be pressed again.

   

The ISR can be configured to be Rising Edge Triggered.

0 Likes