Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TW#12287] ESP32 ADC accuracy #164

Open
nassks opened this issue Dec 14, 2016 · 160 comments
Open

[TW#12287] ESP32 ADC accuracy #164

nassks opened this issue Dec 14, 2016 · 160 comments

Comments

@nassks
Copy link

@nassks nassks commented Dec 14, 2016

Hi,

I'm testing the ESP32's ADC on the SparkFun ESP32 Thing.
Currently my measure seems very noisy, it constantly varies on the 5 first bits, and the zero value is around 90mV.
Is there a way to achieve better accuracy?

My test code :

adc1_config_width(ADC_WIDTH_12Bit);
adc1_config_channel_atten(ADC1_CHANNEL_7, ADC_ATTEN_0db);

while (true) {
        vTaskDelay(300 / portTICK_PERIOD_MS);
        printf("ADC value : %x\n", adc1_get_voltage(ADC1_CHANNEL_7));
}

Thank you in advance for your help.

@projectgus
Copy link
Member

@projectgus projectgus commented Dec 15, 2016

The ADC has a non-linear response, and we are working on producing characterisation data which will be added to esp-idf to produce a linear output.

When you say "noisy", are you getting noisy readings on a constant voltage or is this noise caused by the non-linearity?

There's some more in this related Arduino bug: espressif/arduino-esp32#92

@projectgus projectgus changed the title ESP32 ADC precision ESP32 ADC accuracy Dec 15, 2016
@CarlosGS
Copy link

@CarlosGS CarlosGS commented Dec 16, 2016

@projectgus
Copy link
Member

@projectgus projectgus commented Dec 19, 2016

@CarlosGS : for issues, it is much better to start a new one than to post off-topic in an existing one.

For questions like this, the http://esp32.com forum may be an even better choice.

@michapr
Copy link

@michapr michapr commented Dec 27, 2016

@projectgus : I think nassks means the "noise" within same values - additional I have seen that there is a "noise" between the inputs.
put 1 Volt (with capacititor) on inputs CH4 ..CH7 I get such results:
(using 0bd and 11db for the values)

ADC1 CH4 value: 3719 @ 0db, 1056 @ 11db
ADC1 CH5 value: 3889 @ 0db, 1052 @ 11db
ADC1 CH6 value: 3883 @ 0db, 1052 @ 11db
ADC1 CH7 value: 3891 @ 0db, 1052 @ 11db
-------
ADC1 CH4 value: 3867 @ 0db, 1056 @ 11db
ADC1 CH5 value: 3885 @ 0db, 1053 @ 11db
ADC1 CH6 value: 3887 @ 0db, 1040 @ 11db
ADC1 CH7 value: 3886 @ 0db, 1057 @ 11db
-------
ADC1 CH4 value: 3894 @ 0db, 1056 @ 11db
ADC1 CH5 value: 3855 @ 0db, 1061 @ 11db
ADC1 CH6 value: 3887 @ 0db, 1049 @ 11db
ADC1 CH7 value: 3875 @ 0db, 1053 @ 11db
-------

Difference is up to 5% - maybe it is normal?

But for 0V - I get a value "0" ... without "noise" - it is ok for me

Michael

@michapr
Copy link

@michapr michapr commented Dec 27, 2016

Do not know why the crazy style came up before ;)

Code snippet for reference:

...
adc1_config_width(ADC_WIDTH_12Bit);
...
adc1_config_channel_atten(ADC1_CHANNEL_4,ADC_ATTEN_0db);
int val=adc1_get_voltage(ADC1_CHANNEL_4);
adc1_config_channel_atten(ADC1_CHANNEL_4,ADC_ATTEN_11db);
int val1=adc1_get_voltage(ADC1_CHANNEL_4);
printf("ADC1 CH4 value: %d @ 0db, %d @ 11db\n", val, val1);
....

Michael

@marcmerlin
Copy link

@marcmerlin marcmerlin commented Mar 28, 2017

