query regarding capsense : How to detect only 1 key in every 1 second

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
rahulpatel
Level 2
Level 2
10 replies posted 10 sign-ins 5 replies posted

Hi,

I have one use case in which I need to Sense only one key (i.e key 5) in every 1 second..need to check that whether this key is pressed or not..so how can I achieve this. I configure capsense as a buttons

0 Likes
1 Solution
ncbs
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 sign-ins

Hi @rahulpatel ,

> Whenever you enter deep sleep mode, you need an interrupt or use WDT (watchdog timer) to wake up from the deep sleep mode.

"CE210489_PSoC4_Low_Power_CapSense_Proximity" - refer to this CE to get an idea of using WDT to wake up from deep sleep. You can set the WDT to generate an interrupt for every 1 second (as required in your application)

> It is recommended to use CapSense[v7.0] block as this is the latest version of the CapSense block:

ncbs_0-1619167972579.png

 

> After disabling the sensor in the "if" condition, CapSense_ScanEnabledWidgets(); will effectively scan no widget in the next cycle of the while loop. You may consider removing that function call.


It is recommended to perform CapSense operations after the scan is complete, as unexpected values may be read when the scan is still in process. For this, you may use the CapSense_IsBusy() function (you may refer the above-mentioned code example for this)

if( !CapSense_IsBusy())
{
//your application
}

 

Regards,
Nikhil

View solution in original post

0 Likes
14 Replies
ncbs
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 sign-ins

Hello @rahulpatel,

Which PSoC 4 board are you using? 

You can find CapSense code examples in PSoC Creator. Open PSoC Creator -> File -> Code Example -> Select your device in "Device family" and capsense in "Filter by". 
You will find various code examples.

eg: CE210291_CapSense_P4_One_Button is one of the code examples in PSoC 4200M device family

Regards,
Nikhil

0 Likes
rahulpatel
Level 2
Level 2
10 replies posted 10 sign-ins 5 replies posted

Hi,

My Device is CY8C4248LQI-BL583 and when i check for the example code if capsense i can see only below attached projects CE210291_CapSense_P4_One_Button this one is not present

rahulpatel_0-1618831689485.png

 

 

0 Likes
ncbs
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 sign-ins

Hello @rahulpatel,

You are using PSoC 4200 BLE device.

You may search "CE210291_CapSense_P4_One_Button" as indicated by the picture below.

ncbs_0-1618832797365.png

 

Regards,
Nikhil

 

0 Likes
rahulpatel
Level 2
Level 2
10 replies posted 10 sign-ins 5 replies posted

Hi, 

How do I wake up my capsense sensor from the deep sleep mode using (using this function I put it in deep sleep mode CySysPmDeepSleep())? I tried CapSense_Enable() but it did not help.

Also, I configure Proximity sensor to detect event for this I follow below APIs to configure it and take a reading

uint8_t current_scan_map = 0;

CapSense_UpdateEnabledBaselines();
CapSense_ScanEnabledWidgets();
CapSense_UpdateSensorBaseline(CapSense_PROXIMITYSENSOR0__PROX);
CapSense_EnableWidget(CapSense_PROXIMITYSENSOR0__PROX);
CapSense_ScanSensor(CapSense_PROXIMITYSENSOR0__PROX);

current_scan_map = CapSense_CheckIsWidgetActive(CapSense_PROXIMITYSENSOR0__PROX); 


if( current_scan_map == 1 )
{
CapSense_DisableWidget(CapSense_PROXIMITYSENSOR0__PROX);
Printf("Detect Finger\n\r");
}

 

This function run in While loop..the issue is I am facing two behaviuor

1) At the start the value of the current_scan_map  is zero before any touch to the key..once the finger sens by sensor value is one but after that every time I got the value 1 which means every time sensor detects something.

2) Sometimes Once I start the program immediately it shows the sens. and again every time value of current_scan_map  is one every time.

Please suggest to me what is the correct way to use this proximity sensor and how to wake up capsense for deepsleep every time. 

