Skip to content

Commit

Permalink
add INA226_MINIMAL_SHUNT (#27)
Browse files Browse the repository at this point in the history
- add constant INA226_MINIMAL_SHUNT
  • Loading branch information
RobTillaart authored May 24, 2023
1 parent 460cbd7 commit 1f97226
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 10 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.4.2] - 2023-04-03
## [0.4.3] - 2023-05-07
- add constant INA226_MINIMAL_SHUNT


## [0.4.2] - 2023-04-03
- added **getBusVoltage_uV()** for completeness
- INA226_test_I2C.ino to prep performance tests
- fix changelog.md
Expand All @@ -17,7 +20,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- update license 2023
- minor edits


## [0.4.1] - 2022-11-12
- Add RP2040 support to build-CI.
- Add CHANGELOG.md, replaces release_notes to be consistent over my libraries.
Expand Down
8 changes: 4 additions & 4 deletions INA226.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// FILE: INA226.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.4.2
// VERSION: 0.4.3
// DATE: 2021-05-18
// PURPOSE: Arduino library for INA226 power sensor
// URL: https://github.com/RobTillaart/INA226
Expand Down Expand Up @@ -195,9 +195,9 @@ int INA226::setMaxCurrentShunt(float maxCurrent, float shunt, bool normalize)
// fix #16 - datasheet 6.5 Electrical Characteristics
// rounded value to 80 mV
float shuntVoltage = abs(maxCurrent * shunt);
if (shuntVoltage > 0.080) return INA226_ERR_SHUNTVOLTAGE_HIGH;
if (maxCurrent < 0.001) return INA226_ERR_MAXCURRENT_LOW;
if (shunt < 0.001) return INA226_ERR_SHUNT_LOW;
if (shuntVoltage > 0.080) return INA226_ERR_SHUNTVOLTAGE_HIGH;
if (maxCurrent < 0.001) return INA226_ERR_MAXCURRENT_LOW;
if (shunt < INA226_MINIMAL_SHUNT) return INA226_ERR_SHUNT_LOW;

_current_LSB = maxCurrent * 3.0517578125e-5; // maxCurrent / 32768;

Expand Down
7 changes: 5 additions & 2 deletions INA226.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// FILE: INA226.h
// AUTHOR: Rob Tillaart
// VERSION: 0.4.2
// VERSION: 0.4.3
// DATE: 2021-05-18
// PURPOSE: Arduino library for INA226 power sensor
// URL: https://github.com/RobTillaart/INA226
Expand All @@ -14,7 +14,7 @@
#include "Wire.h"


#define INA226_LIB_VERSION (F("0.4.2"))
#define INA226_LIB_VERSION (F("0.4.3"))


// set by setAlertRegister
Expand All @@ -39,6 +39,9 @@
#define INA226_ERR_SHUNT_LOW 0x8002


// See issue #26
#define INA226_MINIMAL_SHUNT (0.001)


class INA226
{
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,26 @@ The alert line falls when alert is reached.
- **uint16_t getRegister(uint8_t reg)** fetch registers directly, for debugging only.


## Adjusting the range of the INA226

**use at own risk**
In issue #26 a hack is made to scale the INA226 to 300A by using a very small shunt.
The library has a minimal limit for the shunt of 0.001 ohm.
This limit can be overruled to support other ranges like the one discussed in #26.
Overruling can be done by patching the following value in the INA226.h file.

```cpp
#define INA226_MINIMAL_SHUNT (0.001)
```

Be aware that
- **you should NOT do this unless you understand the implications**.
- you do this at your own risk.
- the resistance of wires used affect measurements with very small shunts.
- solder might change the resistance too.
- you do this at your own risk.


## Operational

See examples..
Expand Down
3 changes: 3 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,6 @@ INA226_ERR_SHUNTVOLTAGE_HIGH LITERAL1
INA226_ERR_MAXCURRENT_LOW LITERAL1
INA226_ERR_SHUNT_LOW LITERAL1

INA226_MINIMAL_SHUNT LITERAL1


2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/INA226.git"
},
"version": "0.4.2",
"version": "0.4.3",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=INA226
version=0.4.2
version=0.4.3
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for INA226 power sensor
Expand Down
2 changes: 2 additions & 0 deletions test/unit_test_001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ unittest(test_constants)
assertEqual(0x8000, INA226_ERR_SHUNTVOLTAGE_HIGH);
assertEqual(0x8001, INA226_ERR_MAXCURRENT_LOW);
assertEqual(0x8002, INA226_ERR_SHUNT_LOW);

assertEqualFloat(0.001, INA226_MINIMAL_SHUNT, 0.0001);
}


Expand Down

0 comments on commit 1f97226

Please sign in to comment.