Skip to content

More efficient ADC sample reading in espressif port #11467

Description

@kevinjwalters

I've been looking at some ESP32-S2 ADC phenomena recently and ended up comparing CircuitPython and Arduino code.

The CircuitPython code looks like it's initialising quite a few things per read (use of the value property on AnalogIn object) that only need to be done once. Insides common_hal_analogio_analogin_get_value() there are calls to adc_oneshot_new_unit() and adc_oneshot_config_channel() which the Arduino code only does once or when configuration options change.

CHECK_ESP_RESULT(adc_oneshot_new_unit(&adc_config, &adc_handle));
adc_oneshot_chan_cfg_t channel_config = {
.atten = ATTENUATION,
.bitwidth = DATA_WIDTH
};
adc_channel_t channel = (adc_channel_t)self->pin->adc_channel;
adc_oneshot_config_channel(adc_handle, channel, &channel_config);

I note the return code from adc_oneshot_config_channel() is checked in the Arduino code.

Perhaps the calibration initialisation could also be done just once when AnalogIn is instantiated.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions