esp32s3 ADC filter not working

fallafenflufen
Posts: 2
Joined: Fri Mar 15, 2024 11:30 am

esp32s3 ADC filter not working

Postby fallafenflufen » Fri Mar 15, 2024 11:44 am

Is anyone successfully using the ADC filters on the esp32s3?
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;
}
Last edited by fallafenflufen on Mon Mar 18, 2024 9:50 am, edited 1 time in total.

MicroController
Posts: 1219
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: esp32s3 ADC filter not working

Postby MicroController » Sat Mar 16, 2024 11:26 am

Any errors returned from the IIR functions?

fallafenflufen
Posts: 2
Joined: Fri Mar 15, 2024 11:30 am

Re: esp32s3 ADC filter not working

Postby fallafenflufen » Tue Mar 19, 2024 5:44 pm

While the code does not show any error checking, I checked the relevant IIR functions and all of them would print an error log, if there was an error. There is no error log output.

Who is online

Users browsing this forum: No registered users and 109 guests