So, in case anyone finds this ADC bug, I've found another ADC issue apparently where it will return data between 0-50% input, and cap out at 4096 from 50 to 100% input, but only after I try to use RMT.
Details here: #462

@marcmerlin
Copy link

@marcmerlin marcmerlin commented Apr 4, 2017

So, the lastest arduino-esp32 fixes the issue I just reported when RMT is turned on, analogread values would get damaged.

@FayeY
Copy link
Collaborator

@FayeY FayeY commented May 4, 2017

Hi nassks, is this problem solved?

@igrr
Copy link
Member

@igrr igrr commented May 4, 2017

@FayeY not yet, @Spritetm is working on it.

@FayeY FayeY changed the title ESP32 ADC accuracy [TW#12287] ESP32 ADC accuracy May 4, 2017
@dmody
Copy link

@dmody dmody commented May 6, 2017

Just leaving my two cents on this...
I was hoping to use an inexpensive Voltage Reference IC (LM4040C30ILP) to help increase the accuracy of measured values. I too found the ADC to be non linear and have included my data below for anyone interested.
voltage, ADC
2 2222
3 3730
1 1033
1.5 1629
0 0
0.5 422
2.5 2840
2.8 3300
3.1 3980
3.007 3750

image

@dmody
Copy link

@dmody dmody commented May 7, 2017

took another crack at this, and assuming the ADC readings are related to the 3.3V regulator voltage (mine is at 3.275 V on a developer board). Here's what I found.
image

@negativekelvin
Copy link
Contributor

@negativekelvin negativekelvin commented May 7, 2017

@dmody interesting, have you tried to fit curves to the upper range and lower range separately?

@imotion-software
Copy link

@imotion-software imotion-software commented May 11, 2017

In the future, are you planning to include linearization of adc1_get_voltage or it will be in charge to the user to correct non linear behavior?

Just to know, because if we implement linearization on user app and then adc1_get_voltage will change behavior we'll have to remove all those parts.

@dmody
Copy link

@dmody dmody commented May 11, 2017

@markterrill
Copy link

@markterrill markterrill commented Jun 18, 2017

really interested in this

@al3x-huang
Copy link

@al3x-huang al3x-huang commented Jun 22, 2017

Are we going to fix this soon? I feel like many applications depend on this feature. Is there a workaround at least?

@Spritetm
Copy link
Member

@Spritetm Spritetm commented Jun 23, 2017

Yes, we are. It took us some time to build an automated testing rig to accurately and reliably grab the characteristics of a representative sample of ESP32s; that has rendered the first curves this week and we're working on converting these into some linearization code.

@al3x-huang
Copy link

@al3x-huang al3x-huang commented Jun 30, 2017

@Spritetm any updates on this? Perhaps a timeline to when this might be fixed? Thanks!

@MaxSNi
Copy link

@MaxSNi MaxSNi commented Jul 28, 2017

@Spritetm @igrr I would love to hear an update on this - or if there is an effective workaround?

@dmody
Copy link

@dmody dmody commented Jul 28, 2017

@MaxSNi
The best workaround for me was to write a little function that returns the voltage based on the DAQ value using the formula I presented above. I can post the function if you like.

@MaxSNi
Copy link

@MaxSNi MaxSNi commented Jul 28, 2017

@dmody I would love to see your function. I made a quick function from my own excel trend equation and while it does work better, its pretty crude...

@dmody
Copy link

@dmody dmody commented Jul 29, 2017

@MaxSNi
//*************************************** Analog to Digital Conversion Function ****************************
float A2D(float SenVal)
{
if(SenVal<1) return(0);
else if (SenVal>4094) return(99);
else return(-0.000000000023926 * pow(SenVal,3) + 0.000000094746 * pow(SenVal,2) + 0.00074539 * SenVal + 0.14925);

}

@imotion-software
Copy link

@imotion-software imotion-software commented Aug 3, 2017

Is there any update on this issue?
It sounds me really crazy that on an IoT chip there's no way to have a good ADC reading.

@markterrill
Copy link

@markterrill markterrill commented Aug 3, 2017

Probably time to look at other options.
i realised a few months ago its simply not going to be ready anytime this calendar year for production use

@jan-bozelie
Copy link

@jan-bozelie jan-bozelie commented Aug 21, 2017

we have a simmulair problem , i can live with a correction factor but we discoverd in testing 10 esp32 samples , the difference between samples can be >10 to 20% , making a calibration nessesery for each esp , making it unusable for serios work

@MitchBradley
Copy link

@MitchBradley MitchBradley commented Apr 7, 2020

When cars catch fire at lest manufacturers show the have a plan or worry about the problem.

When Toyotas were accelerating out of control, the response for a long time was denial. Volkswagen similarly denied the diesel emission cheating for a long time. Ralph Nader became famous by revealing that car manufacturers were hiding safety problems Hiding problems is not good, but it is common. In a company, it is pretty difficult to get rewarded for being honest about problems, especially when it could hurt sales, but it is pretty easy to get fired. That's the way the world works. It sucks, but it is what it is.

@svenbieg
Copy link

@svenbieg svenbieg commented May 5, 2020

There are detailed instructions how to read analog values on the ADC-page of Espressif. You have to use multisampling! I collect 20 values, sort them and remove the two smallest and the two greatest to filter wrong ones. Then i calculate the average of the left values. These values can be collected, sorted and filtered again to get a more stable result. I get usable temperatures of a Pt1000 with only a simple voltage divider this way, even with WiFi enabled.

@jan-bozelie
Copy link

@jan-bozelie jan-bozelie commented May 6, 2020

@projectgus --> thanks for the sugestions , is this some ESP sugests on there side ?? . your saying more or les 2 out of 10 readings are rubbisch . We tried even 100* oversampling . and we had no usable result inside a decents acuracy

@raevillena
Copy link

@raevillena raevillena commented May 6, 2020

There are detailed instructions how to read analog values on the ADC-page of Espressif. You have to use multisampling! I collect 20 values, sort them and remove the two smallest and the two greatest to filter wrong ones. Then i calculate the average of the left values. These values can be collected, sorted and filtered again to get a more stable result. I get usable temperatures of a Pt1000 with only a simple voltage divider this way, even with WiFi enabled.

yes that works, but still wont solve the linearity of the reading. those are just sampling techniques we can implement. to fix the linearity it is so laborious to calibrate 1 esp at a time

@svenbieg
Copy link

@svenbieg svenbieg commented May 6, 2020

@svenbieg
Copy link

@svenbieg svenbieg commented May 6, 2020

_20200506_215817

@wosch1
Copy link

@wosch1 wosch1 commented May 7, 2020

Hi,
we have to make a difference between hobbyists and professionals. A hobbyist can calibrate each exemplar of his Project, which is unacceptable for a professional.
In my opinion the biggest problem ist the "dead zone" near zero. So a correct measurement of a voltage for example isn't possible in this region.

@CarlosGS
Copy link

@CarlosGS CarlosGS commented May 7, 2020

After so many years, it's evident that the ADC was implemented merely for marketing reasons (:

I think we will be missing a proper apology from Espressif on this matter. And of course we can forget about a reliable ADC until they can sell us one.

But we do take note, @espressif, we do take note.

@raevillena
Copy link

@raevillena raevillena commented May 8, 2020

I don't think so. There is a formula how to compensate non-linearity in this thread. The chip has a reference voltage wich could cause offset-problems. You need to get a known voltage to an input pin, then You can calculate the Offset too!

---- raevillena schrieb ---- There are detailed instructions how to read analog values on the ADC-page of Espressif. You have to use multisampling! I collect 20 values, sort them and remove the two smallest and the two greatest to filter wrong ones. Then i calculate the average of the left values. These values can be collected, sorted and filtered again to get a more stable result. I get usable temperatures of a Pt1000 with only a simple voltage divider this way, even with WiFi enabled. yes that works, but still wont solve the linearity of the reading. those are just sampling techniques we can implement. to fix the linearity it is so laborious to calibrate 1 esp at a time — You are receiving this because you commented. Reply to this email directly, view it on GitHub<#164 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADABDAXXU7AOQCKLDZZCMPDRQFF6LANCNFSM4CZVWPTQ.

yes i understand and i have tried that already. but like i said Its just to laborious and waste of computing cycles just for compensation, for a code that is time critical, sometimes assync. hmm nahh.

@prtomlinson
Copy link

@prtomlinson prtomlinson commented Aug 3, 2020

Some Comments on ADC noise and accuracy from someone who designed data converters embedded into SOC's.
Although the Espressif spec says ADC1 has a resolution of 12 bits it is impractical to use it as a 12bit ADC. The specified DNL is +/- 8lsb or 2.1mv. This means ADC1 is a 9bit converter(lsb->2.15mv). In a SOC design using a junction isolated CMOS process such as TSMC 40nm the noise floor is typically above 1mv rms. This noise can be either correlated to clocks or pink due to the nature of the radio system. The only practical solution is averaging based on characterization of the application environment. I would be impressed if Espressif achieved 10 bits accuracy.

My issue is the conversion error vs input voltage. I would really like someone for Espressif to comment and provide compensation information. If the error is repeatable it can be corrected.
Thanks,
Tekguy49

@zheyuejiang
Copy link

@zheyuejiang zheyuejiang commented Dec 11, 2020

This issues has any update?

@svenbieg
Copy link

@svenbieg svenbieg commented Dec 11, 2020

It ain't a bug, it is working fine for me. You can find detailed information about multisampling on Espressif's ADC-site!

@VincentBruinink
Copy link

@VincentBruinink VincentBruinink commented Dec 11, 2020

@svenbieg
Copy link

@svenbieg svenbieg commented Dec 11, 2020

This is a comparison to other chips, no bug.

@VincentBruinink
Copy link

@VincentBruinink VincentBruinink commented Dec 11, 2020

@svenbieg
Copy link

@svenbieg svenbieg commented Dec 11, 2020

I don't think Espressif is promising this accuracy.

@michapr
Copy link

@michapr michapr commented Dec 12, 2020

You can use the ADC with multisampling, calibration and ... but never will get from ESP32 such a reliable result as from a good ADC like ADS1115.
It depends on your needs - since a long time I do not longer use ESP32 ADC for any sensors,... do not trust the results more ;)
But for simple control of values it is ok.

