Fix ADCInput clocks for multiple inputs (#2755)

When multiple inputs were active, the frequency was being scaled two
times resulting in incorrect sampling speed.  Correct to only scale
the calculation and not the stored value (which is used in `begin`).

Fixes #2754
This commit is contained in:
Earle F. Philhower, III 2025-01-14 15:58:45 -08:00 committed by GitHub
parent 83b8d122d7
commit 0655b7d5b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -77,8 +77,9 @@ bool ADCInput::setPins(pin_size_t pin0, pin_size_t pin1, pin_size_t pin2, pin_si
}
bool ADCInput::setFrequency(int newFreq) {
_freq = newFreq * __builtin_popcount(_pinMask); // Want to sample all channels at given frequency
adc_set_clkdiv(48000000.0f / _freq - 1.0f);
_freq = newFreq;
int scaledFreq = newFreq * __builtin_popcount(_pinMask); // Want to sample all channels at given frequency
adc_set_clkdiv(48000000.0f / scaledFreq - 1.0f);
return true;
}