Skip to content

Commit cfa3828

Browse files
authored
Merge pull request #2 from sparkfun/v1.0.2
v1.0.2
2 parents 89ecf4c + c870f97 commit cfa3828

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun ACS37800 Power Monitor Arduino Library
2-
version=1.0.1
2+
version=1.0.2
33
author=SparkFun Electronics
44
maintainer=SparkFun Electronics
55
sentence=Library for the Allegro MicroSystems ACS37800 power monitor IC

src/SparkFun_ACS37800_Arduino_Library.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ ACS37800ERR ACS37800::readRMS(float *vRMS, float *iRMS)
552552
volts /= 1000; //Convert to Volts
553553
//Correct for the voltage divider: (RISO1 + RISO2 + RSENSE) / RSENSE
554554
//Or: (RISO1 + RISO2 + RISO3 + RISO4 + RSENSE) / RSENSE
555-
float resistorMultiplier = (((float)_dividerResistance) + ((float)_senseResistance)) / ((float)_senseResistance);
555+
float resistorMultiplier = (_dividerResistance + _senseResistance) / _senseResistance;
556556
volts *= resistorMultiplier;
557557
if (_printDebug == true)
558558
{
@@ -631,7 +631,7 @@ ACS37800ERR ACS37800::readInstantaneous(float *vInst, float *iInst, float *pInst
631631
volts /= 1000; //Convert to Volts
632632
//Correct for the voltage divider: (RISO1 + RISO2 + RSENSE) / RSENSE
633633
//Or: (RISO1 + RISO2 + RISO3 + RISO4 + RSENSE) / RSENSE
634-
float resistorMultiplier = (((float)_dividerResistance) + ((float)_senseResistance)) / ((float)_senseResistance);
634+
float resistorMultiplier = (_dividerResistance + _senseResistance) / _senseResistance;
635635
volts *= resistorMultiplier;
636636
if (_printDebug == true)
637637
{
@@ -686,7 +686,7 @@ ACS37800ERR ACS37800::readInstantaneous(float *vInst, float *iInst, float *pInst
686686
}
687687
//Datasheet says: 3.08 LSB/mW for the 30A version and 1.03 LSB/mW for the 90A version
688688
float LSBpermW = 3.08; // LSB per mW
689-
LSBpermW *= 30.0 / ((float)_currentSensingRange); // Correct for sensor version
689+
LSBpermW *= 30.0 / _currentSensingRange; // Correct for sensor version
690690
power /= LSBpermW; //Convert from codes to mW
691691
//Correct for the voltage divider: (RISO1 + RISO2 + RSENSE) / RSENSE
692692
//Or: (RISO1 + RISO2 + RISO3 + RISO4 + RSENSE) / RSENSE
@@ -720,21 +720,21 @@ ACS37800ERR ACS37800::readErrorFlags(ACS37800_REGISTER_2D_t *errorFlags)
720720
}
721721

722722
//Change the value of the sense resistor (Ohms)
723-
void ACS37800::setSenseRes(int newRes)
723+
void ACS37800::setSenseRes(float newRes)
724724
{
725725
_senseResistance = newRes;
726726
}
727727

728728
//Change the value of the voltage divider resistance (Ohms)
729-
void ACS37800::setDividerRes(int newRes)
729+
void ACS37800::setDividerRes(float newRes)
730730
{
731731
_dividerResistance = newRes;
732732
}
733733

734734
//Change the current-sensing range (Amps)
735735
//ACS37800KMACTR-030B3-I2C is a 30.0 Amp part - as used on the SparkFun Qwiic Power Meter
736736
//ACS37800KMACTR-090B3-I2C is a 90.0 Amp part
737-
void ACS37800::setCurrentRange(int newCurrent)
737+
void ACS37800::setCurrentRange(float newCurrent)
738738
{
739739
_currentSensingRange = newCurrent;
740740
}

src/SparkFun_ACS37800_Arduino_Library.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ const uint8_t ACS37800_DEFAULT_I2C_ADDRESS = 0x60;
2929
const uint32_t ACS37800_CUSTOMER_ACCESS_CODE = 0x4F70656E;
3030

3131
//Default sense resistance for voltage measurement (Ohms)
32-
const int ACS37800_DEFAULT_SENSE_RES = 8200;
32+
const float ACS37800_DEFAULT_SENSE_RES = 8200;
3333

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

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

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

417417
//Change the parameters
418-
void setSenseRes(int newRes); // Change the value of _senseResistance (Ohms)
419-
void setDividerRes(int newRes); // Change the value of _dividerResistance (Ohms)
420-
void setCurrentRange(int newCurrent); // Change the value of _currentSensingRange (Amps)
418+
void setSenseRes(float newRes); // Change the value of _senseResistance (Ohms)
419+
void setDividerRes(float newRes); // Change the value of _dividerResistance (Ohms)
420+
void setCurrentRange(float newCurrent); // Change the value of _currentSensingRange (Amps)
421421

422422
private:
423423

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

434434
//The value of the sense resistor for voltage measurement in Ohms
435-
int _senseResistance = ACS37800_DEFAULT_SENSE_RES;
435+
float _senseResistance = ACS37800_DEFAULT_SENSE_RES;
436436

437437
//The value of the divider resistance for voltage measurement in Ohms
438-
int _dividerResistance = ACS37800_DEFAULT_DIVIDER_RES;
438+
float _dividerResistance = ACS37800_DEFAULT_DIVIDER_RES;
439439

440440
//The ACS37800's current sensing range
441-
int _currentSensingRange = ACS37800_DEFAULT_CURRENT_RANGE;
441+
float _currentSensingRange = ACS37800_DEFAULT_CURRENT_RANGE;
442442

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

0 commit comments

Comments
 (0)