This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADS122U04: ADS122U04 Continuous Conversion mode outputs zeros

Part Number: ADS122U04

My application includes ADS122U04 with 3.3V digital and analog supply. AIN0 and AIN1 are connected across a 2K ohm current-sense resistor, which will measure current from a photocell, which measures light. However I am testing right now with no photocell connected, so the input should be zero volts. I expect to measure some zero offset and noise.

I would like to configure a continuous stream of conversions. But for some reason only the first conversion results in a number and all following conversions return 000000.

Here's my code running on a PC, to configure and read the ADC:

var sp = new System.IO.Ports.SerialPort("COM6", 115200);
sp.Open();
           

//reset:
byte[] ResetMessage = new byte[] { 0x55, 0x06 };
sp.Write(ResetMessage, 0, ResetMessage.Length);

byte[] configuration = new byte[] {0x08, 0x08, 0x50, 0x01, 0x00}; // Gain 16, 20 SPS continuous, count/invert, auto-output.

byte[] msg = new byte[] {0x55, 0x00, 0x00};


            int i;
            for (i=0; i < configuration.Length; i++)
            {
                msg[1] = (byte) (0x40 | (byte) unchecked(i << 1));
                msg[2] = configuration[i];
                Console.WriteLine(" sending config " + msg[0].ToString("X2") + msg[1].ToString("X2") + "=>" + msg[2].ToString("X2") );
                sp.Write(msg, 0, msg.Length);
                System.Threading.Thread.Sleep(10);
            }

            //send start
            byte[] StartMessage = new byte[] { 0x55, 0x08 };
            sp.Write(StartMessage, 0, StartMessage.Length);

            while (true)
            {
                unchecked
                {
                    byte seq = (byte) sp.ReadByte();
                    uint adc = (uint) (sp.ReadByte() + ( sp.ReadByte() << 8) + (sp.ReadByte() << 16) );
                    byte seq2 = (byte) sp.ReadByte();
                    uint adc2 = (uint) ( (int) 0xFF000000 + sp.ReadByte() + ( sp.ReadByte() << 8) + (sp.ReadByte() << 16));
                    
                    if ( ( seq == (byte)(~seq2) ) &&
                        (adc == (uint)(~adc2) ) ) // check if the second four bytes are the invert of the first four bytes.
                    {
                        Console.WriteLine(seq.ToString("X2") + " " + adc.ToString("X6") );
                    }

} }// repeat forever

And this is the output:

Hello World!
 sending config 5540=>08
 sending config 5542=>08
 sending config 5544=>50
 sending config 5546=>01
 sending config 5548=>00
Sending Start Message.
01 FCD147
02 000000
03 000000
04 000000
05 000000
06 000000
07 000000
08 000000
09 000000
0A 000000
0B 000000
0C 000000
0D 000000
0E 000000
0F 000000
10 000000
11 000000
...

Any idea why the conversion fails?

I tried configuring instead in one-shot mode, and this sometimes yields non-zero conversion results. But I find that the results are dependent on the timing of my "start" requests. If I send another start soon after the previous conversion is completed and parsed by my PC code, I get a continuous stream of zeros just like I did in continuous conversion mode. If I add a delay of 15ms or more I get noisy data with a positive zero-offset, for example:


1E 0007EA
1F 0007E3
20 000809
21 0007D0
22 0007E8
23 0007A4
24 00080D
25 000803
26 0007F1
27 0007A4
28 0007EF
29 0007E9
2A 000809
2B 0007D4
2C 000807
2D 0008BF
2E 000701
2F 0007EF
30 0007E5
31 0008CB
32 0008B2
33 0007A4
34 000813

However if I increase the delay between "START" messages, the zero-offset changes along with this delay between conversions. With 100ms between conversions, I get a large negative offset:


10 FFD4C1
11 FFD847
12 FFD309
13 FFD676
14 FFD679
15 FFD4C1
16 FFD67B
17 FFD4C0
18 FFD4BC
19 FFD668
1A FFD67B
1B FFD4BD
1C FFD4B4
1D FFD66E
1E FFD4B9
1F FFD667
20 FFD4B3
21 FFD4AF
22 FFD66B
23 FFD67A
24 FFD4BA

It seems that the ADC result seems to depend on timing of the conversion. This is not what I was expecting... I would like the result to be independent of the timing. Any idea what I am doing wrong?

Thank you for any suggestions

  • Hi user5870291,

    Welcome to the E2E forum! In your while loop you are continually reading the buffer, but data at 20sps only becomes available every 50ms. So when using the automatic data read mode, you must make sure that new contents are in the buffer before reading it, otherwise you will be seeing an empty buffer (all 0's). Note that sending a START command in the middle of a conversion will restart the conversion making the time for when the data is output even longer.

    There are a number of ways to overcome this issue. One is by delaying the reading of the buffer so that you wait 50ms between reads. Another method is to use GPIO2 and set it to DRDY mode then trigger an interrupt (or poll the input pin of the micro) to capture the new data following the high to low DRDY transition. Yet another alternative may be to monitor the UART interrupt status looking for new data available on the RX buffer.

    The last alternative is to not use the automatic mode but rather manually read the data by using the RDATA command. So you may wish to use a combination, such as monitoring DRDY then manually reading the data.


    Best regards.
    Bob B