Skip to content

v1.0.2 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SparkFun ACS37800 Power Monitor Arduino Library
version=1.0.1
version=1.0.2
author=SparkFun Electronics
maintainer=SparkFun Electronics
sentence=Library for the Allegro MicroSystems ACS37800 power monitor IC
12 changes: 6 additions & 6 deletions src/SparkFun_ACS37800_Arduino_Library.cpp
Original file line number Diff line number Diff line change
@@ -552,7 +552,7 @@ ACS37800ERR ACS37800::readRMS(float *vRMS, float *iRMS)
volts /= 1000; //Convert to Volts
//Correct for the voltage divider: (RISO1 + RISO2 + RSENSE) / RSENSE
//Or: (RISO1 + RISO2 + RISO3 + RISO4 + RSENSE) / RSENSE
float resistorMultiplier = (((float)_dividerResistance) + ((float)_senseResistance)) / ((float)_senseResistance);
float resistorMultiplier = (_dividerResistance + _senseResistance) / _senseResistance;
volts *= resistorMultiplier;
if (_printDebug == true)
{
@@ -631,7 +631,7 @@ ACS37800ERR ACS37800::readInstantaneous(float *vInst, float *iInst, float *pInst
volts /= 1000; //Convert to Volts
//Correct for the voltage divider: (RISO1 + RISO2 + RSENSE) / RSENSE
//Or: (RISO1 + RISO2 + RISO3 + RISO4 + RSENSE) / RSENSE
float resistorMultiplier = (((float)_dividerResistance) + ((float)_senseResistance)) / ((float)_senseResistance);
float resistorMultiplier = (_dividerResistance + _senseResistance) / _senseResistance;
volts *= resistorMultiplier;
if (_printDebug == true)
{
@@ -686,7 +686,7 @@ ACS37800ERR ACS37800::readInstantaneous(float *vInst, float *iInst, float *pInst
}
//Datasheet says: 3.08 LSB/mW for the 30A version and 1.03 LSB/mW for the 90A version
float LSBpermW = 3.08; // LSB per mW
LSBpermW *= 30.0 / ((float)_currentSensingRange); // Correct for sensor version
LSBpermW *= 30.0 / _currentSensingRange; // Correct for sensor version
power /= LSBpermW; //Convert from codes to mW
//Correct for the voltage divider: (RISO1 + RISO2 + RSENSE) / RSENSE
//Or: (RISO1 + RISO2 + RISO3 + RISO4 + RSENSE) / RSENSE
@@ -720,21 +720,21 @@ ACS37800ERR ACS37800::readErrorFlags(ACS37800_REGISTER_2D_t *errorFlags)
}

//Change the value of the sense resistor (Ohms)
void ACS37800::setSenseRes(int newRes)
void ACS37800::setSenseRes(float newRes)
{
_senseResistance = newRes;
}

//Change the value of the voltage divider resistance (Ohms)
void ACS37800::setDividerRes(int newRes)
void ACS37800::setDividerRes(float newRes)
{
_dividerResistance = newRes;
}

//Change the current-sensing range (Amps)
//ACS37800KMACTR-030B3-I2C is a 30.0 Amp part - as used on the SparkFun Qwiic Power Meter
//ACS37800KMACTR-090B3-I2C is a 90.0 Amp part
void ACS37800::setCurrentRange(int newCurrent)
void ACS37800::setCurrentRange(float newCurrent)
{
_currentSensingRange = newCurrent;
}
18 changes: 9 additions & 9 deletions src/SparkFun_ACS37800_Arduino_Library.h
Original file line number Diff line number Diff line change
@@ -29,15 +29,15 @@ const uint8_t ACS37800_DEFAULT_I2C_ADDRESS = 0x60;
const uint32_t ACS37800_CUSTOMER_ACCESS_CODE = 0x4F70656E;

//Default sense resistance for voltage measurement (Ohms)
const int ACS37800_DEFAULT_SENSE_RES = 8200;
const float ACS37800_DEFAULT_SENSE_RES = 8200;

//Default voltage-divider resistance for voltage measurement (Ohms)
const int ACS37800_DEFAULT_DIVIDER_RES = 2000000;
const float ACS37800_DEFAULT_DIVIDER_RES = 2000000;

//Default current-sensing range
//ACS37800KMACTR-030B3-I2C is a 30.0 Amp part - as used on the SparkFun Qwiic Power Meter
//ACS37800KMACTR-090B3-I2C is a 90.0 Amp part
const int ACS37800_DEFAULT_CURRENT_RANGE = 30;
const float ACS37800_DEFAULT_CURRENT_RANGE = 30;

//Error result
typedef enum {
@@ -415,9 +415,9 @@ class ACS37800
ACS37800ERR readErrorFlags(ACS37800_REGISTER_2D_t *errorFlags); // Read volatile register 0x2D. Return its contents in errorFlags.

//Change the parameters
void setSenseRes(int newRes); // Change the value of _senseResistance (Ohms)
void setDividerRes(int newRes); // Change the value of _dividerResistance (Ohms)
void setCurrentRange(int newCurrent); // Change the value of _currentSensingRange (Amps)
void setSenseRes(float newRes); // Change the value of _senseResistance (Ohms)
void setDividerRes(float newRes); // Change the value of _dividerResistance (Ohms)
void setCurrentRange(float newCurrent); // Change the value of _currentSensingRange (Amps)

private:

@@ -432,13 +432,13 @@ class ACS37800
uint8_t _ACS37800Address = ACS37800_DEFAULT_I2C_ADDRESS;

//The value of the sense resistor for voltage measurement in Ohms
int _senseResistance = ACS37800_DEFAULT_SENSE_RES;
float _senseResistance = ACS37800_DEFAULT_SENSE_RES;

//The value of the divider resistance for voltage measurement in Ohms
int _dividerResistance = ACS37800_DEFAULT_DIVIDER_RES;
float _dividerResistance = ACS37800_DEFAULT_DIVIDER_RES;

//The ACS37800's current sensing range
int _currentSensingRange = ACS37800_DEFAULT_CURRENT_RANGE;
float _currentSensingRange = ACS37800_DEFAULT_CURRENT_RANGE;

//The ACS37800's coarse current gain - needed by the current calculations
float _currentCoarseGain;