AnsweredAssumed Answered

AD7780 Output Code Format

Question asked by Dogan on Jun 22, 2012
Latest reply on Jun 28, 2012 by J.Gealon

Hi dear,

I am using AD7780 24-bit ADC for reading loadcell. But, not find the 32-bit output  value format of AD7780 in datasheet.

And I am need data/clock timing information.

My code is below. Where is wrong?

//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

typedef union

{

    struct

    {

        xBYTE PAT0:1;        // Status pattern bits. When the user read data from the Ad7780, an patter check can be performed.

        xBYTE PAT1:1;        // PAT1     PAT0

                            //  0        1   Indicates that the serial transfer from the ADC was performed correctly(default).

                            //  Ather, was not performed correctly.

        xBYTE GAIN:1;        // Gain bit,    0: gain = 128    1: gain = 1

        xBYTE ID0:1;        // ID Bits

        xBYTE ID1:1;        // ID1 = 0, ID0 = 1 : Indicate the ID number for the AD7780

        xBYTE ERR:1;        // Error bit,    1: an error occurred during conversion.(An error occurred when the analog inputs aoutside the range)

        xBYTE FILTER:1;        // Filter bit,     0: 16.7Hz  1: 10Hz

        xBYTE RDY:1;        // Ready bit,     0: a conversion is available.

    }Bits;

    xBYTE Value;

}AD7780_STATUS;

 

typedef union

{

    struct

    {

        xBYTE :8;

        xBYTE :8;

        xBYTE :7;

        xBYTE Sign:1;

        xBYTE :8;

    }Bits;

     xBYTE Byte[4];

    xINT32 Value;

}AD7780_ADC;

 

void ad7780Init(void)

{

........

........

}

 

void ad7780Task(void)

{

            if(DOUT_RDY == 0)

            {

                AD7780_STATS Status;

                   AD7780_ADC Adc;

               

               

                Adc.Value = 0;

                Adc.Byte[0] = ad7780ReadByte();

                Adc.Byte[1] = ad7780ReadByte();

                Adc.Byte[2] = ad7780ReadByte();

               

                Status.Value = ad7780ReadByte();

               

                if(Status.Bits.ERR == 1)

                {

                    // An error occrred during conversion.

                    // (An error occrred when the analog inputs outside the range).

                    AD7780.State = AD7780_STATE_ERROR_INPUT_RANGE;

                    sm = SM_AD7780_RESET;

                }

                else

                if(!(Status.Bits.PAT0 == 1 && Status.Bits.PAT1 == 0))

                {

                    // Indicates that serial transfer from the ADC

                    // was not performed the correctly.

                    AD7780.State = AD7780_STATE_ERROR_SERIAL_TRANSFER;

                    sm = SM_AD7780_RESET;

                }

                else

                if(Status.Bits.RDY == 0)

                {

                    if(Adc.Bits.Sign == 1)

                    {

                        // Result is positive.

                        // Clear the sign bits.

                        Adc.Value &= 0x007FFFFF;

                    }

                    else

                    {

                        // Result is negative.

                        // Convert the binary complement.

                        Adc.Value |= 0xFF800000;

                    }

 

                }

            }

}

 

xBYTE ad7780ReadByte(void)

{

    xBYTE data;

     xINT bI;

   

    data = 0x00;

    for(bI = 0x0001; bI < 0x0100; bI <<= 1)

    {

        SCLK = 0;

        asm("nop");

        asm("nop");

        SCLK = 1;

        asm("nop");

        asm("nop");

        if(DOUT_RDY)

        {

            data |= bI;

        }

    }

   

    return data;

}

//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Outcomes