diff options
author | Damien George <damien.p.george@gmail.com> | 2015-02-11 00:25:22 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-02-11 00:25:22 +0000 |
commit | 91fc4a9ce13311bc5c3bdcd5ddaf75795f8a46b5 (patch) | |
tree | dc38de24d1625f9693187ad08f0d1622b83466e7 | |
parent | 99bcaa2fb6b45a378278a956e7f830cee170804e (diff) | |
download | micropython-91fc4a9ce13311bc5c3bdcd5ddaf75795f8a46b5.tar.gz micropython-91fc4a9ce13311bc5c3bdcd5ddaf75795f8a46b5.zip |
stmhal: Fix ADC multiplier from 4096 to 4095; optimise fp operation.
-rw-r--r-- | stmhal/adc.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/stmhal/adc.c b/stmhal/adc.c index 4e0ec46a9a..a59543710b 100644 --- a/stmhal/adc.c +++ b/stmhal/adc.c @@ -353,7 +353,8 @@ float adc_read_core_vbat(ADC_HandleTypeDef *adcHandle) { // be 12-bits. raw_value <<= (12 - adc_get_resolution(adcHandle)); - return raw_value * VBAT_DIV / 4096.0f * 3.3f; + // multiplier is 3.3/4095 + return raw_value * VBAT_DIV * 0.8058608058608059e-3f; } float adc_read_core_vref(ADC_HandleTypeDef *adcHandle) { @@ -363,7 +364,8 @@ float adc_read_core_vref(ADC_HandleTypeDef *adcHandle) { // be 12-bits. raw_value <<= (12 - adc_get_resolution(adcHandle)); - return raw_value / 4096.0f * 3.3f; + // multiplier is 3.3/4095 + return raw_value * 0.8058608058608059e-3f; } #endif |