espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.33k stars 7.2k forks source link

[TW#12287] ESP32 ADC accuracy #164

Open nassks opened 7 years ago

nassks commented 7 years ago

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.

VinceW31 commented 5 years ago

For my project I got over the noise issue on the ADC inputs by taking an average reading over 50 samples taken 1ms apart. This produces a steady, stable and usable voltage reading where any errors can consistently be adjusted /compensated for. I repeat this process once a second to update my project and that works well for me.

srini1948 commented 5 years ago

In my application averaging is not an option - I need to operate at a sampling rate of 500000 samples/second.

T1bolus commented 5 years ago

Anyone noticed a gap between the values 2303 and 2353? I'm not able the read any voltages between this values :/.

Tested on ADC1 channel 3 and 7 with 0db and -6db on two different ESP32 Dev Boards.

srini1948 commented 5 years ago

The poor performance of the ADC makes the otherwise fantastic ESP32 useless for many applications. I have abandoned it in favor of Particle Photon.

marcmerlin commented 5 years ago

was this fixed/is it being fixed in a newer revision of the chip?

markterrill commented 5 years ago

The poor performance of the ADC makes the otherwise fantastic ESP32 useless for many applications. I have abandoned it in favor of Particle Photon.

@srini1948 just add the ads1115 and you'll have a much better and cheaper solution than a particle photon. I've got over 4,000 Particle P1's (the module chip version of the photon when you're producing large quantities) in the field and I'm moving our product across the ESP32.

raevillena commented 5 years ago

does the latest idf fix thsi issue or not? other than ADC i have no problems. yet without proper ADC using this board seems useless.

srini1948 commented 5 years ago

No IDF does not solve the problem.

raevillena commented 5 years ago

alright, I hope this will be fixed near to arduino or even better on the next hardware or software release

markterrill commented 5 years ago

srly, just use an ads1115. its much better than onboard ADC and has a number of filtering and protection benefits.

stefkpl commented 5 years ago

srly, just use an ads1115. its much better than onboard ADC and has a number of filtering and protection benefits.

I thought the same thing before finding this post, after 3 weeks lost, I'll use an external ADC. Now, I'm testing ADS7142 and MCP3221.

frippe75 commented 4 years ago

I know it's closed but still want to say... not good :-)

0xAl3xH commented 4 years ago

Been following this issue for 2 years now. Still no solution. At the point I can only believe that it is not a priority or cannot be solved by Espressif. Such a shame since the ESP32 is such a great board for IoT dev otherwise.

raevillena commented 4 years ago

Yeah I am now using dedicated adc. its not much trouble but its kinda hassle to layout in PCB and all extra code footprint. well its a nice workaround but as we know it should have been working. people are buying this because of a need. now maybe it is too expensive to solve it. lets just wait for the next version of the board.

VincentBruinink commented 4 years ago