@VincentBruinink
Copy link

@VincentBruinink VincentBruinink commented Dec 12, 2020

@stefkpl
Copy link

@stefkpl stefkpl commented Dec 12, 2020

What news about new ESP32-C3?

They solved ADC hardware bug?

Thanks

@rsaxvc
Copy link

@rsaxvc rsaxvc commented Dec 12, 2020

@VincentBruinink is it possible you might be confusing number of bits (12) for effective number of bits (ENOB, not sure if specified)?

@markterrill
Copy link

@markterrill markterrill commented Dec 14, 2020

I don't think Espressif is promising this accuracy.

It ain't a bug, it is working fine for me. You can find detailed information about multisampling on Espressif's ADC-site!

You've made it clear where you sit in the spectrum of people purchasing this chip. We've heard you. You're also dead set wrong for commercial applications, but that's ok, you do you.

For anyone serious, ADS1119IPWR. It's next level tech from TI with proper input buffers (we've got 1Mohm sources) / internal reference / I2C / 16bit / PGA and common noise rejection at 20 SPS.

@VincentBruinink
Copy link

@VincentBruinink VincentBruinink commented Dec 14, 2020

@MitchBradley
Copy link

@MitchBradley MitchBradley commented Dec 14, 2020

Nope. It is specified as a 12-bit SAR ADC.

