6 Replies Latest reply on Jun 11, 2011 11:07 AM by gautamd_

    Push Button



        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?





        • 1. Re: Push Button

          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.

          • 2. Re: Push Button

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

            • 3. Re: Push Button

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

              • 4. Re: Push Button

                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.

                • 5. Re: Push Button

                  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.





                  • 6. Re: Push Button

                    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.