About discharging a CapSense input (CY8CKIT-149)

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.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

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

0 Likes
1 Solution
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi MoTa_728816

To answer your question, yes. This is correct.

You can also see the CapSense_SsSetAllIOsState function which does something similar when CapSense_Start is called.

But this issue is interesting. Whenever parameters such as sense clock frequency or resolution is changed, the tuner sends a command to initiate a CapSense restart so that the changes are effectively applied and this in-turn calls the CapSense_SsSetAllIOsState function that discharges the sensors.

I believe the issue here is with tuner communication. The commands might not be exchanged correctly, resulting in the error. Please make sure that the hardware connection is robust.


Thanks,
Hari

View solution in original post

0 Likes
6 Replies
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi MoTa_728816

To answer your question, yes. This is correct.

You can also see the CapSense_SsSetAllIOsState function which does something similar when CapSense_Start is called.

But this issue is interesting. Whenever parameters such as sense clock frequency or resolution is changed, the tuner sends a command to initiate a CapSense restart so that the changes are effectively applied and this in-turn calls the CapSense_SsSetAllIOsState function that discharges the sensors.

I believe the issue here is with tuner communication. The commands might not be exchanged correctly, resulting in the error. Please make sure that the hardware connection is robust.


Thanks,
Hari

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Dear Hari-san,

Thank you very much for your reply.

But would you let me confirm which sentence did you write "yes" ?

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

(2)  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?

If it was for (1), would you teach me the method?

And if it was for (2) I'm very happy to know that.

Best Regards,

21-Apr-2020

Motoo Tanaka

0 Likes
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi MoTa_728816

1. The method followed is correct, although I would suggest strong drive with driving 0 for faster discharge. The implementation is similar.

2. This is acceptable and is followed in the component code as well.

Thanks,

Hari

MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Dear Hari-san,

I'm just curious, but,

Isn't using Strong Pull Down ('0'), open drain (pull up off) safer?

(And also it does not require writing output value '0' to the input pin port)

Best Regards,

21-Apr-2020

Motoo Tanaka

0 Likes
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi MoTa_728816

Since there is already a series resistor on CapSense traces, it is safe to use strong drive as well. Resistive pull down will take some extra time to discharge completely.

The user has to make sure that they wait this long (which in this case, i see is happening). It is just that discharging will be faster with strong drive.

Thanks,
Hari

MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Dear Hari-san,

Thank you for your answer!

I think we can call it a day for this question, now 😉

Best Regards,

21-Apr-2020

Motoo Tanaka

0 Likes