Just because the ADC is specified as 12 bits does not mean that you get 12 bits of useful data. You can have a million-bit ADC with a noisy power supply and you might be lucky to get 2 bits of actual information. The longstanding problems with the ESP32 ADC are in the noise category. Depending on the phase of the moon it will generate useful results for awhile, then the answer will jump around with no change in the input voltage. It is probably picking up noise from some other subsystem in the chip turning on and off. It could be related to the radio, or the cache, or some I/O device; so far nobody has figured it out for sure. Maybe Espressif knows, but if so they are not saying. It is really hard to get precision analog results from a system-on-chip that has as many digital and radio functions as ESP32. The best analog systems have strict isolation between digital circuitry and analog areas, with careful separation of ground paths, power routing, and galvanic/magnetic isolation of critical analog areas. That is really tricky to do all on one small die that has many other functions and especially that has too few pins to allow separate power and ground for analog circuits. Most likely, the ESP32 ADC was included just to check a box on a marketing bullet list. It can be useful for low-accuracy stuff like monitoring battery voltage, but getting high accuracy requires serious averaging. Even that is of questionable utility, since the noise is not gaussian - it tends to be step functions that jump around at hard-to-predict times.

@VincentBruinink
Copy link

@VincentBruinink VincentBruinink commented Dec 14, 2020

