ADC with Deep Sleep

apurva
Posts: 6
Joined: Tue Oct 08, 2019 2:47 pm

ADC with Deep Sleep

Postby apurva » Wed Feb 05, 2020 4:04 pm

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();

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: ADC with Deep Sleep

Postby chegewara » Wed Feb 05, 2020 6:26 pm

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();

apurva
Posts: 6
Joined: Tue Oct 08, 2019 2:47 pm

Re: ADC with Deep Sleep

Postby apurva » Wed Feb 05, 2020 7:14 pm

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?

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: ADC with Deep Sleep

Postby chegewara » Thu Feb 06, 2020 12:53 am

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.

apurva
Posts: 6
Joined: Tue Oct 08, 2019 2:47 pm

Re: ADC with Deep Sleep

Postby apurva » Thu Feb 06, 2020 3:55 pm

Noted. Thank you for your help!

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 126 guests