0

Current shunts - ADS1115
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Current shunts - ADS1115

by sspence65 on Fri May 08, 2015 12:43 pm

I have a 100mv / 100 amp shunt. I have a ADS1115.

5v / 65536 = .0000762 v steps

The shunt has a 100 mv drop at 100 amps of current.

I'm having a brain fart. how do I calculate amps per step of the ADC?
Last edited by sspence65 on Fri May 15, 2015 10:34 am, edited 1 time in total.

sspence65
 
Posts: 44
Joined: Tue Sep 21, 2010 8:29 pm
Location: Andrews, SC

Re: Current shunts

by adafruit_support_bill on Fri May 08, 2015 12:55 pm

That depends on the gain setting. If your shunt is going to have a max drop of 100mV, you probably want to use the 16x gain setting which has a range of +/- 256mV.

256 / 32768 = 0.0078125 mV

Since 1mV = 1A of current, 0.0078125 mV = 0.0078125 A (7.8125 mA)

adafruit_support_bill
 
Posts: 81950
Joined: Sat Feb 07, 2009 10:11 am

Re: Current shunts

by sspence65 on Fri May 08, 2015 12:58 pm

Should I use the differential pair, or single ended? I'm also going to be measuring voltage with a voltage divider, so differential pairs will give me isolation?

sspence65
 
Posts: 44
Joined: Tue Sep 21, 2010 8:29 pm
Location: Andrews, SC

Re: Current shunts

by adafruit_support_bill on Fri May 08, 2015 1:10 pm

Differential will give you more noise immunity. Unless you need the extra channels, that would be the way to go.

adafruit_support_bill
 
Posts: 81950
Joined: Sat Feb 07, 2009 10:11 am

Re: Current shunts

by sspence65 on Sun May 10, 2015 6:57 am

Does this look correct:

Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include <Adafruit_ADS1015.h>

Adafruit_ADS1115 ads;  /* Use this for the 16-bit version */

void setup(void)
{
  Serial.begin(9600);
  Serial.println("Hello!");
 
  Serial.println("Getting differential reading from AIN0 (P) and AIN1 (N)");
  Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");
 
  // The ADC input range (or gain) can be changed via the following
  // functions, but be careful never to exceed VDD +0.3V max, or to
  // exceed the upper and lower limits if you adjust the input range!
  // Setting these values incorrectly may destroy your ADC!
  //                                                                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
 
  ads.begin();
}

void loop(void)
{
  int16_t results;
 
  /* Be sure to update this value based on the IC and the gain settings! */
  float multiplier = .0078125F; /* ADS1115  @ +/- .256V gain (16-bit results) */

  results = ads.readADC_Differential_0_1(); 
   
  Serial.print("Differential: "); Serial.print(results); Serial.print("("); Serial.print(results * multiplier); Serial.println("mV)");

  delay(1000);
}


and if so, results * multiplier = amps (assuming the 100a / 100mv shunt) ?

sspence65
 
Posts: 44
Joined: Tue Sep 21, 2010 8:29 pm
Location: Andrews, SC

Re: Current shunts

by adafruit_support_bill on Sun May 10, 2015 8:26 am

Mathematically correct. But subject to some cumulative error due to floating point round-off. A better way to calculate is to save the division for last:

amps = (rawResult * 256) / 32768;

adafruit_support_bill
 
Posts: 81950
Joined: Sat Feb 07, 2009 10:11 am

Re: Current shunts

by sspence65 on Sun May 10, 2015 8:54 am

and if a 100 amp / 75 mv shunt is used

amps = (rawResult * 256) / 32768;
amps = amps *1.333;

and if a 100amp / 50mv shunt is used

amps = (rawResult * 256) / 32768;
amps = amps *2;

sspence65
 
Posts: 44
Joined: Tue Sep 21, 2010 8:29 pm
Location: Andrews, SC

Re: Current shunts

by adafruit_support_bill on Sun May 10, 2015 9:18 am

Yup.

adafruit_support_bill
 
Posts: 81950
Joined: Sat Feb 07, 2009 10:11 am

Re: Current shunts

by sspence65 on Mon May 11, 2015 8:50 am

Per my Extech meter (love it, thank you), I have a motor that draws 1.08 amps. However, the amps calculation with the Arduino reads zero, so I enabled printing "results" to the serial monitor. The variable "results" is equal to 127 when the motor is turned on. Something is wrong with my amps calculation, or the way I'm sending it to the serial monitor?
Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include <Adafruit_ADS1015.h>

Adafruit_ADS1115 ads;  /* Use this for the 16-bit version */

void setup(void)
{
  Serial.begin(9600);
  //Serial.println("Hello!");
 
  //Serial.println("Getting differential reading from AIN0 (P) and AIN1 (N)");
  //Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");
 
  // The ADC input range (or gain) can be changed via the following
  // functions, but be careful never to exceed VDD +0.3V max, or to
  // exceed the upper and lower limits if you adjust the input range!
  // Setting these values incorrectly may destroy your ADC!
  //                                                                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
 
  ads.begin();
}

