Messages in this thread | | | Date | Thu, 27 Jul 2023 17:28:42 +0200 | From | Carsten Spieß <> | Subject | Re: [PATCH 1/2] hwmon: (isl28022) new driver for ISL28022 power monitor |
| |
> On 7/26/23 18:19, Guenter Roeck wrote: > I strongly suspect that the conversions will result in overflows and that they are not always correct. > I'll want to write unit test code before accepting the driver. I changed the conversion for current to *val = ((long)regval * 1250L * (long)data->gain) / (long)data->shunt;
The term (1250 * gain) will be 10000 max, fits to 14 bit. So no risk for 32bit overflow when multiply with 16bit value.
And changed the conversion for power to *val = ((51200000L * ((long)data->gain)) / (long)data->shunt) * (long)regval;
The first term (51200000 * gain / shunt) will be larger than 16bit when (shunt/gain) is less than ~800. So min values for shunt are - 6400 µOhm for 320 mV range - 3200 µOhm for 160 mV range - 1600 µOhm for 80 mV range - 800 µOhm for 40 mV range Can i set this conditionally in the .yaml file?
Regards Carsten [unhandled content-type:application/pgp-signature]
| |