This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

FDC1004: Capacitive Sensing Sample Code

Part Number: FDC1004
Other Parts Discussed in Thread: ENERGIA

Hi,

I am trying to use FDC1004 with Arduino and downloaded "Capacitive Sensing Microcontroller Sample Code (Energia)-1.1" from www.ti.com/.../toolssoftware.

I'm not sure "(float)lb3/1048576" part.
Does this mean lb3 is shifted right 20 bits?
Is not it shifting right 19 bits (=lb3/524288)?

Below are from sample code
-----------
// Below are the calculations to take the 24-bit measurement and convert into capacitance for MEAS1
// * From datasheet: p.16 Section 8.6.1.1 shows the formula (all we need to do is shift the 24-bit value right by 19)
// ** Shifting by 19 takes a 24 bit number and makes it a 5 bit number with 19 bits after the decimal point
lbb1 = lb1*256 + lb2; // Puts 16 most significant bits into one integer for left sensor measurement
lbb2 = lbb1>>11; // Sets lbb2 to the 5 bits that exist before the decimal point
lbb3 = 0b0000011111111111 & lbb1; // Sets lbb3 to the 11 bits that exist after the decimal point
Serial.print("LEFT CAP: ");
Serial.print(lbb2 + (float)lbb3/2048 +(float)lb3/1048576, 4); // Performs an algorithm to assign bit values and add components
Serial.print(" pF ");
--------------

Thank you for your help.

  • Hi,

    lb3 is defined as byte.
    In this part above it is casted to float and the devided by 1048576. This can only result in a fractional number lower then 1. So left shifting is not doing the right job here.

    Regards,
    Stefan
  • Hi,
    i think i got your real question and problem now and i agree that the divide should be by 524288.
    This is only the few from the Energia perspective but i am not the expert for the FDC1004.

    Regards,
    Stefan
  • Hello!

    Thank you for reaching out about this! I do apologize for the delay in the respond as I had to re-familiarize myself with what the code doing - this was almost four years ago.

    You are correct that the last term of the Serial.print statement should be lb3/524288. This would mean it is 19 bits shifted, not 20.

    One note I will make is that this term if it is 0b11111111 that will result in a capacitance value change of 0.0004pF or 400 aF. This is such a small change that you should still be able to use this sample code as the capacitance reading till the 1/1000ths place is correct.

    Thanks again for digging into the code and catching this!

    Reed

  • It's clear now.

    Thank you!