INA228 power measurement

Captain Haddock

Senior Member
Has anyone used a Texas Instruments INA228 for voltage and current measurement? Is it possible with picaxe?
Datasheet attached.
I'd quite like to be able to measure power at several different points using a circuit and display already in place and i2c will be the easiest way to go, any other device suggestions welcome.
Thanks in advance for anything useful.
 
I'd quite like to be able to measure power at several different points using a circuit and display already in place and i2c will be the easiest way to go, any other device suggestions welcome.
I haven't used the INA228, but have used INA226 modules for monitoring DC voltage and current from 5V to 24V. I've used Annex RDS Basic and ESP32-C3Supermini or ESP32-S3Zero modules. Examples here (and following).

I even made a PCB with sockets for 6 INA226 modules, shown here. I can post the gerbers from that PCB if anyone has an interest.

With integer-only math, I don't think the PICAXE would be very suitable, even if it could be made to work with contortions.
 
... With integer-only math, I don't think the PICAXE would be very suitable, even if it could be made to work with contortions.
It won't be that difficult !.

Section 8.1.2 of the datasheet explains that the calibration needs to be set before most registers can be used, and 8.2.2.3 gives an example. It should be possible to calculate this calibration setting to give easy 'powers of 2' results.

Once the calibration is set, the results are 20 bit, in a 3 byte ( ie. 24 bit ) field. If you use just the first 2 bytes then you will have a 16 bit result, which is easily good enough for most applications, ( unless you want laboratory standards performance, in which case the shunt is going to cost $$$$ alone. )

The current result is 2's complement, so a simple conversion will be needed to handle reverse current if needed.

Once this is working, there is no need for any calculations, the chip already does most stuff you would want. It's a cool device, I wish I needed one !

Cheers,

Buzby
 
Sounds great Buzby but way beyond my capability unfortunately, I just dabble around the fringe of this stuff and have an MS assisted Swiss cheese brain, reading datasheets is much harder than it used to be for me.
Thanks for the input all the same, I froze when I read 24bits.
 
I think this device may also come in a 16 bit version. Follow the.link in a previous post. I've not used any of this line of chips.
 
I haven’t used these particular devices, only similar energy metering devices from Analog Devices.
As Buzby mentioned, the IC does most of the heavy lifting in real time, including the conversion to real power taking into consideration volts, amps and power factor.
The ADI devices also have a reverse power flag.
 
It won't be that difficult !.

Section 8.1.2 of the datasheet explains that the calibration needs to be set before most registers can be used, and 8.2.2.3 gives an example. It should be possible to calculate this calibration setting to give easy 'powers of 2' results.

Once the calibration is set, the results are 20 bit, in a 3 byte ( ie. 24 bit ) field. If you use just the first 2 bytes then you will have a 16 bit result, which is easily good enough for most applications, ( unless you want laboratory standards performance, in which case the shunt is going to cost $$$$ alone. )

The current result is 2's complement, so a simple conversion will be needed to handle reverse current if needed.

Once this is working, there is no need for any calculations, the chip already does most stuff you would want. It's a cool device, I wish I needed one !

Cheers,

Buzby
If you fancy a play I have one here on a breakout board that I'm happy to post to you FOC as I'm never gonna get my fuzzy brain around setting the calibration let alone anything else, message me with an address if you want to have a go.
 
Thanks, that's a kind offer. I'll happily try one out.

Problem is, I'm on moderation, so can't send new messages. However, I can reply to messages, so please send me one.

Cheers,

Buzby
 
I've got started reading the INA228 module.

First task was to find the chip address. The screenprint says default address is '69', which I assumed was a 7 bit address $45.
Multipled by two to get 8 bits, this gives $8A.

Then read register $3E and $3F which have fixed values for manufacturer and device ID. This proves I'm talking to the chip properly.

Next, register $06, the die temperature. Now I'm getting into the maths for conversions.

Too late tonight, more to follow tomorrow.
 
Not much done today, just tidied up the results a bit.

I now need a way to put a few Amps through the device, without frying myself.
This is where access to the chip pins directly would make the job easier.

If I could get at the shunt pins and the voltage pins seperately, I could then use a clever trick to run the device to full scale, without dissipating any power at all !.

By feeding the shunt pins with the voltage they would 'see' at full current, and seperately feeding the voltage pins with max volts, the device will respond as if it is passing, say, 200A at 80v, an apparent power of 16Kw !.

As it is I'm going to have to dissipate real power, and I don't think I'll reach anywhere like 1Kw, never mind 16Kw.

