Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to read different channel values #3

Open
nuwanprabhath opened this issue Aug 18, 2020 · 0 comments
Open

Unable to read different channel values #3

nuwanprabhath opened this issue Aug 18, 2020 · 0 comments

Comments

@nuwanprabhath
Copy link

nuwanprabhath commented Aug 18, 2020

Hi,

I'm using the example code you have to get capacitance values of three channels. Even though I pass different channel values to the second parameter of "configureMeasurementSingle", when I'm printing data into the serial console, I can observe that when I touch one electrode, values of all three channels increase rather than one channel. My code is below. I have used the Texas Instrument (TI) Sensing Solution software to do the same with the same arrangement and it shows the expected behaviour.

Even with a single channel read, when I touch any channel, it increases the capacitance value rather increase when touching the selected channel. But this is not the case with the same arrangement with TI software, it only shows an increased capacity of one channel.

#include <Wire.h>
#include <Protocentral_FDC1004.h>

#define UPPER_BOUND  0X4000                 // max readout capacitance
#define LOWER_BOUND  (-1 * UPPER_BOUND)
#define MEASURMENT 0                       // measurment channel

int capdac = 0;
char result[100];

FDC1004 FDC1;
FDC1004 FDC2;
FDC1004 FDC3;

void setup()
{
  Wire.begin();        //i2c begin
  Serial.begin(9600); // serial baud rate
}

void loop()
{
  Serial.print("C2:");
  int channel=1;
  FDC1.configureMeasurementSingle(MEASURMENT, channel, capdac);
  FDC1.triggerSingleMeasurement(MEASURMENT, FDC1004_100HZ);

  //wait for completion
  delay(15);
  uint16_t value[2];
  if (! FDC1.readMeasurement(MEASURMENT, value))
  {
    int16_t msb = (int16_t) value[0];
    int32_t capacitance = ((int32_t)457) * ((int32_t)msb); //in attofarads
    capacitance /= 1000;   //in femtofarads
    capacitance += ((int32_t)3028) * ((int32_t)capdac);

    Serial.print((((float)capacitance/1000)),4);

    if (msb > UPPER_BOUND)               // adjust capdac accordingly
	{
      if (capdac < FDC1004_CAPDAC_MAX)
	  capdac++;
    }
	else if (msb < LOWER_BOUND)
	{
      if (capdac > 0)
	  capdac--;
    }

  }

  Serial.print(":C3:");
  channel=2;

  FDC2.configureMeasurementSingle(MEASURMENT, channel, capdac);
  FDC2.triggerSingleMeasurement(MEASURMENT, FDC1004_100HZ);

  //wait for completion
  delay(15);
  uint16_t value1[2];
  if (! FDC2.readMeasurement(MEASURMENT, value1))
  {
    int16_t msb = (int16_t) value1[0];
    int32_t capacitance = ((int32_t)457) * ((int32_t)msb); //in attofarads
    capacitance /= 1000;   //in femtofarads
    capacitance += ((int32_t)3028) * ((int32_t)capdac);

    Serial.print((((float)capacitance/1000)),4);

    if (msb > UPPER_BOUND)               // adjust capdac accordingly
	{
      if (capdac < FDC1004_CAPDAC_MAX)
	  capdac++;
    }
	else if (msb < LOWER_BOUND)
	{
      if (capdac > 0)
	  capdac--;
    }

  }

  Serial.print(":C4:");
  channel=3;
  FDC3.configureMeasurementSingle(MEASURMENT, channel, capdac);
  FDC3.triggerSingleMeasurement(MEASURMENT, FDC1004_100HZ);

  //wait for completion
  delay(15);
  uint16_t value2[2];
  if (! FDC3.readMeasurement(MEASURMENT, value2))
  {
    int16_t msb = (int16_t) value2[0];
    int32_t capacitance = ((int32_t)457) * ((int32_t)msb); //in attofarads
    capacitance /= 1000;   //in femtofarads
    capacitance += ((int32_t)3028) * ((int32_t)capdac);

    Serial.print((((float)capacitance/1000)),4);

    if (msb > UPPER_BOUND)               // adjust capdac accordingly
	{
      if (capdac < FDC1004_CAPDAC_MAX)
	  capdac++;
    }
	else if (msb < LOWER_BOUND)
	{
      if (capdac > 0)
	  capdac--;
    }

  }
  Serial.println("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant