Texas Instruments AM335 Series Design Manual page 37

Hide thumbs Also See for AM335 Series:
Table of Contents

Advertisement

www.ti.com
DIY INA I2C Measurement
#!/bin/bash
#INA226 Registers
CONFIG_REG=0x0
SHUNTV_REG=0x1
BUSV_REG=0x2
#EVM Specific
declare
-a INA_ADDRS=(0x41);
declare
-a
SUPPLIES=('VDD_MPU ');
declare
-a RES=(0.001);
#Take shunt voltage measurements #Re-initialize INA226
i2cset -y 1 ${INA_ADDRS[0]} $CONFIG_REG 0x0080 w
i2cset -y 1 ${INA_ADDRS[0]} $CONFIG_REG 0xFF4F w
shuntv=$(i2cget -y 1 ${INA_ADDRS[0]} $SHUNTV_REG w)
let
"temp = shuntv >> 8"
let
"temp2 = shuntv << 8 | $temp"
let
"shuntv = $temp2 & 0xffff"
let
"neg_test = $shuntv & 0x8000"
if
[
"$neg_test"
shuntv=0
fi
shuntv=$(echo
"$shuntv*0.0025"
#Take bus voltage measurements #Re-initialize INA226
i2cset -y 1 ${INA_ADDRS[0]} $CONFIG_REG 0x0080 w
i2cset -y 1 ${INA_ADDRS[0]} $CONFIG_REG 0xFF4F w
busv=$(i2cget -y 1 ${INA_ADDRS[0]} $BUSV_REG w)
let
"temp = $busv >> 8"
let
"temp2 = $busv << 8 | $temp"
let
"busv = $temp2 & 0xffff"
busv=$(echo
"$busv*0.00125"
#Calculate power
current=$(echo
"${shuntv}/${RES[0]}"
power=$(echo
"${current}*${busv}"
#Output to console
printf
"Supply\t\tRes (ohm)\tShunt (mV)\tBus (V)\t\tCurrent (mA)\tPower (mW)\n"
printf
"%s\t%.3f\t\t%f\t%f\t%f\t%f\n" "${SUPPLIES[0]}" "${RES[0]}" "${shuntv}" "${busv}"
"${current}" "${power}"
SPRAC74A – February 2017 – Revised March 2017
Submit Documentation Feedback
-gt 0 ];
then
#handle negative
| bc)
| bc)
|
bc
|
bc
-l)
Copyright © 2017, Texas Instruments Incorporated
-l)
Example Source Code
37
Additional Information

Advertisement

Table of Contents
loading

Table of Contents