Losing my mind getting ADS1015 to output mV

Like it says. I’ve been hacking at this on and off for days. I’ve used the ADS1015 and ADS1115 before, successfully. But I guess my aging brain just can’t figure out what’s going on with it now. Here’s a snippet of code where I set the 1015 to a gain of 16, read a value 10 times, average it, and display the raw value, followed by the scaled value in mV (disregard the /1000 - this is voltage across a 1K resistor, so I’m doing that to get current). A Fluke 179 across A2 and A3 on the ADS1015 is showing 3.8mV, which is very close to what I expect (it’s measuring current from a 3v button cell providing backup power for RAM) which translates to 3.8uA when the 1K resistor is factored in. But for the life of me, I can’t get the 1015 value to make sense. I get -4832 for the “* 10” value, then I divide it by 10, divide it by 1000, and multiply it by 0.125mV per bit and get… 60.4. If I divide by 0.125 instead, I get 3.866uA which agrees with the meter, but I’m supposed to multiply by the mV/bit, right??? :’(

 ads_1015b.setGain(GAIN_SIXTEEN);// 16x gain  +/- 0.256V  1 bit = 0.125mV

  Serial.println(" ");
  raw = 0; 
  for (int i = 0; i < 10; i++) {
    raw = raw + ads_1015b.readADC_Differential_2_3(); 
    delay(100);
  }
 
  Serial.println("ADSb_Diff_2_3 * 10=" + String(raw));
  B1Current = ((abs(raw) / 10.0)  / 1000) * 0.125; //16x gain  +/- 0.256V  1 bit = 0.125mV:

Always provide the entire code. I see things that could be wrong but they can't be checked out of this snippet of code.

I didn’t post the whole thing because it’s 2400 lines. However, in trying to find the relevant parts to add for you, I found that I had declared them as Adafruit_ADS1115 rather than Adafruit_ADS1015, and it looks like that might have been the problem. I’ll test it more tomorrow.

culturedropout:
...this is voltage across a 1K resistor, so I'm doing that to get current...

This raises the question if you're within the common mode range of the ADS.
Basically, voltage on both sides of the 1k resistor must stay within the boundaries of the supply of the ADS.
Leo..

culturedropout:
I didn't post the whole thing because it's 2400 lines. However, in trying to find the relevant parts to add for you, I found that I had declared them as Adafruit_ADS1115 rather than Adafruit_ADS1015, and it looks like that might have been the problem. I'll test it more tomorrow.

No problem with a large code. I have methods to search for what I want to know, Help Yourself.

Wawa:
This raises the question if you're within the common mode range of the ADS.
Basically, voltage on both sides of the 1k resistor must stay within the boundaries of the supply of the ADS.
Leo..

The expected range is less than 10uA across 1k. Supply is 5v, and the battery is 3v, in series between ground and the 1k. Should be okay, right?

Supply is 5v, and the battery is 3v, in series between ground and the 1k.

Schematic, PLEASE.

I had planned to use ADS1115’s so that’s how I started writing the code, but a couple of thousand lines later I found that all I had on hand were ADS1015’s, so I used those, but I forgot to change the initialization. DOH

WAS:
Adafruit_ADS1115 ads_1015(0x48); // single-ended for power supply voltages
Adafruit_ADS1115 ads_1015b(0x49); // differential, for backup battery current

NOW:
Adafruit_ADS1015 ads_1015(0x48); // single-ended for power supply voltages
Adafruit_ADS1015 ads_1015b(0x49); // differential, for backup battery current

Now the readings are as expected. That’s embarrassing.

FWIW, I’ve attached a schematic of the part of the board I’m testing. I have the ADC inputs connected to TP11 and TP12, and am doing a differential reading across them, measuring the voltage on the 1K series resistor to determine current being drawn from the battery on the board under test.

Oh - and the battery is a 3v lithium coin cell.

battery.PNG

Railroader:
No problem with a large code.

YOU might not have a problem with large code, but the forum software very well!
My messages were frequently truncated due to excess of size, even if it was between code delimiters.

RIN67630:
YOU might not have a problem with large code, but the forum software very well!
My messages were frequently truncated due to excess of size, even if it was between code delimiters.

Supplied code not showing the reason for the error helps nobody. Why spend time on guessing? Large amounts of code has to be included as file.

Code not containing the reason for the trouble helps nobody to do better then guessing. Code too large for code tags has to be included as a file.