4 Replies Latest reply on Jul 15, 2015 3:54 AM by user_14586677

    debouncer circuit

    atul.singh

      I have a switch connected to PRoC.

         

      How to implement debouncer circuit in PRoC as it does not has logic gates/FF?

        • 1. Re: debouncer circuit
          rohit.kumar

          How about software based debouncer? Something like following:

             

          #define Button_PUSHED_MASK               0x01
          #define Button_DETECTED_MASK            0x02

             

          #define SWITCH_DEBOUNCE_DELAY                  400   /* Counter value equivalent to debounce time */

             

          uint8 buttonStatus =0;

             

          void CheckButtonPress(void)
          {   
              if(Button_Pin_Read() == FALSE)
              {
                  /* Register the button press for the first time and check if button debouncing is completed */
                  if(!(buttonStatus & (Button_PUSHED_MASK | Button_DETECTED_MASK)))
                  {
                      /* If button press not registered, register the button press event*/
                      buttonStatus = buttonStatus | Button_PUSHED_MASK;
                      
                      /* Initiate a debounce counter */
                      switchDebounceTimer = SWITCH_DEBOUNCE_DELAY;
                  }
                  else if( (buttonStatus & Button_PUSHED_MASK) && (switchDebounceTimer == 0) )
                  {
                      /* If debounce counter has elapsed, then register a button press detect event */
                      buttonStatus = buttonStatus & (~Button_PUSHED_MASK);
                      buttonStatus = buttonStatus | Button_DETECTED_MASK;
                  }
              }
              else
              {
                  if((buttonStatus & Button_DETECTED_MASK))
                  {
                      /******USER_CODE: Add your custom code for push button based events or debugging code*********/
                      
                      /*********************************************************************************************/
                      
                      /* Reset button status flag */
                      buttonStatus = buttonStatus & ( ~(Button_DETECTED_MASK) );
                  }
                  /* If button press is not detected and the switch debounce timer has expired, clear the button press status
                   * in the ButtonStatus register */
                  else if((buttonStatus & Button_PUSHED_MASK) && switchDebounceTimer == 0)
                  {
                       buttonStatus = buttonStatus & (~Button_PUSHED_MASK);
                  }
              }
           }

             

           

             

          The above is assuming that the input pin ''Button_Pin'' is configured as resistive pull-up. Make sure that you have a timer based system that decrements 'switchDebounceTimer ' whenever it is non-zero. 

          • 2. Re: debouncer circuit
            user_14586677

            Some ref material -

               

             

               

            Regards, Dana.

            • 3. Re: debouncer circuit
              atul.singh

              thanks roit and Dana.

              • 4. Re: debouncer circuit
                user_14586677

                Glad I could be of assistance.

                   

                 

                   

                Regards, Dana.