capsense using generic widgets for psoc 4m

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

cross mob
Anonymous
Not applicable

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

0 Likes
3 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Use a

   

while(CapSense_1_IsBusy() ){}

   

 

   

Bob

0 Likes
Anonymous
Not applicable

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

0 Likes
Anonymous
Not applicable

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.

0 Likes