0 Likes
ncbs
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 sign-ins

Hi @rahulpatel ,

> Whenever you enter deep sleep mode, you need an interrupt or use WDT (watchdog timer) to wake up from the deep sleep mode.

"CE210489_PSoC4_Low_Power_CapSense_Proximity" - refer to this CE to get an idea of using WDT to wake up from deep sleep. You can set the WDT to generate an interrupt for every 1 second (as required in your application)

> It is recommended to use CapSense[v7.0] block as this is the latest version of the CapSense block:

ncbs_0-1619167972579.png

 

> After disabling the sensor in the "if" condition, CapSense_ScanEnabledWidgets(); will effectively scan no widget in the next cycle of the while loop. You may consider removing that function call.


It is recommended to perform CapSense operations after the scan is complete, as unexpected values may be read when the scan is still in process. For this, you may use the CapSense_IsBusy() function (you may refer the above-mentioned code example for this)

if( !CapSense_IsBusy())
{
//your application
}

 

Regards,
Nikhil

0 Likes
rahulpatel
Level 2
Level 2
10 replies posted 10 sign-ins 5 replies posted

Hi,

I am using Capsense V2.60

In my application, I notice few things..

1) In my application I scan the key at every one second of the interval, but I noticed that After 7-8 seconds of long-press it scans the first time. and if I reduce the interval it takes 2-3 seconds to detect..why this happen? why it takes so much time to detect the key ?

2) One more thing MY device is battery-powered device so I need to save the battery for this I write logic that after scan the key capsense goes to sleep and before scanning it's wake up. but if I used those code then it stuck at CapSense_IsBusy() which shows it's busy below is the code. what I missed in this ?

 

 

 

while(1)
{
    if(flag == 0)
    {
      flag  = 1;
      guard_Write(0);
      shield_Write(0);
      CapSense_Start();
    }

    CapSense_Wakeup();
    //wait for scan to complete
    if(!CapSense_IsBusy())
    {
        CapSense_UpdateEnabledBaselines();
        CapSense_EnableWidget(CapSense_BUTTON5__BTN);
	CapSense_ScanEnabledWidgets();
		
	current_scan_map = 
        CapSense_CheckIsWidgetActive(CapSense_BUTTON5__BTN);      //5
         if( current_scan_map == 1 )
         {
             current_scan_map = 0;
         }
     }
    CapSense_Sleep();
}

 

 

 

 3) as per my application I need to scan only one button so is there any API which are scans only one key rather than all keys ?

0 Likes
ncbs
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 sign-ins

Hi @rahulpatel,

> CapSense_Start() may be used once outside the infinite while loop. 
> When CapSense_Wakeup() is called, the component is enabled (so no need to call CapSense_EnableWidget() function). After CapSense_Wakeup(), you need to call the scanning function. You may use CapSense_ScanSensor() or CapSense_ScanWidget() function.
> After this is done, you need to check if the sensor is still in scan mode or not by using CapSense_IsBusy() function. Once the scan is complete, execution enters the "if" block. 

> In your application, it is required for you to put the capsense block to sleep for 1 second and then wake it up. I find that there is no block to measure that 1 second delay. You may implement this using a WDT. 


(Since there is no delay, capsense block would be continuously switching between active and sleep modes)

Following a state machine implementation is preferable. You may refer  "CE210489_PSoC4_Low_Power_CapSense_Proximity01" CE

 

Regards,
Nikhil

0 Likes
rahulpatel
Level 2
Level 2
10 replies posted 10 sign-ins 5 replies posted

Hi,

Thanks for the help, I update my capSense to v4.0 now..In that can you help me with which API I use to enable and disable the widget(V2.6 API EnableWidget() and DisableWidget())...I found one API in datasheet CapSense_SetParam but i did not find the use case for this can you help me with this..

