Skip to content

Commit 0655b7d

Browse files
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
1 parent 83b8d12 commit 0655b7d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

libraries/ADCInput/src/ADCInput.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ bool ADCInput::setPins(pin_size_t pin0, pin_size_t pin1, pin_size_t pin2, pin_si
7777
}
7878

7979
bool ADCInput::setFrequency(int newFreq) {
80-
_freq = newFreq * __builtin_popcount(_pinMask); // Want to sample all channels at given frequency
81-
adc_set_clkdiv(48000000.0f / _freq - 1.0f);
80+
_freq = newFreq;
81+
int scaledFreq = newFreq * __builtin_popcount(_pinMask); // Want to sample all channels at given frequency
82+
adc_set_clkdiv(48000000.0f / scaledFreq - 1.0f);
8283
return true;
8384
}
8485

0 commit comments

Comments
 (0)