Skip to content

Commit 91fc4a9

Browse files
committed
stmhal: Fix ADC multiplier from 4096 to 4095; optimise fp operation.
1 parent 99bcaa2 commit 91fc4a9

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

stmhal/adc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ float adc_read_core_vbat(ADC_HandleTypeDef *adcHandle) {
353353
// be 12-bits.
354354
raw_value <<= (12 - adc_get_resolution(adcHandle));
355355

356-
return raw_value * VBAT_DIV / 4096.0f * 3.3f;
356+
// multiplier is 3.3/4095
357+
return raw_value * VBAT_DIV * 0.8058608058608059e-3f;
357358
}
358359

359360
float adc_read_core_vref(ADC_HandleTypeDef *adcHandle) {
@@ -363,7 +364,8 @@ float adc_read_core_vref(ADC_HandleTypeDef *adcHandle) {
363364
// be 12-bits.
364365
raw_value <<= (12 - adc_get_resolution(adcHandle));
365366

366-
return raw_value / 4096.0f * 3.3f;
367+
// multiplier is 3.3/4095
368+
return raw_value * 0.8058608058608059e-3f;
367369
}
368370
#endif
369371

0 commit comments

Comments
 (0)