Also As I said I am using capsense v4.0 how need to change the tuning parameter..right now I set CSD tunning Mode to Smart Sense(Full Auto-Tune) but in this, I am not able to change it as its automatic...but previously I use v2.60 in this I can see the tuning parameter in Auto mode...Can you help me how to check and change the tuning parameter .

0 Likes
ncbs
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 sign-ins

Hi @rahulpatel,

> You can enable/disable a widget as follows:

CapSense_SetParam(CapSense_WDGT_ENABLE0_PARAM_ID, value);

where 

  • CapSense_WDGT_ENABLE<RegisterNumber>_PARAM_ID is the required register (can be found in CapSense_RegisterMap.h)
  • To disable value = 0
    To enable value = 1

 

When SmartSense is used, only minimal parameters can be tuned. If you wish to perform manual tuning, double click on the capsense component to open the configurator,  and set the CSD tuning mode to "Manual tuning". 
Then in the advance tab, explore the General, CSD sub-tabs, Widget details and Scan order sub-tabs. You can manually tune them. 

You may use CapSense Tuner to assist you in tuning. You need I2C or UART for communication with the CapSense Tuner, so configure these blocks before you launch CapSense Tuner. (refer to PSoC4_CapSense_Tuner_I2C and/or PSoC4_CapSense_Tuner_UART code examples to use CapSense tuner).

Regards,
Nikhil

0 Likes
rahulpatel
Level 2
Level 2
10 replies posted 10 sign-ins 5 replies posted

Hi Nikhil,

In my application, I used 13 Buttons. My requirement is after the keypad operation done I want to disabled only 12Buttons.

But If I use below api

CapSense_SetParam(CapSense_WDGT_ENABLE0_PARAM_ID, value);

It disabled the Widget itself It means to disable all the 13 Buttons.
so, What I do to Enabled/Disabled only those 12Buttons or particular keys/Buttons ?

0 Likes
ncbs
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 sign-ins

Hi @rahulpatel,

More information regarding value:

Suppose there are 5 CSD buttons configured as shown:
ncbs_0-1619685129734.png

 

To enable/disable any particular widget, bit masking is used.
value takes a 5 bit value in the following format:

<Button4><Button3><Button2><Button1><Button0>   (MSB = left most bit, LSB = right most bit)

  • To enable only Button0value = 00001(in binary) or 1(in decimal)
       CapSense_SetParam(CapSense_WDGT_ENABLE0_PARAM_ID, 1);
  • To enable only Button3value = 01000(in binary) or 8(in decimal)
       CapSense_SetParam(CapSense_WDGT_ENABLE0_PARAM_ID, 8);
  • To disable only Button2value = 11011(in binary) or 27(in decimal)
       CapSense_SetParam(CapSense_WDGT_ENABLE0_PARAM_ID, 27);

 

 

Regards,
Nikhil

0 Likes
rahulpatel
Level 2
Level 2
10 replies posted 10 sign-ins 5 replies posted

HI Nikhil,

If the Widget is enabled and still execute this CapSense_SetParam(CapSense_WDGT_ENABLE0_PARAM_ID, 4095) (which I want to enable all 12 buttons) the keypad is not responding may its disabled or something. 

Is there any specific API I should Call before I call CapSense_SetParam() and it's not right to call Enable widget if its already enable?

0 Likes
ncbs
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 sign-ins

Hi @rahulpatel,

No other API is required to for CapSesne_SetParam(CapSense_WDGT_ENABLE0_PARAM_ID, 4095) function to work. You may call the SetParam function anywhere in the code.

You may enable different widgets based on conditions too.

if(condition)
CapSense_SetParam(CapSense_WDGT_ENABLE0_PARAM_ID,value1);
else
CapSense_SetParam(CapSense_WDGT_ENABLE0_PARAM_ID,value2);

 

There would be no harm/difference if the "enabled" button is again enabled by the function call, although redundant function calls may be avoided.

Regards,
Nikhil

0 Likes
rahulpatel
Level 2
Level 2
10 replies posted 10 sign-ins 5 replies posted

Hi Nikhil,

Thanks, it works for me.

0 Likes