Measure VDD33 using ADC2

Posts: 9
Joined: Tue Feb 20, 2018 2:53 pm

Measure VDD33 using ADC2

Postby timm_f » Thu May 03, 2018 9:35 am


I am trying to measure the ESP32 supply voltage (VDD33) using ADC2.
From the ref. manual p565, I figured out to set bit SENS_SAR2_EN_TEST in register SENS_SAR_START_FORCE_REG.
I did these steps:
  1. configured attenuation for adc2 channel 7 to 6dB
  2. set bit SENS_SAR2_EN_TEST in register SENS_SAR_START_FORCE_REG
  3. called adc2_get_raw() for channel 7 and 12 bit resolution
This didn't work out... Questions which came to my mind:
  1. Do I have to use a specific channel?
  2. Do pads have to be configured?
Thanks in advance for any input.

Best Regards, Timm

Posts: 21
Joined: Tue Oct 03, 2017 12:02 pm

Re: Measure VDD33 using ADC2

Postby woofy! » Thu May 03, 2018 10:54 am

Perhaps someone will correct me if I'm wrong here, but .. .

I don't think you can do this directly. An ADC needs a reference to measure against and the ESP32 does not have one. I know some have said there is a 1.1v reference, but I think this is just the default 0db input range. It is so variable (1000mv to 1200mV) that it is useless as a reference and is possibly just a Vcc derived input range. In that case you will not be able to measure Vcc changes.

When I needed to measure the battery voltage powering an ESP32, I put a voltage divider across the battery and the mid point to the ADC. That way the regulator was the reference, and with a little calibration could monitor the battery.

Also I read that ADC2 cannot be used with the radio working. Does anyone know if that is still the case?

Posts: 1
Joined: Thu Jul 05, 2018 8:58 pm

Re: Measure VDD33 using ADC2

Postby CROSOFT » Thu Jul 05, 2018 10:22 pm

Did you ever find a solution to this?
The technical reference manual says on page 579, under register SENS_SAR_START_FORCE_REG:
SENS_SAR2_EN_TEST SAR2_EN_TEST is active only when reg_sar2_dig_force = 0. (R/W)
The reg_sar2_dig_force is not defined any where, I assume they mean SENS_SAR2_DIG_FORCE in SENS_SAR_READ_CTRL2_REG.
I have checked my code and this bit an is set to 0, I also did some experiments on selection other AD channels, but did not find a cure.

Section 28,3.2 mentions:
• One channel for internal voltage vdd33, two for pa_pkdet (available on selected controllers)
But the manual does not state that it should be possible to get a AD reading of the 3,3 V. Mine read 0.

I miss information on where the ADC reference is connected to. Normally this should be clear in the datasheet, but I did not find this information. As I can't see any AD reference on the pin out, I assume they have an internal AD ref. probably some build in reference or simply the 3V3 supply voltage somewhere on die where voltage stability is good. In case the reference is tied to 3V3 supply voltage, the AD conversion will always result in a reading of 4095, so it will not be possible to measure the 3V3 voltage, meaning that the en_test selection can only be used for some internal testing (Although I don't see the meaning in this)

Posts: 18
Joined: Wed Jul 25, 2018 3:34 pm

Re: Measure VDD33 using ADC2

Postby FrancisL » Fri Aug 03, 2018 8:05 am

I am also wondering whether measuring Vcc internally is possible?
Looking at the reference manual, the answer should be Yes... but the information to define the way is missing.
Any idea about the answers: is it actually possible and if Yes, HOW?

Posts: 107
Joined: Mon Mar 05, 2018 12:44 am

Re: Measure VDD33 using ADC2

Postby Archibald » Fri Aug 03, 2018 2:23 pm

An ADC set to maximum attenuation of 11dB will only measure up to about 3.1V on a 3.3V supply, and even then with lots of non-linearity. I therefore doubt it's possible to use an ADC to measure Vdd via internal connection. The suggestion in a previous post to use a voltage divider makes sense. That would allow you to use 6dB attenuation setting to give good linearity.

However, I wonder whether you could use an DAC to give you an output voltage proportional to Vdd instead of using a voltage divider. The ESP32 documentation indicates for a DAC that a digital value of 255 will give an output of Vdd. This is not the case: the DAC output is about 0.96*Vdd. Allowing also for a small zero offset, if you provide a digital value of 85, the DAC output will be close to one-third of Vdd.

You will need to calibrate the ADC to derive voltage values from digital values allowing for manufacturing variations of offset and slope. The internal voltage reference of about 1.1V should ensure that the ADC is not affected by changes of Vdd.

After ADC calibration, connect the DAC output to the ADC input and multiply voltage readings by three. Check the reading against a voltmeter connected to Vdd and if necessary adjust the digital value applied to the DAC. Hopefully someone can say whether it's possible to connect a DAC output to an ADC input internally or whether you would have to use an external link.

Use ADC1 or read the documentation about limitations of ADC2. Also read the documentation regarding ADC 'noise'.

Posts: 19
Joined: Sun Mar 22, 2020 10:19 pm

Re: Measure VDD33 using ADC2

Postby waterfox » Tue Jun 23, 2020 8:28 pm


is there anything new on this?

What do i need to set the ADC2 to measure VDD33 if Bluetooth and wifi are disabled.

Posts: 1
Joined: Mon Sep 14, 2020 5:54 am

Re: Measure VDD33 using ADC2

Postby rkit2134 » Mon Sep 14, 2020 9:01 am

  1. int read_battery() {
  2.     adc2_channel_t channel = ADC2_GPIO25_CHANNEL; // accepted gpios are 25, 26, 27
  3.     gpio_num_t adc_gpio_num;
  4.     int result;
  5.     ESP_ERROR_CHECK(adc2_pad_get_io_num(channel, &adc_gpio_num));
  6.     ESP_ERROR_CHECK(adc2_vref_to_gpio(adc_gpio_num));
  7.     ESP_ERROR_CHECK(adc2_config_channel_atten(channel, ADC_ATTEN_DB_6));
  8.     ESP_ERROR_CHECK(adc2_get_raw(channel, ADC_WIDTH_12Bit, &result));
  9.     return result;
  10. }

Seems to work.

Who is online

Users browsing this forum: Baidu [Spider], Majestic-12 [Bot] and 41 guests