Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overflow in currentSensorToCentiamps() #3131

merged 1 commit into from Apr 27, 2018


None yet
2 participants
Copy link

commented Apr 27, 2018

Fixes #3124

@@ -108,7 +108,7 @@ uint16_t batteryAdcToVoltage(uint16_t src)

int32_t currentSensorToCentiamps(uint16_t src)
int32_t microvolts = ((uint32_t)src * ADCVREF * 1000) / 0xFFF - (int32_t)batteryConfig()->current.offset * 1000;
int32_t microvolts = ((uint32_t)src * ADCVREF * 100) / 0xFFF * 10 - (int32_t)batteryConfig()->current.offset * 1000;

This comment has been minimized.

Copy link

digitalentity Apr 27, 2018


Good catch! I didn't realize that after a certain point multiplication result won't fit into 32 bits any more. Since ADCVREF is 3300 we are not loosing any percision with this change.

@digitalentity digitalentity merged commit 969e8e2 into iNavFlight:development Apr 27, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed

@digitalentity digitalentity added this to the 2.0 milestone Apr 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.