You are here

capsense using generic widgets for psoc 4m | Cypress Semiconductor

capsense using generic widgets for psoc 4m

Summary: 3 Replies, Latest post by glenn-edgar_1523231 on 01 Dec 2016 04:22 PM PST
Verified Answers: 0
Last post
Log in to post new comments.
glenn-edgar_1523231's picture
User
22 posts

I am using a capacitive sensor to measure soil moisture.  The approach is similar to the liquid level capsense application note.  I got the solution to work on the psoc 5lp system, but I am having problem getting the solution to work on a psoc 4m.   I am using the cy8kit-043 for the psoc 4m.

 

I set up one generic widget on P6.5 and the CMOD on P4.2.   I am assuming that the kit provides the necessary capacitor on P4.2 for the CMOD.  The generic widget is configured to 14 bit scan resolution.  The other parameters follow the guidelines in the liquid level app note.

 

I used the following code segment as shown below.

 

volatile int32 sensor_value;

int main(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */

   
    
    CapSense_1_Start();
    for(;;)
    {
       CapSense_1_ScanSensor(0);  // CapSense_1_SENSOR_GENERIC0_0__GEN which is zero
       if( CapSense_1_IsBusy() != 0 )
       {
           CyDelay(1);
       }
       sensor_value = CapSense_1_ReadSensorRaw(0);
    }
}

 

The sensor_value was 0x3fff , irrespective of what was connected to the P6.5 pin.

Any ideas on what I am doing wrong.

Glenn

 

 

 

user_1377889's picture
User
9581 posts

Use a

while(CapSense_1_IsBusy() ){}

 

Bob

glenn-edgar_1523231's picture
User
22 posts

Thanks for correction.  Apparently this fix did not completely solve the problem.  I got the same results with the following code segment.

volatile int32 sensor_value;
volatile int32 busy_flag;
int main(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */
    
    CapSense_1_Start();
    for(;;)
    {
       CapSense_1_ScanSensor(0);
       while( CapSense_1_IsBusy() != 0 )
       {
           CyDelay(1);
       }
       busy_flag = CapSense_1_IsBusy();
       sensor_value = CapSense_1_ReadSensorRaw(0);
    }
}

sensor_value is 0x3fff  and the busy flag is 0 as a sanity check

Glenn

glenn-edgar_1523231's picture
User
22 posts

New Update.

I found out that my sensors had a lot of capacitance.  By change the modulator and clock divider and clock divider from 2 to 10, seems to solve this problem  The scan time increased from 1. ms to around 13.6 ms.  This larger scan time seems to allow larger capacitances to be accomodated.

 

 

 

Log in to post new comments.