INA228_results_1.JPG
 
Hi,

The current-sensing resistor is external to the Texas chip and I'd be surprised if it (or at least a very low value) were included even on a Breakout Board. Surely you only need to test/calibrate the "high gain" current-shunt configuration, with a few volts on the "Bus"? Or is this "Breakout Board" actually a more fully-functional system?

IMHO the "USP" (Unusual Selling Point - certainly not Unique) of the INA228 is its Differential Current Monitoring (and perhaps its overvoltage/"alert" hardware, if needed), because it's important to isolate a (calibrated) shunt resistance from its lead wires and any PCB tracks, etc.. Its bi-directional (current) measurement capability might be of benefit, but requires familiarity with the Two's Complement number system (not that this is very difficult, even with a PICaxe).

Apart from the High Gain Differential current measurement, the chip doesn't really seem to offer very much benefit. It's not doing a.c. (sinewave) power measurements and all the "mathematics" uses the binary number system (needing conversion to "decimals" before use), that can be done with a few bytes/words in a PICaxe (albeit rather more slowly). The PICaxe maths might even be a little easier without those annoying "*16"s or "/ 16"s necessitated by the 20-bit to 16- or 24-bit data-field conversions; PICaxe has native 16 * 16 bits (= 32-bits) multiplication using the * and ** operators. The "temperature compensation" feature might be useful when using a "copper wire" current-shunt resistor (0.393% per degree C), but even the PICaxe can monitor its own chip temperature to within a few degrees (after a simple calibration stage) with no additional hardware.

Cheers, Alan.
 
I got some success !

First challenge, finding the resistance of the shunt. The MATEKSYS website is not very useful, ( https://www.mateksys.com/?portfolio=i2c-ina-bm ), but I think it says the shunt is 0.0002 ohm.

Plugging that into a complicated Excel formula gives a result of $19.

I might not have the Excel formula right, because trying $19 in SHUNT_CAL made the result about 8000mA, when my PSU was sending 5A.
So by iteratively adjusting SHUNT_CAL until I got sensible results, I ended up with a value of $A0. This gives a current reading close to what is actually flowing.

INA228_results_2.JPG
In the table above the 6160mA value was when about 6.1A was showing on my PSU, and it followed correctly as I changed PSU current.

Now that I can read current, I should really check the Excel formula is correct, but I'm not really bothered. If I needed the device for a purpose then I would finalise the calibration and write code to read POWER etc.

However, I'm not sure this device on it's own can measure more than just current. There is no seperate battery -ve pin, so it might get it from a common ground. Again, I'm not going to find out, tracing circuits or trawling forums.

It's a really clever chip though. If I had a need this would be just the job.

@Captain Haddock, do you want the board back ?.
 
The PICaxe maths might even be a little easier without those annoying "*16"s or "/ 16"s necessitated by the 20-bit to 16- or 24-bit data-field conversions;
It's even easier than that, there is no conversion needed if you just use 16 bits.

Chip holds a 20 bit value in 3 bytes, with 4 unused bits below the LSB.
hi2cin regnum,(b3,b2,b1) ' Read 3 bytes from chip. Note the order of reading.
MyResult = w1 ' Use 2 MSB bytes for result. w1 = b3 as MSB, b2 as LSB. Ignore the last byte, b1, with the last 4 bits, it's too small to matter.

This gets the top 16 bits as the result in w1, in sensible units, as long as the calibration is correct.

If the result is a Two's Complement value, just test for > 32767.

e.g. if w1 > 32767 then ' Test for -ve
w1 = 0 - w1 ' Convert from -ve
sertxd("-",#w1)
else ' Value is +ve
sertxd("+",#w1)
endif

( In effect, the result is only 15 bit resolution with 1 bit sign. However, even 15 bit resolution is good enough for the vast majority of applications. If you need the full 20 bit resolution then you wouldn't use a PICAXE, or a $10 breakout board and shunt. )

There are some registers that are bigger, with 24 or 40 bit values, such as POWER, ENERGY, CHARGE. On these you may need to see more resolution at low values, but there are tricks to manage these without using wide-bit calculations.

Cheers,

Buzby
 
There's no PICAXE code needed for calibration. The chip just needs SHUNT_CAL loading with the result from a rather messy calculation. I did the calc in Excel, but I'm not sure I got it right !.

Once the correct value is in SHUNT_CAL, all the other values that the chip calculates internally are automatically in suitable units.
 
Back
Top