@flodmotorgrodan
Copy link

@flodmotorgrodan flodmotorgrodan commented Dec 27, 2020

The ADC has unusual linearity and offset drawbacks. When feed a linear ramp the lowest range is terribly non linear.

ESP32_ADC_vs_PWM_DAC_2

Also the ADC is "dead" with no reading below 100 LSB on a 4096 scale depending on amplification.

ADC_Sweep_2018-11-20_123554

It means the ADC inputs have to be offset with external components to start measuring from 0V. That is really bad.

We can live with the noise, and it is not that bad as you can see from the multisampled curve. But the ADC being detached from reality makes it a bad experience. The ESP32 is a fantastic device it is such a pity the ADC problem never gets corrected.

@pylorak
Copy link

@pylorak pylorak commented Mar 13, 2021

This is a comparison to other chips, no bug.

Actually, this probably is a bug. It becomes more clear to see it when you have some additional context. The ESP32 contains also an internal temperature sensor and even an analog comparator, but they were removed from all documentation and specifications because they turned out to be unusable months after release. Not not-working-unusable, but working-but-so-bad-that-they-were-unusable. The hardware should still be there in everyone's chips even today, just disabled/unsupported/unreachable through the IDF libraries because their functionality was officially discontinued.

Now, the following is just a hunch, but I assume there is a connection between the removed parts and the under-performing ADC: a general (design- or manufacturing-related) problem with the analog parts of the IC, which is why these components had to be removed and why the ADC performs so poorly. Back when the ESP32 V3 came out, I was actually most excited because I was hoping they would finally fix the analog issues: improve the ADC and maybe even re-enable the other integrated peripherals. Unfortunately this was not the case.

The ESP32 is a very cool and versatile part with a low price, and probably my biggest gripe with it is its ADC. You simply cannot fix some of its defects using multisampling, and per-device calibration is not an option for mass production. I've learned to use external ADCs in ESP32-based projects where I need more than just simple "room temperature measurements". One of my current favorites is the TLA2024. Cheap, small, accurate and easy-to-use.

@DavidSG2020
Copy link

@DavidSG2020 DavidSG2020 commented Mar 17, 2021

I have been doing analog and digital electronics since the dawn of the microprocessor era., and I can say quite definitively that this is not a bug.

It is totally and utterly incompetent design papered over by marketing specmanship.

The guys who designed these parts are brilliant digitologists, but don't know squat about analog chip design.

IMHO the only kind of ADC for which "multisampling" can be justified as a means of hitting a headline spec is in a sigma-delta converter, where you can achieve 23 bit resolution with sufficient filtering. Been there, done that.

Headlining a 12-bit ADC then burying the truth in a table deep in a data sheet is simply deceptive. And that truth says to me "8 bits".

I am now a happily retired hobbyist, doing my first ESP32 design. Fortunately I don't need the ADC function except for a trivial reading of an LDR. I love the pure grunt of the ESP32. Well, atleast I am forewarned if my next project needs some serious A to D.

@srini1948
Copy link

@srini1948 srini1948 commented Mar 17, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet