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 was merged in pull request #2755.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user