How to interface arduino (any ) to AD7156 and get the average capacitance value

#include <Wire.h>
//int chip_addr = 0x48; //AD7150 adress
int chip_addr= 0x48 ;// address of device during write cycle
#define ch1_dataH_addr 0x01 //Address to point the Data High of Ch1
#define ch1_dataL_addr 0x02 //Address to point the Data Low of Ch1
#define ch1_avgH_addr  0x05
#define ch1_avgL_addr  0x06

#define ch1_SetupR_addr 0x0B //Setup (range) register address for Ch1
#define ConfigR_addr 0x0F //Configuration register (operation mode -threshold-) 
#define Ch1_ThHR_addr 0x09 //Ch1 Threshold High Register
#define Ch1_ThLR_addr 0x0A //Ch1 Threshold Low Register

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Wire.begin();   
}

void rconfig1()
{
  Wire.beginTransmission(chip_addr);
  Wire.write(ch1_SetupR_addr); //Move pointer to the register address
  Wire.write(203); //Setup features for range (bx11001011)
  Wire.endTransmission();
}

float input_range=1.0;
void loop() {
  //Get capacitance data
  // move the register pointer back to the second register
  Wire.beginTransmission(chip_addr); // 
  Wire.write(1); // "move your register pointer back to 01h"
  Wire.endTransmission();
  // now get the data from the AD7156
  Wire.requestFrom(chip_addr, 4); 
  while(Wire.available())    // slave may send less than requested
  { 
  byte ch1H = Wire.read(); // first received byte stored here
  byte ch1L = Wire.read(); // second received byte stored here
   unsigned int ch1 = ch1H*256 + ch1L; //Concatanates the two bytes into one 16 bit word for capacitor 1.
 float cap1=(ch1-12288)*input_range/40960;
//print the data on serial monitor, data that was gotten from the registers that store capacitance values
 // Serial.println("Ch1="); 
  //Serial.println(ch1,BIN);
 // Serial.println(" Ch1="); 
 // Serial.println(ch1);
  Serial.println(" Capacitance ="); 
 Serial.println(cap1); 
  }
  delay(700);
}

I'm getting a continuous capacitance value , but i need the average value for my experiment
(the capacitance that i am using is not fixed capacitance)

We need a schematic to know how your external circuit is connected and links for ALL the hardware you are using.

i dont have schematic
but i have an arduino uno
AD7156 CDC
and 2 capacitor plate (copper strips)
i want to find the capacitance of this copper strip

Then you need to make one before anyone can offer anything more than just generalised help.

No schematic means you can never check if you have got your wiring as you intended, let alone any one else.

OK, so check this:

This starts reading at 0x01. According to the datasheet, that is 'Ch1 data high'.
Average channel data starts at 0x05. So start by changing the '1' in the quoted line of code above into '5' and see if you get a better result.

Furthermore, you are requesting 4 bytes from the device, but consequently only read 2. What happens with the other 2? Probably you get lucky and force the device into a new communication session on the next iteration through your main loop, but it sure isn't the way you should be doing this.
If you only want to read channel 1, just request 2 bytes instead of 4.

Looks like you took some example code and started modifying it, but I think you need to pay a bit more attention to the modifications you make and have a good look at the datasheet of the chip you're using.

One more thing: if this is capacity measurement, keep in mind that stray/parasitic capacity will play a role. You mention 2 copper plates in proximity as your DUT (device under test), but the tracks/wires to the chip will also have some capacity. You'll have to compensate for this in your measurements. Also keep in mind that the AD7156 can compensate for this automatically, but I do not know if this compensation is also included in the values you can read from the data register. Again, consult the datasheet on this.

Thank you sir!!
Yes I'm only using Ch1
and i did take a sample code and modified it by referring the datasheet

Thanks for the help

Sir i have a doubt
what should i put in the input range of equation
and what will be the equation of average

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.