ESP32 ADC Raw to Voltage Conversion problem #72983
Labels
area: ADC
Analog-to-Digital Converter (ADC)
bug
The issue is a bug, or the PR is fixing a bug
platform: ESP32
Espressif ESP32
priority: low
Low impact/importance bug
Hello everyone,
I recently encountered a problem while working on a Zephyr project with an ESP32. Specifically, the issue arose when trying to convert raw ADC readings to voltage values. The problem occurs due to an unexpected jump in the scaled ADC values. Here’s the context and details:
Problem Description
In my code, I use the following function to convert raw ADC readings to voltage:
From here zephyr\drivers\adc\adc_esp32.c will be called
modules\hal\espressif\zephyr\esp32\src\esp_adc_cal\esp_adc_cal.c
The problem appears when
chars->bit_width
is set to 3, causing large jumps in the scaled values due to significant bit shifts.Analysis
When
chars->bit_width
is 3, the scaling factor becomes(12 - 3) = 9
bits, leading to significant jumps. For example:adc_reading
is 7 (max for 3 bits), the calculation is7 << 9 = 3584
.Such a large jump can cause instability and unexpected behavior in the voltage readings.
My Code
\src\main.c
\boards\esp32_devkitc_wroom_procpu.overlay
Environment Setup
Best regards,
Stefan
The text was updated successfully, but these errors were encountered: