AnsweredAssumed Answered

AD7714 acting very weird

Question asked by Cjp3323 on May 1, 2013
Latest reply on May 13, 2013 by Cjp3323

Hi,

 

I'm using the AD7714 for a project at work and its acting very strange on me. Earlier this morning I had it working. I would use two channels and get valid readings off of both channels. Since then, things have gone completely down hill. With time it seems as though the ADC got worse and worse. My battery voltages would drop to zero which they were not and my current readings would give me back a voltage word in the data reg of 2^24. My code for initializing the module is below:

 

void Config_ADC()

{

    unsigned char byte;

    CS_ADC_LOW;

    //Configure the first differential input AIN1/AIN2

    byte = SPI_Transfer(0x24); //next write to filter high reg

    byte = SPI_Transfer(0xC0);

 

    byte = SPI_Transfer(0x34); //next write to filter low reg

    byte = SPI_Transfer(0xC0);

    byte = SPI_Transfer(0x14); //next write to mode reg

    byte = SPI_Transfer(0x20);

 

    //wait for calibration to complete (DRDY line goes low)

    while(DRDY_ADC_PORT);

 

 

    //Configure the second differential input AIN3/AIN4

    byte = SPI_Transfer(0x25); //next write to filter high reg

    byte = SPI_Transfer(0xC0);

 

 

    byte = SPI_Transfer(0x35); //next write to filter low reg

    byte = SPI_Transfer(0xC0);

 

 

    byte = SPI_Transfer(0x15); //next write to mode reg

    byte = SPI_Transfer(0x20);

 

 

    //wait for calibration to complete (DRDY line goes low)

    while(DRDY_ADC_PORT);

 

 

    CS_ADC_HIGH;

}

 

The code for reading the currents and voltages are as follows:

float Read_Bat_Voltage()

{

    unsigned char byte;

    float voltage = 0, word, i;

 

 

    CS_ADC_LOW;

    byte = SPI_Transfer(0x5C); //command to read data from data reg

 

 

//    __delay_ms(500); //make sure DRDY has time to go high when switching channels

    while(DRDY_ADC_PORT); // wait for data to be valid in the adc reg

    for(i=0; i<3;i++)

    {

        word = (float)(SPI_Transfer(0));

        voltage = word*powf(2,(2-i)*8) + voltage;

    }

    CS_ADC_HIGH;

 

 

    writeDebugUARTFlo((2.50/powf(2,24))*voltage);NL();

    //return the voltage on the voltage divider plus the voltage drop across

    //the 0.1 ohm resistor

    return(((2.50/powf(2,24))*voltage)*16.00 + Ic*0.1);

}

 

 

float Read_Current()

{

    unsigned char byte;

    float voltage, voltage_word = 0, word, i;

 

 

    CS_ADC_LOW;

    byte = SPI_Transfer(0x5D); //command to read data from data reg

 

 

    while(DRDY_ADC_PORT); // wait for data to be valid in the adc reg

    for(i=0; i<3;i++)

    {

        word = (float)(SPI_Transfer(0));

        voltage_word = word*powf(2,(2-i)*8) + voltage_word;

    }

    CS_ADC_HIGH;

 

 

    writeDebugUARTStr("voltage on Rsense: ");

  

  

    voltage = ((2.50/powf(2,24))*voltage_word)/20.00; //20 is the gain of the amplifier

     writeDebugUARTFlo(voltage);

      NL();

    return(voltage/0.10); //.05 is the value of the resistor across the terminals of the amp

 

 

}

 

I dont think There are any errors here as (like I've said) I've used it correctly earlier. Now its doing absolutely nothing right. I'm very frustrated with this chip. I can't post the schematic but if anyone spots any code errors or sees something I'm doing wrong here, please let me know.

 

Thanks

Outcomes