VCC measurement with ADC via GPIO39

poweruser123
Posts: 2
Joined: Wed Oct 04, 2017 3:00 pm

VCC measurement with ADC via GPIO39

Postby poweruser123 » Wed Oct 04, 2017 3:05 pm

Hallo all,

I have a small problem. I connected VCC with GPIO 39 to check the VCC of the battery. However I always get 4095 as result, independent of the VCC of the battery.

I use following code:

Code: Select all

  
    adc1_config_width(ADC_WIDTH_12Bit);
    adc1_config_channel_atten(ADC1_CHANNEL_3,ADC_ATTEN_11db);
 
   int val =  adc1_get_voltage(ADC1_CHANNEL_3);
   
Can you please help me, to understand where my error is? Is the direct wiring the problem or am I doing simething wrong with the code?

The espressif specification says that GPIO39 can me used for ADC, as I understood it.

Many thanks.

Best Regards

poweruser123
Posts: 2
Joined: Wed Oct 04, 2017 3:00 pm

Re: VCC measurement with ADC via GPIO39

Postby poweruser123 » Sun Oct 08, 2017 1:42 pm

Hi all,

does no one has an idea, whether GPIO 39 can be used for ADC (VCC measurement)? How is wiring supposed to be done?

Many thanks.

early-riser
Posts: 1
Joined: Thu Aug 10, 2017 8:09 pm

Re: VCC measurement with ADC via GPIO39

Postby early-riser » Tue Oct 10, 2017 5:04 pm

It is possible to use ADC1_3, which is GPIO #39. There is a very recent update to the analog API functions to measure the actual V REF and then use it to scale the analog inputs appropriately. You should be using the most recent ESP-IDF files and there is a sample project called 'adc' which will allow you see how the calibration routine is performed. It defaults to GPIO #34, but you can change that. Also note the sample code has "0db" for the attenuation - so change this to "11db" if you want to use 3.3 V as full scale. In my testing, the ESP32 chip was able to read from a low point of 0.12 V all the way up to ~3.1 V with "11db" attenuation.

DrScanlon
Posts: 11
Joined: Tue Oct 04, 2016 8:46 pm

Re: VCC measurement with ADC via GPIO39

Postby DrScanlon » Fri Oct 13, 2017 12:19 am

Hello,
I just ran a test with ADC1_3. I used voltage ranges from 0 to 3.2vdc for input. Just for a quick test, I used the common power supply ground for the analog ground. I read 4095 counts at approx 3.14vdc. If I decrease the voltage, I see an expected drop in the counts. It appears to be functioning as required. If your battery voltage never drops below 3.14 vdc, then you will always see 4095 counts as configured for this test.

Frank

DrScanlon
Posts: 11
Joined: Tue Oct 04, 2016 8:46 pm

Re: VCC measurement with ADC via GPIO39

Postby DrScanlon » Fri Oct 13, 2017 2:05 pm

I'm not sure what is going on with the forum. I attempted to post a reply previously and I got logged out.
About your measurement, I did a test using GPIO39 (ADC1 Channel 3) and found that 3.14vdc input resulted in 4095 counts. I decreased the voltage and saw a corresponding decrease in the AD counts. Note that if the battery voltage in your application does not drop below the max volts (3.14 in my case), then you will continue to see 4095 counts.

Frank

Who is online

Users browsing this forum: Baidu [Spider] and 138 guests