ADS1015 data rate vs. gain issue

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
zep
 
Posts: 11
Joined: Sat Dec 18, 2021 9:45 pm

ADS1015 data rate vs. gain issue

Post by zep »

Working the singleended sketch with 0.100 dc input I observe apparent unforced gain changes when using data rates above about 500. I use setGain for the 6 gain ranges and setDataRate for data rate. For data rates less than about 500 I get 0.100 volts using computeVolts for ALL gains. But for example, with setGain(GAIN_TWO) and setDataRate(600) I get 0.200 volts. getGain() returns the correct value of 1024 for GAIN_TWO in this case. I'm kinda stuck here, maybe just missed something. Thank you.

User avatar
adafruit_support_bill
 
Posts: 88136
Joined: Sat Feb 07, 2009 10:11 am

Re: ADS1015 data rate vs. gain issue

Post by adafruit_support_bill »

Please post a complete program exhibiting the problem.

User avatar
zep
 
Posts: 11
Joined: Sat Dec 18, 2021 9:45 pm

Re: ADS1015 data rate vs. gain issue

Post by zep »

Thanks. Input to all 4 SE inputs is 0.100 VDC. I should have said ' with setGain(GAIN_TWO) and setDataRate(920) I get 0.200 volts'. If I change data rate to 490 I get the correct 0.100 volts. Also I tried adding delays, changing the input voltage and taking multiple readings and still get the same effect. Some gains at data rates above 490 give correct result but other gains settings seem to set the PGA incorrectly. In any case readings are stable and repeatable.

Code: Select all

#include <Adafruit_ADS1X15.h>
//Adafruit_ADS1115 ads;  /* Use this for the 16-bit version */
Adafruit_ADS1015 ads;     /* Use this for the 12-bit version */
int16_t adc0, adc1, adc2, adc3;
float volts0, volts1, volts2, volts3, dataRate, sampint;
int gain;

void setup(void)
{
  Serial.begin(9600);
  //                                                         ADS1015           ADS1115
  //                                                        -------            -------
  //ads.setGain(GAIN_TWOTHIRDS);  // 2/3x gain +/- 6.144V  1 bit = 3mV         0.1875mV (default)
  //ads.setGain(GAIN_ONE);        // 1x gain   +/- 4.096V  1 bit = 2mV         0.125mV
  ads.setGain(GAIN_TWO);          // 2x gain   +/- 2.048V  1 bit = 1mV         0.0625mV
  // ads.setGain(GAIN_FOUR);      // 4x gain   +/- 1.024V  1 bit = 0.5mV       0.03125mV
  //ads.setGain(GAIN_EIGHT);      // 8x gain   +/- 0.512V  1 bit = 0.25mV      0.015625mV
  //ads.setGain(GAIN_SIXTEEN);    // 16x gain  +/- 0.256V  1 bit = 0.125mV     0.0078125mV
  gain = ads.getGain();
 
  //ads.setDataRate(128);  // .0078125 sample interval
  //ads.setDataRate(250);  // .0040000 sample interval
  //ads.setDataRate(490);    // .0020408 sdample interval
  ads.setDataRate(920);  // .0010869 sample interval
  //ads.setDataRate(1600); // .0006250 sample interval (default)
  //ads.setDataRate(2400); // .0004167 sample interval
  //ads.setDataRate(3300); // .0003030 sample interval
  dataRate = ads.getDataRate(); sampint = 1/dataRate;
  
  if (!ads.begin()) {
    Serial.println("Failed to initialize ADS.");
    while (1);
  }
}

void loop(void)
{
  adc0 = ads.readADC_SingleEnded(0);
  adc1 = ads.readADC_SingleEnded(1);
  adc2 = ads.readADC_SingleEnded(2);
  adc3 = ads.readADC_SingleEnded(3);

  volts0 = ads.computeVolts(adc0);
  volts1 = ads.computeVolts(adc1);
  volts2 = ads.computeVolts(adc2);
  volts3 = ads.computeVolts(adc3);

  if (gain==0){ Serial.println("2/3x gain +/- 6.144V  1 bit = 3mV"); }
  if (gain==512){ Serial.println("1x gain   +/- 4.096V  1 bit = 2mV"); }
  if (gain==1024){ Serial.println("2x gain   +/- 2.048V  1 bit = 1mV"); }
  if (gain==1536){ Serial.println("4x gain   +/- 1.024V  1 bit = 0.5mV"); }
  if (gain==2048){ Serial.println("8x gain   +/- 0.512V  1 bit = 0.25mV"); }
  if (gain==2560){ Serial.println("16x gain  +/- 0.256V  1 bit = 0.125mV"); }
  Serial.print("Data Rate: "); Serial.print(dataRate,0); Serial.print("  "); Serial.print("Sample interval: "); Serial.println(sampint,7);
   
  Serial.print("AIN0: "); Serial.print(adc0); Serial.print("  "); Serial.print(volts0,4); Serial.println(" V");
  Serial.print("AIN1: "); Serial.print(adc1); Serial.print("  "); Serial.print(volts1,4); Serial.println(" V");
  Serial.print("AIN2: "); Serial.print(adc2); Serial.print("  "); Serial.print(volts2,4); Serial.println(" V");
  Serial.print("AIN3: "); Serial.print(adc3); Serial.print("  "); Serial.print(volts3,4); Serial.println(" V");
  
  Serial.println("-----------------------------------------------------------");
   
  delay(1000);
}
Last edited by adafruit_support_bill on Sun Dec 19, 2021 10:04 am, edited 1 time in total.
Reason: Please use [code] tags when posting code to the forums.

