AnsweredAssumed Answered

AD7147 as a capacitance measuring instrument

Question asked by Ago on Apr 7, 2016
Latest reply on Aug 8, 2016 by Maurice

Hi,

I am using AD7147 to read different capacitor values. I'm using Arduino UNO for the IC programming.

I have no particular requirements for the power settings, but I need the maximum resolution and full scale range.

 

Do I have to setup some particular register?

Moreover, i'm using the I2C comunication without the INT pin. There are some problems with this configuration?

 

I'm using the register settings in the following code.

 

#include <Wire.h>

#include "AD7147RegMap.h"

#define device 0B0101100    // device address

//variables

short unsigned int adLSB=0;

short unsigned int adMSB=0;

short unsigned int LSBi=0; 

short unsigned int MSBi=0;

short unsigned int LSB=0;

short unsigned int MSB=0;

unsigned int i1=0;

unsigned int i2=0;

unsigned int i3=0;

unsigned int c1=0x0010;

unsigned int c2=0x0010;

unsigned int c3=0x0010;

unsigned int cella=0;

unsigned int I2Cdata;

unsigned int t0=0;

unsigned int t1=0;

unsigned int test=0;

int i=0;

//__________________________________________SETUP

void setup() {

// comunication setup

  Serial.begin(115200);

  Wire.begin(); // join i2c bus (address optional for master);

/////// CAPACITIVE SENSOR AD7147 STAGE SET UP  //

    writeI2C(PWR_CONTROL,0b0000010000000000);//reset

//// setup My configuration

    writeI2C(PWR_CONTROL,0x0000); // 1 stage

    writeI2C(STAGE_CAL_EN,0x0001);// enable calibration of 1 stages

    writeI2C(AMB_COMP_CTRL1,0b0000000101100100);

    writeI2C(AMB_COMP_CTRL0,0x32FB);

    writeI2C(AMB_COMP_CTRL1,0x4FF);

    writeI2C(AMB_COMP_CTRL2,0x832);//

    // STAGE 0 CIN 0_________________________________________________________________

   writeI2C(STAGE0_CONNECTION6_0,0xFFFF);    

   writeI2C(STAGE0_CONNECTION12_7,0x3FFF);  

   writeI2C(STAGE0_AFE_OFFSET,0x0000);      

    ////////////////////////////////////////////////////////////////////////////////////////////////////

writeI2C(STAGE0_CONNECTION6_0,0x7FFE);

writeI2C(STAGE0_CONNECTION12_7,0x0FFF);

writeI2C(STAGE0_AFE_OFFSET,0x0000);

writeI2C(STAGE0_SENSITIVITY,0x0000);

writeI2C(STAGE0_OFFSET_LOW,0x0000);  

writeI2C(STAGE0_OFFSET_HIGH,0x0000);

writeI2C(STAGE0_OFFSET_LOW_CLAMP,0x0000);

writeI2C(STAGE0_OFFSET_HIGH_CLAMP,0x0000);

writeI2C( STAGE0_FF_WORD0,0x0000);//          0x0E1

writeI2C( STAGE0_FF_WORD1,0x0000);//          0x0E2

writeI2C( STAGE0_FF_WORD2,0x0000);//          0x0E3

writeI2C( STAGE0_FF_WORD3,0x0000);//          0x0E4

writeI2C( STAGE0_FF_WORD4,0x0000);//          0x0E5

writeI2C( STAGE0_FF_WORD5,0x0000);//          0x0E6

writeI2C( STAGE0_FF_WORD6,0x0000);//          0x0E7

writeI2C( STAGE0_FF_WORD7,0x0000);//          0x0E8

writeI2C( STAGE0_SF_WORD0,0x0000);//          0x0E9

writeI2C( STAGE0_SF_WORD1,0x0000);//          0x0EA

writeI2C( STAGE0_SF_WORD2,0x0000);//          0x0EB

writeI2C( STAGE0_SF_WORD3,0x0000);//          0x0EC

writeI2C( STAGE0_SF_WORD4,0x0000);//          0x0ED

writeI2C( STAGE0_SF_WORD5,0x0000);//          0x0EE

writeI2C( STAGE0_SF_WORD6,0x0000);//          0x0EF

writeI2C( STAGE0_SF_WORD7,0x0000);//          0x0F0

writeI2C( STAGE0_SF_AMBIENT,0x0000);//        0x0F1

writeI2C( STAGE0_FF_AVG,0x0000);//            0x0F2

writeI2C( STAGE0_PEAK_DETECT_WORD0,0x0000);// 0x0F3

writeI2C( STAGE0_PEAK_DETECT_WORD1,0x0000);// 0x0F4

writeI2C( STAGE0_MAX_WORD0,0x0000);//         0x0F5

writeI2C( STAGE0_MAX_WORD1,0x0000);//         0x0F6

writeI2C( STAGE0_MAX_WORD2,0x0000);//         0x0F7

writeI2C( STAGE0_MAX_WORD3,0x0000);//         0x0F8

writeI2C( STAGE0_MAX_AVG,0x0000);//           0x0F9

writeI2C( STAGE0_HIGH_TRESHOLD,0x0000);//     0x0FA

writeI2C( STAGE0_MAX_TEMP,0x0000);//          0x0FB

 

}

//__________________________________________MAIN

void loop()

  t0=micros();

  c1=readI2C(0x00B);

  Serial.println(c1);

}

//__________________________________________function READ

unsigned int readI2C(unsigned int address)

{

Wire.beginTransmission(device);

   adMSB=address >> 8 ;

   adLSB=address & 0xFF ;

   Wire.write(adMSB);            

   Wire.write(adLSB);            

Wire.endTransmission();

//

Wire.requestFrom(device, 2);   

  while(Wire.available())      

{

   MSBi = Wire.read();

   LSBi = Wire.read();

}

  I2Cdata = LSBi |(MSBi  << 8 ) ;

  return(I2Cdata);

}

//__________________________________________function WRITE

unsigned int  writeI2C(unsigned int address,unsigned int data)

{

  Wire.beginTransmission(device);

   adMSB=address >> 8 ;

   adLSB=address & 0xFF ;

   MSB=data >> 8 ;

   LSB=data & 0xFF ;

// address  

   Wire.write(adMSB);             // 0x017=10111         // sends instruction byte

   Wire.write(adLSB);             // 0x017=10111         // sends instruction byte 

//data

   Wire.write(MSB);             // 0x017=10111         // sends instruction byte

   Wire.write(LSB);             // 0x017=10111         // sends instruction byte   

   delay(3);

Wire.endTransmission();

}

Outcomes