ADS1115 lag between samples / sampling consistency issues

Show me in the datasheet where this is specified.

If you are reading DC values then sampling rate is meaningless.

An ADS1115, with it's absolute A/D, is the wrong choice for reading a pot.

A ratiometric A/D is both better for a pot and faster (~10ksps for a basic Uno R3).

Not the datasheet wrong, the "45 clocks" being wrong... Duh.

Sure looks like 45 clocks to me:

In single-shot mode, before we read the ADC register, two additional frames are involved: one to start the conversion and another to check data readiness. Do we need to add these two overhead frames to the timing shown in Figure 30? If so, does that make the actual read time 7 frames (5 + 2), totaling 63 clocks?

Please tell us more about your project.
"Analog input, from a potentiometer. Standing in for a sensor in the future."
Which future sensor, which processor.

See post #42 and read the entire datasheet.

Here is the experimental result.

  • Single ended operation of Ch-0
  • Gain = +/-6.144V
  • Continuous mode
  • ADS1115 Breakout board with 5V supply
  • 100 kHz I2C speed (clock period = 10 us)
  • Arduino UNO R3
  • Test voltage = 3.3V

Result:

22:24:32.665 -> ===========================================
22:24:33.669 -> 16-bit Read time: 549.25 us
22:24:33.701 -> Raw: 17697	Voltage: 3.3 V
22:24:33.701 -> ===========================================
22:24:34.697 -> 16-bit Read time: 554.06 us
22:24:34.729 -> Raw: 17696	Voltage: 3.3 V
22:24:34.763 -> ===========================================
22:24:35.735 -> 16-bit Read time: 551.56 us
22:24:35.771 -> Raw: 17696	Voltage: 3.3 V
22:24:35.803 -> ===========================================

16-bit Read time = 549 us - 553 us
===> 549/10 = 54.9 clocks
===> 54.9/9 ~= 6 bus cycles (frames) which agress with Figure 30 of post #45 @westfw. The extra one bus cycle (90 us - 100 us) is the overhead due to using of Wire.h Librray! Sketch-II takes more overaed (about 915 us) due to the use of Adafruit_ADS1X15.h Librray. If using assembly, the read time will be very much close to 450 us.

So, the effective time required to read 16-bit data from the ADC is 5 x 9 = 45 clocks (450 us) and validats @gilshultz's assertion.

Test Sketch-I:

#include <Wire.h>

// ADS1115 I2C Address (ADDR pin connected to GND)
const uint8_t ADS1115_ADDRESS = 0x48;

#define REG_CONVERSION 0x00
#define REG_CONFIG 0x01

void setup() 
{
  Serial.begin(9600);
  while (!Serial)
    ;

  Wire.begin();
  Serial.println("Initializing ADS1115 in Continuous Mode (Gain = +/- 6.144V)...");
 //initialize TC1 to measure 16-bit ADC read time----
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0;

  // Configuration Hex Word: 0x4083 (Binary: 0100 0000 1000 0011)
  uint16_t config = 0x4083; //default 128 samples; FS = +/- 6.144V, cont.mose, etc.

  // 1. Point to the Configuration Register (0x01)
  Wire.beginTransmission(ADS1115_ADDRESS);
  Wire.write(REG_CONFIG);  //point config register
  Wire.write(highByte(config));  // High byte: 0x40
  Wire.write(lowByte(config));         // Low byte:  0x83
  Wire.endTransmission();

  delay(10);
}

void loop() {
  TCNT1 = 0;
  TCCR1B = 0x01;  //start TC1 with N = 1

  Wire.beginTransmission(ADS1115_ADDRESS);
  Wire.write(REG_CONVERSION);  //point at coversion register
  Wire.endTransmission();

  // Request 2 bytes of conversion data from the ADS1115
  Wire.requestFrom(ADS1115_ADDRESS, (uint8_t)2);

  TCCR1B = 0x00;  //stop TC1
  Serial.print("16-bit Read time: ");
  Serial.print(TCNT1 * 0.0625);
  Serial.println(" us");

  if (Wire.available() == 2) {
    uint8_t highByte = Wire.read();
    uint8_t lowByte = Wire.read();
    int16_t rawValue = (highByte << 8) | lowByte;

    // Convert raw ADC value to voltage
    // With GAIN_TWOTHIRDS (+/-6.144V), the resolution is 6.144V / 32768 = 0.1875 mV per bit
    float voltage = rawValue * 0.1875 / 1000.0;

    // Print results to Serial Monitor
    Serial.print("Raw: ");
    Serial.print(rawValue);
    Serial.print("\tVoltage: ");
    Serial.print(voltage, 1);
    Serial.println(" V");
    Serial.println("===========================================");
  } else {
    Serial.println("Error: Failed to read from ADS1115.");
  }

  delay(1000);
}

Test Sketch-II

#include <Adafruit_ADS1X15.h>   //default 100 kHz I2C speed

Adafruit_ADS1X15 ads1115;

void setup(void)
{
  Serial.begin(9600);
  ads1115.begin();
  /* if (!ads1115.begin())
    {
     Serial.println("Failed to initializs ADS1115.");
     while (true);
    }
    Serial.println("ADS1115 is initialized.");*/
  Serial.println("Hello");
  ads1115.setGain(GAIN_TWOTHIRDS);   //LSB size = 6.144V/32768 = 0.1875 mV
  //---------------------------------
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0;
  //TCCR1B = 0x01;  //start with division fcator 1024
}

