diff --git a/library.properties b/library.properties index b92d171..e50347b 100644 --- a/library.properties +++ b/library.properties @@ -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 diff --git a/src/SparkFun_ACS37800_Arduino_Library.cpp b/src/SparkFun_ACS37800_Arduino_Library.cpp index 8e814ad..f0796c1 100644 --- a/src/SparkFun_ACS37800_Arduino_Library.cpp +++ b/src/SparkFun_ACS37800_Arduino_Library.cpp @@ -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,13 +720,13 @@ 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; } @@ -734,7 +734,7 @@ void ACS37800::setDividerRes(int 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; } diff --git a/src/SparkFun_ACS37800_Arduino_Library.h b/src/SparkFun_ACS37800_Arduino_Library.h index 4888150..e216b1d 100644 --- a/src/SparkFun_ACS37800_Arduino_Library.h +++ b/src/SparkFun_ACS37800_Arduino_Library.h @@ -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;