The whole code please. Snippets do not troubleshoot well.
Analog to Digital Converter (ADC) - ESP32 - — ESP-IDF Programming Guide latest documentation (espressif.com)