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
merged 1 commit into from
Apr 27, 2018

Conversation

shellixyz
Copy link
Collaborator

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants