-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
Description
In the src/main/sensors/battery.c following code is available
int32_t currentSensorToCentiamps(uint16_t src)
{
int32_t microvolts = ((uint32_t)src * ADCVREF * 1000) / 0xFFF - (int32_t)batteryConfig()->current.offset * 1000;
return microvolts / batteryConfig()->current.scale; // current in 0.01A steps
}
range of src variable values - 0x0 to 0xFFF
ADCVREF eq 3300
let us assume src = 4095
calculation
0x00000FFF * 3300*1000 = 0x3 2577 A560 <- Іnteger overflow here
On my OMNIBUS F4 PRO maximum displayed current is 9,63 Amp , if more -1
maybe this is the best option
int32_t microvolts = ((uint32_t)src * 806UL) - (int32_t)batteryConfig()->current.offset * 1000;
then there will be no overflow, but there will be less precision