User avatar
adafruit_support_bill
 
Posts: 88136
Joined: Sat Feb 07, 2009 10:11 am

Re: ADS1015 data rate vs. gain issue

Post by adafruit_support_bill »

Like the gain setting, the data rate settings have pre-defined constants in the header. You need to use these in your call to setDataRate.

Code: Select all

/** Data rates */
#define RATE_ADS1015_128SPS (0x0000)  ///< 128 samples per second
#define RATE_ADS1015_250SPS (0x0020)  ///< 250 samples per second
#define RATE_ADS1015_490SPS (0x0040)  ///< 490 samples per second
#define RATE_ADS1015_920SPS (0x0060)  ///< 920 samples per second
#define RATE_ADS1015_1600SPS (0x0080) ///< 1600 samples per second (default)
#define RATE_ADS1015_2400SPS (0x00A0) ///< 2400 samples per second
#define RATE_ADS1015_3300SPS (0x00C0) ///< 3300 samples per second

User avatar
zep
 
Posts: 11
Joined: Sat Dec 18, 2021 9:45 pm

Re: ADS1015 data rate vs. gain issue

Post by zep »

I put your code in the header and modified calls as ADS1015.setDataRate(920); and ADS1015.setGain(GAIN_TWOTHIRDS);
I still get same result. Where are the gain constants defined?

User avatar
adafruit_support_bill
 
Posts: 88136
Joined: Sat Feb 07, 2009 10:11 am

Re: ADS1015 data rate vs. gain issue

Post by adafruit_support_bill »

The constants are already defined in the library header file. You need to use one of the constants in your call - just like the way you do for the call to setGain.

Code: Select all

ads.setDataRate(RATE_ADS1015_920SPS ); 

User avatar
zep
 
Posts: 11
Joined: Sat Dec 18, 2021 9:45 pm

Re: ADS1015 data rate vs. gain issue

Post by zep »

It works!! Thanks so much for your help!! Now I will go forward with some real time-variant data.
zep

User avatar
zep
 
Posts: 11
Joined: Sat Dec 18, 2021 9:45 pm

Re: ADS1015 data rate vs. gain issue

Post by zep »

Now I am trying to acquire a 10Hz sinewave 1.0V P-P (0 to +1.0V) . I use default data rate 1600SPS and a for loop to grab the data:

for (i = 0; i < 256; ++i) {
ADarray_0 = ads.readADC_SingleEnded(0);
}

My question is; should I expect to realize the 1600SPS data rate with the for loop?

After the for loop I read the 256 points and see period of the clean sinewave is about 46 points which correlates to frequency of about 35Hz, it should be 10Hz. The 35Hz suggests data rate of about 460SPS, far below 1600SPS. I have set I2C clock to 400KHz.

User avatar
adafruit_support_bill
 
Posts: 88136
Joined: Sat Feb 07, 2009 10:11 am

Re: ADS1015 data rate vs. gain issue

Post by adafruit_support_bill »

The sample rate of the device is the rate at which it performs conversions. That is independent of how fast your code runs.

The library is not optimized for speed and does not support continuous conversion mode. The call to ads.readADC_SingleEnded(0) instructs the device to perform a single conversion and waits for the result. Sample rate will be limited by conversion time as well as the overhead of the i2c bus communication.

It looks like the Sparkfun library has support for continuous mode: https://github.com/sparkfun/SparkFun_AD ... no_Library

User avatar
zep
 
Posts: 11
Joined: Sat Dec 18, 2021 9:45 pm

Re: ADS1015 data rate vs. gain issue

Post by zep »

Thanks so much again, very good explanation to penetrate my hard skull. Things are starting to make more sense now.
And thanks for pointer to possible solution. I'm still an Adafruit customer.
zep

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”