Skip to content

Commit

Permalink
Merge pull request #2 from ewpa/voltage-fix
Browse files Browse the repository at this point in the history
Change the method of converting the 12 bit sampled ADC value
  • Loading branch information
porrey authored Aug 26, 2019
2 parents cac901e + 3530a81 commit 99644a0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=MAX1704X
version=1.0.0
version=1.0.1
author=Daniel Porrey <daniel.porrey@hotmail.com>
maintainer=Daniel Porrey <daniel.porrey@hotmail.com>
sentence=Arduino library for MAX17043/MAX17044 lithium ion battery fuel gauge.
Expand Down
6 changes: 3 additions & 3 deletions src/MAX17043.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MAX1704X Arduino Library for MAX17043 and MAX17044 Fuel Gauge.
*
* Version 1.0.0
* Version 1.0.1
* Copyright © 2018 Daniel Porrey. All Rights Reserved.
* https://github.com/porrey/max1704x
*
Expand Down Expand Up @@ -30,8 +30,8 @@ extern MAX1704X FuelGauge;

// ***
// *** The MAX17043 is a one-cell device with a
// *** a voltage measurement range of 0 to 5 V.
// *** a voltage measurement range of 0 to 5 V in 1.25 mV increments.
// ***
MAX1704X FuelGauge = MAX1704X(5);
MAX1704X FuelGauge = MAX1704X(1.25);

#endif
6 changes: 3 additions & 3 deletions src/MAX17044.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MAX1704X Arduino Library for MAX17043 and MAX17044 Fuel Gauge.
*
* Version 1.0.0
* Version 1.0.1
* Copyright © 2018 Daniel Porrey. All Rights Reserved.
* https://github.com/porrey/max1704x
*
Expand Down Expand Up @@ -30,8 +30,8 @@ extern MAX1704X FuelGauge;

// ***
// *** The MAX17044 is a two-cell device with a
// *** a voltage measurement range of 0 to 10 V.
// *** a voltage measurement range of 0 to 10 V in 2.50 mV increments.
// ***
MAX1704X FuelGauge = MAX1704X(10);
MAX1704X FuelGauge = MAX1704X(2.50);

#endif
11 changes: 6 additions & 5 deletions src/MAX1704X.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MAX1704X Arduino Library for MAX17043 and MAX17044 Fuel Gauge.
*
* Version 1.0.0
* Version 1.0.1
* Copyright © 2018 Daniel Porrey. All Rights Reserved.
* https://github.com/porrey/max1704x
*
Expand All @@ -23,9 +23,9 @@
*/
#include "MAX1704X.h"

MAX1704X::MAX1704X(float maxVoltage)
MAX1704X::MAX1704X(float voltageIncrement)
{
this->_maxVoltage = maxVoltage;
this->_voltageIncrement = voltageIncrement;
}

void MAX1704X::begin()
Expand All @@ -44,9 +44,10 @@ uint16_t MAX1704X::adc()
float MAX1704X::voltage()
{
// ***
// *** The MAX1704X is a 12-bit ADC measuring 0 to 5 volts.
// *** The MAX1704X has a 12-bit ADC measuring 0 to 5 or 10 Volts in differing
// *** increments.
// ***
return (float)(this->adc() / 4096.0 * this->_maxVoltage);
return (float)(this->adc() * this->_voltageIncrement);
}

float MAX1704X::percent()
Expand Down
4 changes: 2 additions & 2 deletions src/MAX1704X.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MAX1704X Arduino Library for MAX17043 and MAX17044 Fuel Gauge.
*
* Version 1.0.0
* Version 1.0.1
* Copyright © 2018 Daniel Porrey. All Rights Reserved.
* https://github.com/porrey/max1704x
*
Expand Down Expand Up @@ -65,7 +65,7 @@ class MAX1704X
void setThreshold(uint8_t threshold);

protected:
float _maxVoltage;
float _voltageIncrement;
uint8_t thresholdToConfig(uint8_t threshold);
uint8_t configToThreshold(uint8_t config);
uint16_t readRegister16(uint8_t registerId);
Expand Down

0 comments on commit 99644a0

Please sign in to comment.