sciosense / pcap04-sample-code

Sample code for PCap04, a capacitance-to-digital converter (CDC).
MIT License
4 stars 1 forks source link

Reading raw value from CDC(Capacitive Digital Converter) and calculate capacitance. #2

Closed Vineetha1705 closed 3 months ago

Vineetha1705 commented 4 months ago

I am working with the PCAP04 sensor. Here, the STM32F7 is configured as an SPI master, and the PCAP04 is configured as an SPI slave. My application involves reading values from the CDC (Capacitive Digital Converter) and calculating capacitance.

I am following the code provided by you (CDC Click https://www.mikroe.com/cdc-click) , but I have some doubts which are mentioned below. Specifically, I am reading the raw values in results.res_0

define CDC_EXT_CAP_C1_C0_PF 0.0f

define CDC_INT_CAP_PF 10.0f

define CDC_REF ( CDC_EXT_CAP_C1_C0_PF + CDC_INT_CAP_PF )

C= results.res_0 * CDC_REF - CDC_INT_CAP_PF //capacitance calculation

In the code CDC_REF is taken as sum of CDC_EXT_CAP_C1_C0_PF and CDC_INT_CAP_PF . How you taken CDC_INT_CAP_PF as 10PF.

But In the datasheet, the internal reference capacitance ranges from 1 pF to 31 pF, and the calculation for Cref is Cref ~ 0.959 pF*C_REF_SEL + 3.23pF

Which method should I follow to calculate Cref​?

Please help me in this regard.

Thanks & Regards, D. Vineetha.

webseitz commented 3 months ago

Dear D. Vineetha,

The provided code was written by MIKROE.

The PCap04 sensor provides calculated ratios, where the sensor capacitance is divided by the reference capacitance. You only need to read these ratios. For more details, please refer to our application note, "Interpreting-and-Scaling-Raw-Result", available on our website. The sensor capacitance can be determined by multiplying the ratio by the reference capacitance. The internal reference value, which you may be referring to, is more of a theoretical value and is specified on page 11 of the datasheet. image

The displayed formula is merely an approach. image