The internal ADC gives between 4 and 5 LSB`s noise.

wosch1 commented 4 years ago

Hi, I'm new in this and looking into ESP32. I found and am aware of the cuple of errors of the ADC of this part. With my work I found a very strange behavior of the ADC. My observation looks into the huge amount of noise in the measurement of a stable voltage:

My setting: ESP32 devkit v1 attenuation 0db resolution 12 bit one sample on GPIO34 every one ms filtering with a simple Kalman filter output on COM port every 100 ms

The min and max readings are stored over the output periode and sent together with the result of the filter.

My observation: Over a time of about 17 seconds I can see the expected huge noise, but then for abaut 1.4sec. the noise is dramatical reduced. Then the periode repeats. Attached a picture. Variations of the settings do not have any influence.

It seems that the ADC in special conditions is able to give a quite low noisy reading, but this conditions are mostly not present? Is there any explanation for this behavior?

adc2b

srini1948 commented 4 years ago
This ADC is a piece of junk. Don’t use it. I gave up on this chip 2 years ago because of this. Sent from Mail for Windows 10 From: wosch1Sent: Saturday, March 14, 2020 12:38 PMTo: espressif/esp-idfCc: srini1948; MentionSubject: Re: [espressif/esp-idf] [TW#12287] ESP32 ADC accuracy (#164) Hi,I'm new in this and looking into ESP32. I found and am aware of the cuple of errors of the ADC of this part. With my work I found a very strange behavior of the ADC. My observation looks into the huge amount of noise in the measurement of a stable voltage:My setting:ESP32 devkit v1attenuation 0dbresolution 12 bitone sample on GPIO34 every one msfiltering with a simple Kalman filteroutput on COM port every 100 msThe min and max readings are stored over the output periode and sent together with the result of the filter.My observation:Over a time of about 17 seconds I can see the expected huge noise, but then for abaut 1.4sec. the noise is dramatical reduced. Then the periode repeats.Attached a picture.Variations of the settings do not have any influence.It seems that the ADC in special conditions is able to give a quite low noisy reading, but this conditions are mostly not present?Is there any explanation for this behavior?—You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or unsubscribe. 
wosch1 commented 4 years ago

Thanks for reply, I think you are right at all. But I am interrestet in the mechanics of the error. My mesurement show that the ADC periodically is able to sample the voltage over a time of about 1.5 s ( equals about 1500 samples) with a rather little noise. Why not during the other time? If one this could find out, the part would be a bit more useable.

negativekelvin commented 4 years ago

It is a pretty interesting result but that large of a period it seems like it is probably an external factor. What are your test conditions and what chip features are enabled?

wosch1 commented 4 years ago

Afaik I have no special chip features enabled in my sketch. It id not a real gadget, rather a workbench test. So in the vicinty is nothing with such a timing. Is it possible that the second core is working something I dont know? I have done some experiments with WIFI and BT with this devkit before, but not stored anything permanent. Could there be a leftover from that? The measured values are raw binary from the ADC (except the Kalman fitered value). Some infos in my first post. Attached a further picture. It shows the difference between the lowest and the highest reading over the COM sendperiod multiplied by 10. If you are interrested, I can send my code. adc4

wosch1 commented 4 years ago

For further explanation. I stored the min and max readvalues during the time between the serial messages. Then I send the difference ((vmax-vmin)10). Sampling occures every one ms, that means I sample100 readings. The blue line shows the diff between the highest and the lowest read value from this 100.(10)

MitchBradley commented 4 years ago

Has anybody tried with the WiFi turned off? The problem could be related to internal or external ground currents. When the radio is on, ground current could be causing voltage drops that are effectively in series with either the input to the ADC, or the internal reference, or both. A long ago I was tasked with reducing the noise of a 13-bit ADC that was implemented with discrete components. I improved it by >10 dB by changing the PCB layout so the ground current from other digital components flowed through separate paths so the ADC did not "see" the ever-changing ground voltage drop caused by the digital switching.

MitchBradley commented 4 years ago

In addition to ground current errors, the noise could be caused by other forms of interference from the radio. The antenna is very close to the SVN and SVP pins. There is a ground pin on the module that is quite close to the SVN and SVP pins, but the nearest GND pins on the dev boards are rather far away - one is on the other row of pins and another is at the other end of the row of pins from SVN/SVP. Given that, and the high currents involved in the radio, I suspect that this is a difficult problem to fix. I think an external ADC might be the only solution if low noise and high sample rate is required. We shall see how the new ESP32-S2 fares in this regard...

MitchBradley commented 4 years ago

The least expensive external ADC solution might be to add an ATTiny MCU. They cost about $0.30 in quantity, and have a 10 bit ADC that can sample one of several input pins and can accessed from another MCU via I2C. For not much more money, you can get a STM32G030J with a 32-bit MCU and 12-bit ADCs.

flodmotorgrodan commented 4 years ago

Without the ADC linearity problem fixed the ESP32 is like a ten floor building without an elevator. Wonder why the spent so much effort to make the product, and do not care about completing it?

Wonder how they think and where the thinking is located? What kind of reasoning can justify ignoring this gigant problem? Is it costly, impossible or some policy to never fix a broken thing?

It is a mystery.

MitchBradley commented 4 years ago

That's a very extreme position to take. Lots of applications do not require an ADC at all, others can get by with limited resolution ADC, still others can get by with slow ADC (noise reduction via averaging), and the linearity issue can be handled in software. Obviously it would be preferable to have a good ADC, but even without it, ESP32 is very good functionality for the money.

Regarding "why don't they fix it": do you have any idea how much it costs to do a mask set and other NRE for a microprocessor? Apparently you do not. Fixing an existing product, especially if the fix requires deep changes to layout, is often much less economical than coming out with a new product. The new ESP32-S2 is already starting production, slated to be out this summer, modulo coronavirus. We can hope that they have improved the ADC on that one. Maybe they have and maybe they haven't, but even if not, the new chip has impressive functionality and price/performance if the price is anywhere comparable to the old ESP32.

As Mark Twain said "To do good is noble. To tell other to do good is even nobler and much less trouble."

jan-bozelie commented 4 years ago

@mitchbreadly --> i disagree if you were one of the first users , and spend hunderd of hours , getting it to work , and on the end it will not work by faulty specifications , you would think otherwise and errors in technicue occur , its your attitude to fix it ( or not in this case )

wosch1 commented 4 years ago

It's true, a lot of applications do not need a very accurate ADC. In my case it's just the interest to understand and to find solutions for "as good as possible without attended invest". I think, the ESP's rather bad ADC is a "accident" in developement/design of the part and the investment to fix it is to high. As you said. But as you can see on my measurement, there are periodical times (1.5s) who the part is able to give results with rather low noise. What is the reason for the huge noise in the other time (17s)? Althoug in my sketch WIFI and BT are not used I switched both off explicitly. The strange behavior stays unchanged. A cuple of changes in my timing (samplerate, outputrate) and filtering ( Kalman, moving average) have no effect at all. Check of the supply gave no indication (USB 5V) for a variation. Could a watchdog timer or RTC or similar do this? I have none activated (knowingly).

wosch1 commented 4 years ago

Addentum: At the moment I am not looking in the linearity or offset problems.

grussy commented 4 years ago

I can also see a variation in ADC behavior every 17s. I sample four channels every second and send the measured values through wifi/mqtt. Every 17s I have one value measuring about 100mV less than for the rest of the time.

Auswahl_026

flodmotorgrodan commented 4 years ago

That's a very extreme position to take. Lots of applications do not require an ADC at all, others can get by with limited resolution ADC, still others can get by with slow ADC (noise reduction via averaging), and the linearity issue can be handled in software. Obviously it would be preferable to have a good ADC, but even without it, ESP32 is very good functionality for the money.

Regarding "why don't they fix it": do you have any idea how much it costs to do a mask set and other NRE for a microprocessor? Apparently you do not. Fixing an existing product, especially if the fix requires deep changes to layout, is often much less economical than coming out with a new product. The new ESP32-S2 is already starting production, slated to be out this summer, modulo coronavirus. We can hope that they have improved the ADC on that one. Maybe they have and maybe they haven't, but even if not, the new chip has impressive functionality and price/performance if the price is anywhere comparable to the old ESP32.

As Mark Twain said "To do good is noble. To tell other to do good is even nobler and much less trouble."

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

It should be stated in the datasheet the ADC has serious issues. Lot of companies start off thinking this any MPU with an ADC and slowly find out it has shaky readings an a terrible offset where calibration does not help.

Honesty and being service minded will work too.

MitchBradley commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

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 commented 4 years ago

Yes, Espressif suggests multisampling. I did some measurement series with a Pt1000 and some values were wrong. With 16 values out of 20 i get good results from -5°C to 140°C. I'm using it for a thermal solar control for over 3 months now.

---- jan-bozelie schrieb ----

@projectgushttps://github.com/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

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/espressif/esp-idf/issues/164#issuecomment-624463666, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADABDAWOFSWLRTLA2CYRERLRQD62TANCNFSM4CZVWPTQ.

svenbieg commented 4 years ago

_20200506_215817

wosch1 commented 4 years ago

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.

raevillena commented 4 years ago

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 commented 4 years ago

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 commented 3 years ago

This issues has any update?

svenbieg commented 3 years ago

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

VincentBruinink commented 3 years ago

It is a bug. It is a 12bit ADC with 3LSB's of noise leaving only 9bits of resolution if you do multisample or remove the noise with a filter. A 12bit ADC should have at least 12*6dB=72dB S/N. Even the cheap ones does.

On Fri, Dec 11, 2020, 8:03 PM Sven Bieg notifications@github.com wrote:

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/espressif/esp-idf/issues/164#issuecomment-743369040, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJHUW5TMSX25RL7UMSDXMK3SUJUHDANCNFSM4CZVWPTQ .

svenbieg commented 3 years ago

This is a comparison to other chips, no bug.

VincentBruinink commented 3 years ago

No it is not. A 12 bit ADC should be capable of capturing a signal with at least 72dB S/N (the math is (resolution*6)+3=S/N) The ESP32 is only capable of capturing a signal with 54dB S/N. So there is a serious bug in the hardware.

On Fri, Dec 11, 2020, 10:22 PM Sven Bieg notifications@github.com wrote:

This is a comparison to other chips, no bug.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/espressif/esp-idf/issues/164#issuecomment-743433552, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJHUW5XYDOL767UKTE7UOHDSUKESZANCNFSM4CZVWPTQ .

svenbieg commented 3 years ago

I don't think Espressif is promising this accuracy.

michapr commented 3 years ago

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 commented 3 years ago

They do. They are promising 12bits of resolution

On Sat, Dec 12, 2020, 12:43 AM Sven Bieg notifications@github.com wrote:

I don't think Espressif is promising this accuracy.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/espressif/esp-idf/issues/164#issuecomment-743483993, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJHUW5WBSGFJZFFJ6MGCCR3SUKVDPANCNFSM4CZVWPTQ .

stefkpl commented 3 years ago

What news about new ESP32-C3?

They solved ADC hardware bug?

Thanks

rsaxvc commented 3 years ago

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