void loop(void)
{
  int16_t results;
 
  results = ads.readADC_Differential_0_1(); 
  Serial.println(results);   
  Serial.print("Amps: ");
 
  //Serial.print("(");
 
 
  float amps = (results * 256) / 32768;
  //amps = amps * 1.333; //uncomment for 75mv shunt
  //amps = amps * 2; //uncomment for 50mv shunt
 
  Serial.println(amps);
 
 
  //Serial.println("mV)");

  delay(5000);
}

sspence65
 
Posts: 44
Joined: Tue Sep 21, 2010 8:29 pm
Location: Andrews, SC

Re: Current shunts

by adafruit_support_bill on Mon May 11, 2015 9:01 am

On a calculator I get 0.9921875

Looks like you are getting some integer truncation. Try:

Code: Select all | TOGGLE FULL SIZE
float amps = ((float)results * 256.0) / 32768.0;

adafruit_support_bill
 
Posts: 81950
Joined: Sat Feb 07, 2009 10:11 am

Re: Current shunts

by sspence65 on Mon May 11, 2015 9:11 am

Perfect!

sspence65
 
Posts: 44
Joined: Tue Sep 21, 2010 8:29 pm
Location: Andrews, SC

Re: Current shunts

by sspence65 on Mon May 11, 2015 10:19 am

Here is the finished project. Works like a charm. Thank you for your help! Linked to your product and tutorial in the blog post. http://arduinotronics.blogspot.com/2015 ... duino.html

sspence65
 
Posts: 44
Joined: Tue Sep 21, 2010 8:29 pm
Location: Andrews, SC

Re: Current shunts

by adafruit_support_bill on Mon May 11, 2015 10:34 am

Nice writeup! Thanks for posting your results.

adafruit_support_bill
 
Posts: 81950
Joined: Sat Feb 07, 2009 10:11 am

Re: Current shunts - ADS1115

by jtomerli on Mon Jun 01, 2015 12:46 pm

Not sure if I should continue this thread or start a new one.

Thanks for the good article. I am trying to do the same thing, but I am measuring a 100mV/10A shunt on A0/A1, and V behind a 6:1 voltage divider, (~ 4.0V to the channels A1/A2) and using both to get Watts consumed by a pair of heating elements.
I am getting periodic crazy measurments. The measurements are stable one day, then for weeks, I will get a wild fluctuation on the mV measurements.
At the moment, with the heater and power supplies powered off, and the Arduino running, I am getting the same range of fluctuations. If I switch to a 9V battery to power the Arduino, the readings drop to a stable 0.0V with all other PSU's off.

Normal or desired readings are about 70 mV across the shunt. Unstable readings are roughly -25 to 225 mV, and will rapidly fluctuate.
The DMM reading across the shunt is stable, a scope shows little fluctuation.


I measure a 1V difference between the ground of the 24V power supply that running the heaters which is tied to the shunt, and the Arduino ground rail.
If I run the arduino on a 9V battery, or a bench top power supply the readings are rock solid, but I can't use either in the finished project.

Things I have tried:
    have tried unplugging the fan in the schematic, I have bypassed the SSR, I have tried the simplest code as a test.
    I have tried running the Arduino on: USB, the 12VDC PSU in the diagram, a 9V battery, and a 9V wall wart.
    When I use the battery, I measure a 0.5V difference from the 24V PSU and Arduino ground
Should I, or is it safe to tie the 24V PSU ground to the Arduino?

I have been chasing this problem for months and I am sure I am missing something either in the circuit or code, any help is welcome.

viewtopic.php?f=19&t=65300&p=378631&hilit=ads1115#p378631


Hi Loek,

Thanks for your feedback as always. I should have used a schematic with more detail. The voltage divider is 2 resistors. 3K & 15K ohms.
I didn't have any luck with a fast control using PWM, so I use a very slow frequency period 7 seconds on, then 3 seconds off for a 10 second period.
For my application this is fast enough.. I am using digitalWrite to cycle the relay.
Both power supplies are using the same chassis ground on the 120VAC side. I am not sure if that is enough to create a robust ground plane.
On the low voltage DC side, the power supplies have about 20 - 30 mV Voltage difference, that fluctuates constantly.


OK, preliminary fix, I used a voltage regulator running off of the 24VDC PSU to supply 9.8VDC to the Mega 2560, readings are rock steady.
My assumption is that tying the main PSU ground to the Arduino through the V reg fixed the issue of the fluctuating DC shunt readings.
Attachments
Heated Blanket SchematicRevB.jpg
Heated Blanket SchematicRevB.jpg (86.2 KiB) Viewed 2991 times

jtomerli
 
Posts: 11
Joined: Mon Oct 20, 2014 12:21 pm

Please be positive and constructive with your questions and comments.