Skip to content

Commit 893857b

Browse files
ball-haydennashif
authored andcommitted
max17055: Fix current conversion from MAX17055 unit to milliamps
`SENSOR_CHAN_GAUGE_AVG_CURRENT` is currently treated as a capacity by the MAX17055 driver, however the unit conversion is different for current and must be calculated separately. Add a separate method to convert a current reading to milliamps from 1.5625 uV/R_SENSE units, instead of the 5uVH/R_SENSE conversion that was previously used. Tested by comparing value read and converted from MAX17055 with value from an external power profiling kit. Signed-off-by: Hayden Ball <[email protected]>
1 parent ea2ab69 commit 893857b

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

drivers/sensor/max17055/max17055.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ static int max17055_reg_read(struct max17055_data *priv, int reg_addr,
4141
return 0;
4242
}
4343

44+
/**
45+
* @brief Convert current in MAX17055 units to milliamps
46+
*
47+
* @param rsense_mohms Value of Rsense in milliohms
48+
* @param val Value to convert (taken from a MAX17055 register)
49+
* @return corresponding value in milliamps
50+
*/
51+
static int current_to_ma(unsigned int rsense_mohms, int16_t val)
52+
{
53+
return (val * 1.5625) / rsense_mohms;
54+
}
55+
4456
/**
4557
* @brief Convert capacity in MAX17055 units to milliamps
4658
*
@@ -91,11 +103,11 @@ static int max17055_channel_get(const struct device *dev,
91103
valp->val2 = tmp % 1000000;
92104
break;
93105
case SENSOR_CHAN_GAUGE_AVG_CURRENT: {
94-
int cap_ma;
106+
int current_ma;
95107

96-
cap_ma = capacity_to_ma(config->rsense_mohms,
97-
priv->avg_current);
98-
set_millis(valp, cap_ma);
108+
current_ma = current_to_ma(config->rsense_mohms,
109+
priv->avg_current);
110+
set_millis(valp, current_ma);
99111
break;
100112
}
101113
case SENSOR_CHAN_GAUGE_STATE_OF_CHARGE:

0 commit comments

Comments
 (0)