6 Replies Latest reply on Apr 21, 2020 12:27 AM by MoTa_728816

    About discharging a CapSense input (CY8CKIT-149)

    MoTa_728816

      Hi,

       

      ============

      BACKGROUND

      ============

      I have a customer who is trying to create a water-proof application prototype with CY8CKIT-149.

       

      And when they changed the sense clock of one sensor from the CapSense Tuner, all CapSensor's count got higher,

      and even after they changed the sense clock back to the original value, the reading counts remained similar (higher than before).

       

      Interestingly we could not reproduce the problem at our site, but from the symptom,

      I imagined that there should be remaining static.

       

      So I wrote a function, which will change the driving mode of the sensor pin to GPIO pull-down,

      and let the pin discharge the static for a while and then restore the CapSense setting.

       

      At the customer site, this method worked OK.

      But the customer is wondering if this is the recommended method and/or this function can be applied to the production version.

       

      ==========

      QUESTION:

      ==========

      So, would you teach me if there is/are better method to discharge the sensor when sense clock changed.

      And/or if changing the drive mode of the CapSense pin to GPIO pull-down and later restoring it is acceptable solution for production device?

       

      The discharge function I wrote was

      ===============

      /**********************************************************************************

      * Function Name: discharge_btn0

      ***********************************************************************************/

      /**

      * BTN0 : P4[4]

      * Drive Mode: GPIO_PRT4_PC[14:12] = DM4[14:12]

      * 0x0: OFF:

      * Mode 0 (analog mode): Output buffer off (high Z). Input buffer off.

      * 0x1: INPUT:

      * Mode 1: Output buffer off (high Z). Input buffer on.

      * 0x2: 0_PU:

      * Mode 2: Strong pull down ('0'), weak/resistive pull up (PU). Input buffer on.

      * 0x3: PD_1:

      * Mode 3: Weak/resistive pull down (PD), strong pull up ('1'). Input buffer on.

      * 0x4: 0_Z:

      * Mode 4: Strong pull down ('0'), open drain (pull up off). Input buffer on.

      * 0x5: Z_1:

      * ode 5: Open drain (pull down off), strong pull up ('1'). Input buffer on.

      * 0x6: 0_1:

      * Mode 6: Strong pull down ('0'), strong pull up ('1'). Input buffer on.

      * 0x7: PD_PU:

      * Mode 7: Weak/resistive pull down (PD), weak/resistive pull up (PU). Input buffer on.

      */

      #define DRIVE_MODE 0x3

      #define DM4_BIT_OFFSET 12

      #define DM4_CLEAR_MASK 0xFFFF8FFF

      void discharge_btn0(void)

      {

          uint32_t saved_value ;

          uint32_t reg_value ;

         

          saved_value = CY_GET_REG32(CYREG_GPIO_PRT4_PC) ;

          reg_value = saved_value ;

         

          reg_value = (reg_value & DM4_CLEAR_MASK) | (DRIVE_MODE << DM4_BIT_OFFSET) ;

          CY_SET_REG32(CYREG_GPIO_PRT4_PC, reg_value) ;

       

          CyDelay(1) ; /* wait 1 ms */

       

          CY_SET_REG32(CYREG_GPIO_PRT4_PC, saved_value) ;

      }

      ===============

       

      And sense clock change detect function is

      ===============

      /**********************************************************************************

      * Function Name: is_btn0_sense_clock_changed

      ***********************************************************************************/

      /**

      * Detect BTN0 Sensor Clock change

      */

      int  is_btn0_sense_clock_changed(void)

      {

          static int prev_btn0_sns_clk ;

          int result = 0 ;

          int btn0_sns_clk ;

         

          if (prev_btn0_sns_clk == 0) {

              prev_btn0_sns_clk = CapSense_dsRam.wdgtList.btn0.snsClk  ;

          }

          btn0_sns_clk = CapSense_dsRam.wdgtList.btn0.snsClk  ;

          if (prev_btn0_sns_clk != btn0_sns_clk) {

              result = 1 ;

              prev_btn0_sns_clk = btn0_sns_clk ;

          }

          return( result ) ;

      }

      ===============

       

      Attached is the whole project, which is CE220891 with a guard sensor.

       

      moto