Page 1 of 1

ADC with Deep Sleep

Posted: Wed Feb 05, 2020 4:04 pm
by apurva
Hello. I am trying to implement ADC read with the ESP32 periodically going into deep sleep. Will esp_adc_cal_get_voltage() give the correct voltage reading for subsequent function calls if I just initialize the ADC once before the first deep sleep cycle and then just toggle it using adc_power_on() and adc_power_off()?

Initialization that runs just once before the first sleep consists of:

Code: Select all

adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(ADC1_GPIO32_CHANNEL, ADC_ATTEN_DB_11);
adc_chars = calloc(1, sizeof(esp_adc_cal_characteristics_t));
esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, VREF, adc_chars);
adc_power_off();
Part that runs every few sleep cycles:

Code: Select all

adc_power_on();
esp_adc_cal_get_voltage(ADC1_GPIO32_CHANNEL, adc_chars, &V_raw);
adc_power_off();

Re: ADC with Deep Sleep

Posted: Wed Feb 05, 2020 6:26 pm
by chegewara
If you are reading ADC in normal running app (not deep sleep), then you have to call this function each time before you start deep sleep:

Code: Select all

adc1_ulp_enable();

Re: ADC with Deep Sleep

Posted: Wed Feb 05, 2020 7:14 pm
by apurva
Isn't that function used if I want to use ADC in sleep using the ULP? I want to minimize the current consumption of the ESP32 as much as possible while in deep sleep. Would I be able to use rtc_gpio_isolate() for the GPIO pin that I am using to read the ADC or would it affect the readings? I am also calling esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF) before initiating deep sleep. Would this also pose a problem?

Re: ADC with Deep Sleep

Posted: Thu Feb 06, 2020 12:53 am
by chegewara
Sorry, i misunderstood your question, so ignore my previous answer (and you are correct, it is to use ADC in ULP).

Wakeup from deep sleep is almost the same as reset esp32, so you have to perform full ADC initialization.

Re: ADC with Deep Sleep

Posted: Thu Feb 06, 2020 3:55 pm
by apurva
Noted. Thank you for your help!