void loop(void)
{
  int16_t adc0;
  TCNT1 = 0;
  TCCR1B = 0x01;  //start TC1 with N = 1024
  adc0 = ads1115.readADC_SingleEnded(0);
  TCCR1B = 0x00; //stop TC1
  Serial.print("16-Bit Read Time: "); Serial.print(TCNT1*0.0625); Serial.println (" us");
  Serial.println(adc0);//, HEX);
  float testVolt = adc0 * (6.144 / 32768.0);
  Serial.print("testVolt: "); Serial.println(testVolt, 1);
  delay(1000);
  Serial.println("=======================================");
}
23:01:41.852 -> 16-Bit Read Time: 1377.94 us
23:01:41.884 -> 17695
23:01:41.884 -> testVolt: 3.3
23:01:42.876 -> =======================================
23:01:43.002 -> 16-Bit Read Time: 1365.63 us
23:01:43.002 -> 17695
23:01:43.045 -> testVolt: 3.3
23:01:43.977 -> =======================================

Now that you are on it, can you check single shot mode as well?

Thank you so much for your interest in the results of post #49, which has successfully resolved @jim-p's puzzle and has given us great relief!

I was a bit lost when I observed the read time (550 us) being quite far from 450 us, and I was wondering to whom to attribute this extra 100 us overhead. Luckily, it came to mind to perform Test Sketch-II, which uses the Adafruit_ADS1X15.h library and introduces about 900 us of overhead. Therefore, in Test Sketch-I, the 100 us overhead must be due to Wire.h Library.

given the math you could print 3 decimals... ==> 3,318 Volt

I presented no puzzle but have simply said @gilshultz was wrong and as usual you just ignore any of my questions and just do what you want.

You had been calling @gilshultz wrong all the time without providing the technical reasoning behind it; so, finding the actual data became a puzzle, which we have now successfully resolved through testing. Has this data changed your conclusion regarding @gilshultz?

I have intentionally printed one digit after the decimal point as the header of UNO R3 shows 3.3V.

When measuring time delay, there are two main components to consider:

1. Conversion delay

  • In continuous conversion mode, the data-ready status of the current conversion can be tracked by polling the RDY pin of the ADC, which goes LOW for 8 us after each conversion. This happens every 7.8 ms at 128 samples/sec.
  • In single-shot mode, the data-ready status of the current conversion can be monitored by polling the OS (operational status) bit of the configuration register.

2. Actual delay to read 16-bit data from the conversion registers using I2C communication.

3. My Questions:
(1) When people refer to the time it takes to read 16-bit ADC data, does it mean the sum of 1. and 2., or only 2.?

(2) Which method is preferred for measuring this time delay: micros() or directly using the hardware timer TCNT1?

Usually "read time" on its own means only the I2C transfer in step 2, while the full time from starting a conversion to having the value in your code is the sum of conversion plus I2C, so it is worth stating which one you are reporting. For measuring it, micros() is normally the simpler and clearer choice, since it is portable and its 4-microsecond resolution is usually enough for a millisecond-scale conversion cycle; TCNT1 is useful only if you need finer timing and are willing to handle prescaler and overflow handling yourself.

1. In continuous conversion mode, the conversion takes place in the backgorund at every 7.8 ms intervals for 128 samples/sec (default) option. The ADC eports the end-of-conversion by asserting an 8 us low-ging pulse on the RDY pin. Since, there is no idea to the user about the conversion trigger time, can we really measure the conversion time in this mode?

2. In single shot mode, I run the following small program and found about 3767 us conversion time -- does it make sense?

Output:

13:53:51.596 -> Conversion time in single-shot: 3777 us
13:53:51.656 -> =========================================
13:53:52.643 -> Conversion time in single-shot: 3767 us
13:53:52.677 -> =========================================
13:53:53.658 -> Conversion time in single-shot: 3767 us
13:53:53.692 -> =========================================

Test Sketch:

#include <Wire.h>
#define ADS1115_ADDRESS 0x48
#define REG_CONVERSION 0x00
#define REG_CONFIG 0x01

uint16_t config;

void setup() {
  Serial.begin(9600);
  while (!Serial)
    ;

  Wire.begin();
  Serial.println("Initializing ADS1115 in Continuous Mode (Gain = +/- 6.144V)...");

  TCCR1A = 0;  //initialize TC1 to measure 16-bit ADC read time
  TCCR1B = 0;
  TCNT1 = 0;
}

void loop() {
  TCNT1 = 0;
  config = 0xC183;

  //trigger single-shot conversion 0xC183
  Wire.beginTransmission(ADS1115_ADDRESS);
  Wire.write(REG_CONFIG);        //point config register
  Wire.write(highByte(config));  // High byte: 0xC1
  Wire.write(lowByte(config));   // Low byte:  0x83
  Wire.endTransmission();

  //point config register
  Wire.beginTransmission(ADS1115_ADDRESS);
  Wire.write(REG_CONFIG);  //point config register
  Wire.endTransmission();

  TCCR1B = 0x01;  //start TC1 wit N = 1
  do              //chcek end of converson by polling bit-15 of config register
  {
    Wire.requestFrom(ADS1115_ADDRESS, 1);
  } while (bitRead(Wire.read(), 7) != HIGH);
  TCCR1B = 0x00;  //Stop TC1
  Serial.print("Conversion time in single-shot: ");
  Serial.print((uint16_t)(TCNT1 * 0.0625));  //shows: 3770 us
  Serial.println(" us");
  Serial.println("=========================================");
  delay(1000);
}

Note: The effective read time (in single shot mode):
Conversion time + actual read time
===> 3767 + 550 = 4317 us.

I'm not sure, but I was expecting both to be in range of 8ms.

Are you saying 8 ms looking at the sampling rate -- 1/128 = 7.8 ms?

The ADC is taking the sample of the analog input at every 7.8 ms intervals. Is not the conversion time different from the sampling interval?

Just what I would expect. With marginal difference to continuous ..