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.
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
valueproperty onAnalogInobject) that only need to be done once. Insidescommon_hal_analogio_analogin_get_value()there are calls toadc_oneshot_new_unit()andadc_oneshot_config_channel()which the Arduino code only does once or when configuration options change.circuitpython/ports/espressif/common-hal/analogio/AnalogIn.c
Lines 82 to 89 in 1727222
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
AnalogInis instantiated.