analogReadMilliVolts() does not handle changes in resolution made by analogReadResolution() #8999
Closed
1 task done
Labels
Area: Peripherals API
Relates to peripheral's APIs.
Resolution: Awaiting response
Waiting for response of author
Milestone
Board
ESP32-S2
Device Description
Tested with Unexpected Maker FeatherS2 & senseBox MCU-S2 ESP32-S2
Hardware Configuration
Any analog sensor (e.g. Truebner SMT50 or SparkFun SEN-13322) is connected.
Version
v2.0.14
IDE Name
ArduinoIDE
Operating System
macOS 14.1.2
Flash frequency
80MHz
PSRAM enabled
yes
Upload speed
921600
Description
Expected behaviour:
When using ESP32-S2 and
analogReadMilliVolts(pin)
I should always get the measured voltage in milliVolts.Weird behaviour: When changing the default 13 bit resolution of the ADC1 to e.g. 12bit using
analogReadResolution(12);
the outputs of analogReadMilliVolts(pin) are incorrect (half in size in case of 12bit).Tried to track it down and found this to be happening (in esp32-hal-adc.c):
The
__analogRead()
function uses the 12 bit resolution (as expected because ofanalogReadResolution(12)
). But__analogReadMilliVolts()
internally also uses__analogRead()
which returns a 12bit ADC value. But during transformation inesp_adc_cal_raw_to_voltage((uint32_t)adc_reading, &chars)
the adc_reading is always expected to be the raw 13bit value in case of the ESP32-S2. There it assumes the 12 bit value to be 13 bit and the resulting value in milliVolts half of the correct value.I assume this also happens with other chips than the S2, but haven't tested it so far.
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: