I supply a constant voltage to an input pin (GPIO 8 - ADC0) and measure the same standard deviation of the converted ADC values regardless of the filter setting (0/1/2/3/4/off). I am using the continuous mode driver. The conversion values are OK, except the measured fluctuation is always the same.
I expect to see a reduction in standard deviation with filter enabled and with increased filter length.
Here is my configuration code:
Code: Select all
bool startADC()
{
constexpr int BLOCK_SIZE = 256;
constexpr float m_controlFrequency = 100;
constexpr gpio_num_t pin = GPIO_NUM_8;
adc_continuous_handle_cfg_t adc_config = {
.max_store_buf_size = (uint32_t)BLOCK_SIZE * SOC_ADC_DIGI_DATA_BYTES_PER_CONV,
.conv_frame_size = (uint32_t) BLOCK_SIZE * SOC_ADC_DIGI_DATA_BYTES_PER_CONV,
};
ESP_ERROR_CHECK(adc_continuous_new_handle(&adc_config, &m_adcHandle));
int adcSamplingFrequency = m_controlFrequency * BLOCK_SIZE ;
adc_continuous_config_t dig_cfg = {
.sample_freq_hz = (uint32_t) adcSamplingFrequency,
.conv_mode = ADC_CONV_SINGLE_UNIT_1,
.format = ADC_DIGI_OUTPUT_FORMAT_TYPE2,
};
adc_unit_t adcUnit;
adc_channel_t channel;
adc_continuous_io_to_channel(pin, &adcUnit, &channel);
adc_digi_pattern_config_t adc_pattern[1] = {};
dig_cfg.pattern_num = 1;
adc_pattern[0].atten = adc_atten_t::ADC_ATTEN_DB_0;
adc_pattern[0].channel = channel;
adc_pattern[0].unit = adcUnit;
adc_pattern[0].bit_width = SOC_ADC_DIGI_MAX_BITWIDTH;
dig_cfg.adc_pattern = adc_pattern;
ESP_ERROR_CHECK(adc_continuous_config(m_adcHandle, &dig_cfg));
adc_continuous_iir_filter_config_t filterCfg = {
.unit = adcUnit,
.channel = channel,
.coeff = adc_digi_iir_filter_coeff_t::ADC_DIGI_IIR_FILTER_COEFF_64 // or other values (0-4 integer values)
};
adc_new_continuous_iir_filter(m_adcHandle, &filterCfg, &m_adcFilterHandle);
adc_continuous_iir_filter_enable(m_adcFilterHandle);
// adc_continuous_iir_filter_disable(m_adcFilterHandle); // for comparison test
ESP_ERROR_CHECK(adc_continuous_start(m_adcHandle));
return true;
}