Skip to content

Commit 4a7508b

Browse files
committed
0.1.1 INA238
1 parent 63d9876 commit 4a7508b

7 files changed

Lines changed: 78 additions & 42 deletions

File tree

libraries/INA238/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.1.1] - 2025-12-27
10+
- Fix #2, getBusVoltage
11+
- add performance figures
12+
- minor edits
13+
914
## [0.1.0] - 2025-12-27
1015
- initial version (publish)
1116

libraries/INA238/INA238.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// FILE: INA238.cpp
22
// AUTHOR: Rob Tillaart
3-
// VERSION: 0.1.0
3+
// VERSION: 0.1.1
44
// DATE: 2025-06-11
55
// PURPOSE: Arduino library for the INA238, I2C, 16 bit, voltage, current and power sensor.
66
// URL: https://github.com/RobTillaart/INA238
@@ -95,7 +95,7 @@ float INA238::getBusVoltage()
9595
{
9696
// always positive, remove reserved bits.
9797
int16_t value = _readRegister(INA238_BUS_VOLTAGE, 2);
98-
float bus_LSB = 3.125; // 3.125 mV
98+
float bus_LSB = 3.125e-3; // 3.125 mV
9999
float voltage = value * bus_LSB;
100100
return voltage;
101101
}
@@ -282,8 +282,8 @@ uint8_t INA238::getAverage()
282282
int INA238::setMaxCurrentShunt(float maxCurrent, float shunt)
283283
{
284284
// Shunt can be really small
285-
if (shunt < 0.0001) return -2; // TODO error code
286-
if (maxCurrent < 0.0) return -3; // TODO error code
285+
if (shunt < 0.0001) return -2;
286+
if (maxCurrent < 0.0) return -3;
287287
_maxCurrent = maxCurrent;
288288
_shunt = shunt;
289289
_current_LSB = _maxCurrent * 3.0517578125e-5; // pow(2, -15);
@@ -368,13 +368,13 @@ uint16_t INA238::getDiagnoseAlertBit(uint8_t bit)
368368
// THRESHOLD AND LIMIT REGISTERS 12-17
369369
// section 7.3.6, 7.6.1.10
370370
//
371-
// TODO (sync INA228)
371+
// (sync INA228 whenever fixed)
372372
// - API
373-
// - return bool for setters
373+
// - return bool for setters?
374374
// - float voltage interface instead of uint16_t? breaking!
375375
void INA238::setShuntOvervoltageTH(uint16_t threshold)
376376
{
377-
// TODO ADCRANGE DEPENDENT
377+
// ADCRANGE DEPENDENT
378378
// Conversion Factor: 5 μV/LSB when ADCRANGE = 0
379379
// 1.25 μV/LSB when ADCRANGE = 1.
380380
// float LSB = 5.0e-6;
@@ -384,23 +384,23 @@ void INA238::setShuntOvervoltageTH(uint16_t threshold)
384384

385385
uint16_t INA238::getShuntOvervoltageTH()
386386
{
387-
// TODO ADCRANGE DEPENDENT
387+
// ADCRANGE DEPENDENT
388388
// float LSB = 5.0e-6;
389389
// if (_ADCRange == 1) LSB = 1.25e-6;
390390
return _readRegister(INA238_SOVL, 2);
391391
}
392392

393393
void INA238::setShuntUndervoltageTH(uint16_t threshold)
394394
{
395-
// TODO ADCRANGE DEPENDENT
395+
// ADCRANGE DEPENDENT
396396
// float LSB = 5.0e-6;
397397
// if (_ADCRange == 1) LSB = 1.25e-6;
398398
_writeRegister(INA238_SUVL, threshold);
399399
}
400400

401401
uint16_t INA238::getShuntUndervoltageTH()
402402
{
403-
// TODO ADCRANGE DEPENDENT
403+
// ADCRANGE DEPENDENT
404404
// float LSB = 5.0e-6;
405405
// if (_ADCRange == 1) LSB = 1.25e-6;
406406
return _readRegister(INA238_SUVL, 2);

libraries/INA238/INA238.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22
// FILE: INA238.h
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.0
4+
// VERSION: 0.1.1
55
// DATE: 2025-06-11
66
// PURPOSE: Arduino library for the INA238, I2C, 16 bit, voltage, current and power sensor.
77
// URL: https://github.com/RobTillaart/INA238
@@ -14,7 +14,7 @@
1414
#include "Wire.h"
1515

1616

17-
#define INA238_LIB_VERSION (F("0.1.0"))
17+
#define INA238_LIB_VERSION (F("0.1.1"))
1818

1919

2020
// for setMode() and getMode()
@@ -66,7 +66,6 @@ enum INA238_timing_enum {
6666

6767

6868
// for diagnose/alert() bit fields.
69-
// TODO bit masks?
7069
enum INA238_diag_enum {
7170
INA238_DIAG_MEMORY_STATUS = 0,
7271
INA238_DIAG_CONVERT_COMPLETE = 1,
@@ -190,8 +189,6 @@ class INA238
190189
// read datasheet for details, section 7.3.6, page 16++
191190
// section 7.6.1.10, page 26++
192191
//
193-
// TODO - design and implement better API?
194-
//
195192
void setShuntOvervoltageTH(uint16_t threshold);
196193
uint16_t getShuntOvervoltageTH();
197194
void setShuntUndervoltageTH(uint16_t threshold);

libraries/INA238/README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ TODO Test
113113
114114
```
115115

116-
TODO Test
116+
_Tested - see #2_
117117

118118

119119
### Special characters
@@ -169,26 +169,23 @@ Note this might differ per breakout board.
169169

170170
### Performance
171171

172-
TODO run tests and fill performance figures.
173-
174-
Run **INA238_performance.ino** sketch to get a first indication.
175-
Numbers below are based upon tests with TODO.
172+
Run **INA238_performance.ino** sketch to get a first indication of your
173+
board used.
174+
Numbers below are based upon tests with RP2040 (see issue #2).
176175

177176
Time in micros, I2C speed in kHz.
178177

179178
| I2C | function | time | notes |
180179
|:-----:|:------------------|:------:|:-------:|
181-
| 100 | getBusVoltage | | 100%
182-
| 100 | getShuntVoltage | |
183-
| 100 | getCurrent | |
184-
| 100 | getPower | |
185-
| 100 | getTemperature | |
186-
| 100 | getEnergy | |
187-
| 100 | getCharge | |
188-
| | | | other functions similar gain.
189-
| 200 | getBusVoltage | |
190-
| 400 | getBusVoltage | |
191-
| 800 | getBusVoltage | |
180+
| 100 | getBusVoltage | 620 | 100%
181+
| 100 | getShuntVoltage | 590 | 95%
182+
| 100 | getCurrent | 583 | 94%
183+
| 100 | getPower | 728 | 117%
184+
| 100 | getTemperature | 601 | 97%
185+
| | | | other functions similar gain.
186+
| 200 | getBusVoltage | 350 | 56%
187+
| 400 | getBusVoltage | 237 | 38%
188+
| 800 | getBusVoltage | 167 | 27%
192189

193190

194191
Most non core functions are as fast as **getTemperature()**
@@ -279,8 +276,6 @@ Read datasheet for details, section 7.6.1.2, page 21++
279276
- **void setADCRange(bool flag)** flag = false => ~163.84 mV, true => ~40.96 mV
280277
- **bool getADCRange()** return set value.
281278

282-
TODO: examples to show the effect of the ADC configuration.
283-
284279

285280
### ADC mode
286281

@@ -386,7 +381,7 @@ Read datasheet for details, section 7.3.6, page 16++
386381

387382
Note: the implementation of this part is rather minimalistic and
388383
might be changed / extended in the future.
389-
Idem INA228 library.
384+
Idem see my INA228 library.
390385

391386
#### Shunt
392387

@@ -428,17 +423,22 @@ Idem INA228 library.
428423
- update documentation.
429424
- test and verify with hardware
430425
- keep sync INA228 where possible.
426+
- fix TODO's in code + readme.md
431427

432428
#### Should
433429

434-
- TODO's in code and docs.
435-
- add error handling.
436430
- how to detect nothing connected?
437431
- vshunt > maxVShunt (new variable)
438432
- current > maxCurrent
433+
- examples
434+
- example to show the effect of the ADC configuration.
435+
- improve error handling (INA228)
436+
- constants/enum
439437

440438
#### Could
441439

440+
- improve API thresholds and limits (INA228)
441+
- improve API use bitmasks for diagnostics (INA228)
442442
- write examples, (please share yours).
443443
- improve unit tests
444444
- clean up magic numbers in the code?
Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,41 @@
1-
BOARD: Arduino UNO
2-
IDE: 1.8.19
3-
1+
BOARD: RP2040
2+
IDE: MSDEV
3+
See issue #2
44

55
INA238_performance\INA238_performance.ino
66

7-
PLACEHOLDER (TODO HW TEST)
7+
INA238_LIB_VERSION: 0.1.0
8+
9+
========================================================
10+
Speed: 100000
11+
getBusVoltage: 620
12+
getShuntVoltage: 590
13+
getCurrent: 583
14+
getPower: 728
15+
getTemperature: 601
16+
17+
========================================================
18+
Speed: 200000
19+
getBusVoltage: 350
20+
getShuntVoltage: 334
21+
getCurrent: 344
22+
getPower: 396
23+
getTemperature: 336
24+
25+
========================================================
26+
Speed: 400000
27+
getBusVoltage: 237
28+
getShuntVoltage: 202
29+
getCurrent: 208
30+
getPower: 252
31+
getTemperature: 213
32+
33+
========================================================
34+
Speed: 800000
35+
getBusVoltage: 167
36+
getShuntVoltage: 152
37+
getCurrent: 164
38+
getPower: 187
39+
getTemperature: 161
40+
41+
Done

libraries/INA238/library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/INA238.git"
1717
},
18-
"version": "0.1.0",
18+
"version": "0.1.1",
1919
"license": "MIT",
2020
"frameworks": "*",
2121
"platforms": "*",

libraries/INA238/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=INA238
2-
version=0.1.0
2+
version=0.1.1
33
author=Rob Tillaart <rob.tillaart@gmail.com>
44
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
55
sentence=Arduino library for the INA238, I2C, 16 bit, voltage, current and power sensor.

0 commit comments

Comments
 (0)