From b9eff4b2ec50db16740e9647af633f0e32414523 Mon Sep 17 00:00:00 2001 From: Phil Mitchell Date: Fri, 23 Jun 2023 13:34:07 +1000 Subject: [PATCH] Fix rounding errors in ADC value calculation for 6POS switch. --- radio/src/hal/adc_driver.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/radio/src/hal/adc_driver.cpp b/radio/src/hal/adc_driver.cpp index 33bb58a0e05..d9c93cbaa5d 100644 --- a/radio/src/hal/adc_driver.cpp +++ b/radio/src/hal/adc_driver.cpp @@ -346,7 +346,7 @@ void getADC() } #endif - #define ANAFILT_MAX (2 * RESX * JITTER_ALPHA * ANALOG_MULTIPLIER - 1) + #define ANAFILT_MAX (2 * RESX * JITTER_ALPHA * ANALOG_MULTIPLIER) StepsCalibData * calib = (StepsCalibData *) &g_eeGeneral.calib[x]; if (IS_POT_MULTIPOS(x) && IS_MULTIPOS_CALIBRATED(calib)) { // TODO: consider adding another low pass filter to eliminate multipos switching glitches @@ -354,7 +354,7 @@ void getADC() s_anaFilt[x] = ANAFILT_MAX; for (uint32_t i=0; icount; i++) { if (vShifted < calib->steps[i]) { - s_anaFilt[x] = (i * ANAFILT_MAX) / calib->count; + s_anaFilt[x] = (i * (ANAFILT_MAX + JITTER_ALPHA * ANALOG_MULTIPLIER)) / calib->count; break; } }