Strange readings from the AD7998 ADC

Discussion in 'Embedded Systems and Microcontrollers' started by Litch, Apr 5, 2013.

  1. Litch

    Thread Starter Member

    Jan 25, 2013
    86
    7
    Original design thread HERE.

    Attached is a (partial) circuit diagram of what I have in place, this hooks up to a Raspberry Pi via the top-left header which I'll summarise:

    From the RPi header (P1 bottom-left, P2 top-left, P3 2nd-from-bottom-left):
    * P1 is 3V3 supply for the AD7998 (centre)
    * P3+5 are SDA/SCL
    * P7 is CONVST pin on the AD7998
    * P9 is GND
    * P11 goes to a 330R, then to the base of a BC548
    * P13+15 are irrelevant
    * P17 is 3V3 supply (Same supply as P1) for the BC548

    Now, if I throw a 59K resistor between V+ (BC548 emitter) and any pin on that ADC header I get this inconsistent output from my program (below), but if I have all the pins open circuit then the reading is a solid 1.6 volts (Half Vref?)

    I'm confused.

    Code ( (Unknown Language)):
    1. Channel 00 = 3.299194 (Alert = 0, 0x0FFF)
    2. Channel 01 = 3.299194 (Alert = 1, 0x1FFF)
    3. Channel 02 = 0.000000 (Alert = 1, 0x2000)
    4. Channel 03 = 0.000000 (Alert = 0, 0x3000)
    5. Channel 04 = 0.000000 (Alert = 1, 0x4000)
    6. Channel 05 = 0.011279 (Alert = 1, 0x500E)
    7. Channel 06 = 0.448755 (Alert = 0, 0x622D)
    8. Channel 07 = 3.299194 (Alert = 0, 0x7FFF)
    9.  
    10. Channel 00 = 3.299194 (Alert = 0, 0x0FFF)
    11. Channel 01 = 3.299194 (Alert = 0, 0x1FFF)
    12. Channel 02 = 3.299194 (Alert = 1, 0x2FFF)
    13. Channel 03 = 3.299194 (Alert = 0, 0x3FFF)
    14. Channel 04 = 3.299194 (Alert = 1, 0x4FFF)
    15. Channel 05 = 3.299194 (Alert = 1, 0x5FFF)
    16. Channel 06 = 0.000000 (Alert = 0, 0x6000)
    17. Channel 07 = 0.000000 (Alert = 0, 0x7000)
    18.  
    19. Channel 00 = 3.299194 (Alert = 0, 0x0FFF)
    20. Channel 01 = 3.299194 (Alert = 1, 0x1FFF)
    21. Channel 02 = 3.299194 (Alert = 1, 0x2FFF)
    22. Channel 03 = 3.299194 (Alert = 0, 0x3FFF)
    23. Channel 04 = 3.299194 (Alert = 1, 0x4FFF)
    24. Channel 05 = 3.299194 (Alert = 1, 0x5FFF)
    25. Channel 06 = 3.299194 (Alert = 0, 0x6FFF)
    26. Channel 07 = 2.274390 (Alert = 0, 0x7B07)
    27.  
    28. Channel 00 = 3.299194 (Alert = 0, 0x0FFF)
    29. Channel 01 = 3.299194 (Alert = 0, 0x1FFF)
    30. Channel 02 = 3.299194 (Alert = 1, 0x2FFF)
    31. Channel 03 = 0.000000 (Alert = 0, 0x3000)
    32. Channel 04 = 0.000000 (Alert = 1, 0x4000)
    33. Channel 05 = 0.000000 (Alert = 1, 0x5000)
    34. Channel 06 = 0.001611 (Alert = 0, 0x6002)
    35. Channel 07 = 2.145483 (Alert = 0, 0x7A67)
    36.  
    Source:
    Code ( (Unknown Language)):
    1.  
    2.    
    3. for (int i = 0; i < 8; i++) {
    4.     // Channel is masked as 0b0CCC 0000
    5.     // Read Single flag is 0b1000 0000
    6.     channel = (i << AD799X_CHANNEL_SHIFT)
    7.         | AD7997_8_READ_SINGLE;
    8.     // Write command
    9.     if (write(m_i2c,&channel,1) != 1) {
    10.         printf("Failed to write to the i2c bus: %s\n",
    11.             strerror(errno));
    12.     }
    13.     // Wait 5uS
    14.     delay_us(5);
    15.     // Read from device, format is:
    16.     // ACCC DDDD DDDD DDDD
    17.     // Where:
    18.     //   A = alarm
    19.     //   C[3] = channel
    20.     //   D[12] = voltage
    21.     if (read(m_i2c,buf,2) != 2) {
    22.         printf("Failed to read from the i2c bus: %s\n",
    23.             strerror(errno));
    24.     } else {
    25.         // Dump it
    26.         data = (float)((buf[0] & 0b00001111) << 8) + buf[1];
    27.         data = (data / 4096.0f) * 3.3f;
    28.         channel = ((buf[0] & 0b01110000) >> 4);
    29.         printf("Channel %02d = %04f (Alert = %d, 0x%02X%02X)\n",
    30.             channel, data, (buf[(i<<1) + 0] & 0x80) ? 1 : 0,
    31.             buf[0], buf[1]);
    32.     }
    33. }
    34.  
     
Loading...