Skip to content

Commit

Permalink
Fix rounding errors in ADC value calculation for 6POS switch.
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Mitchell committed Jun 23, 2023
1 parent 2a3825e commit b9eff4b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions radio/src/hal/adc_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,15 @@ 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
uint8_t vShifted = ANA_FILT(x) >> 4;
s_anaFilt[x] = ANAFILT_MAX;
for (uint32_t i=0; i<calib->count; 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;
}
}
Expand Down

0 comments on commit b9eff4b

Please sign in to comment.