Author Topic: ESP32 and their ADCs. How to work with them?  (Read 5842 times)

0 Members and 1 Guest are viewing this topic.

Offline viperTopic starter

  • Frequent Contributor
  • **
  • Posts: 306
  • Country: us
ESP32 and their ADCs. How to work with them?
« on: October 09, 2025, 12:42:58 am »
Trying to pull in a 0-5V analog sensor transducer signal.  Was going to use a discrete ADC but they are amazingly high priced for what they do, so figured I'd try to make the friggin BUILT IN ADCs do their job.  I have read that I need a precision Vref, all sorts of calibrations, RC filter, etc, etc.  Making me second guess a discrete ADC.  It would be best to achieve .001V resolution.  I am probably less worried about the actual "accuracy", more about "repeatability".  If .001V is not going to work, what are the options?  I can probably also get this sensor in a 0-12V version which might help with the step counts. 
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12498
  • Country: us
    • Personal site
Re: ESP32 and their ADCs. How to work with them?
« Reply #1 on: October 09, 2025, 01:31:08 am »
You can't get 1 mV resolution on a 5 V signal even in theory with 12 bit ADC, even assuming ADC is ideal.

ESP32 ADCs are notoriously bad. If you need more than rough battery voltage reading, use external ADC.

And it can't do 5V, so you would need to scale that down to 3.3 V.
Alex
 
The following users thanked this post: bookaboo, SiliconWizard

Offline viperTopic starter

  • Frequent Contributor
  • **
  • Posts: 306
  • Country: us
Re: ESP32 and their ADCs. How to work with them?
« Reply #2 on: October 09, 2025, 01:56:11 am »
You can't get 1 mV resolution on a 5 V signal even in theory with 12 bit ADC, even assuming ADC is ideal.

ESP32 ADCs are notoriously bad. If you need more than rough battery voltage reading, use external ADC.

And it can't do 5V, so you would need to scale that down to 3.3 V.

Thanks for the very direct reply.  I should clarify that this is a current transducer sensor, and the 1mV thought would be from the sensor, only to achieve a reasonable current value output.  I really don't need anything more than +/- .1A, or maybe even less on the sensor.  Primarily being used to determine if a device is running or not. 

I totally hear you on the 3.3V deal, and I can get these sensors made in other flavors, thus why I mentioned the 0-12V scale.  I might also have to balance the budget a bit.  I think a 16bit ADC is what I need, but most that I looked at were 5X the price, so I will have to balance cost and the reality of resolution. 
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12498
  • Country: us
    • Personal site
Re: ESP32 and their ADCs. How to work with them?
« Reply #3 on: October 09, 2025, 01:57:52 am »
Well, figure out absolute worst resolution you can accept. Based on that you can calculate ideal number of bits. You can then pick an ADC with ENOB that is at least that good.

Absolute value of the current does not matter, you need to figure out ho that maps to the 0-3.3V range. And with any ADC it is better to avoid extremes, so expect to stay away ~100 mV from the ends.

You also need to define expected sampling range. Fast ADCs get expensive.
« Last Edit: October 09, 2025, 02:00:50 am by ataradov »
Alex
 

Offline viperTopic starter

  • Frequent Contributor
  • **
  • Posts: 306
  • Country: us
Re: ESP32 and their ADCs. How to work with them?
« Reply #4 on: October 09, 2025, 02:23:23 am »
Well, figure out absolute worst resolution you can accept. Based on that you can calculate ideal number of bits. You can then pick an ADC with ENOB that is at least that good.

Absolute value of the current does not matter, you need to figure out ho that maps to the 0-3.3V range. And with any ADC it is better to avoid extremes, so expect to stay away ~100 mV from the ends.

You also need to define expected sampling range. Fast ADCs get expensive.

I get you, that ADC is going to bottle neck any analog range to that 3.3 range.  As for speed, this sensor will mostly need extremely lazy speed other than when a motor is in inrush, in which that normally occurs for about 150ms.  The precise about of time it stays in inrush is not important, just that it 'went there', and came back down to RLA amps.  I am looking at both the TLA2021 and MCP3460.  The MCP is oddly cheap, 16 bit, and 153k s/s.  Only 3.3v input though.  Even considering the TLA at only 3.3 s/s, that is a sample every 18ms, so it should capture an inrush artifact, but to be honest, that seems pretty lazy to me.  Even the ESP has way better speed. 

Most of this might come down to if the ESP ADC can be tamed to do the job or if it will be largely smarter to act like they don't even exist. 
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12498
  • Country: us
    • Personal site
Re: ESP32 and their ADCs. How to work with them?
« Reply #5 on: October 09, 2025, 02:37:11 am »
It is not about the voltage range. You need to figure out your current range and how that will map to the voltage range and sampled bits.

Stated number of bits is not the only important characteristic. You need to look at ENOB/INL/DNL. All those things affect the final result and how much infraction you can extract.

3.3 ksps is a sample every 0.3 ms.
Alex
 

Offline viperTopic starter

  • Frequent Contributor
  • **
  • Posts: 306
  • Country: us
Re: ESP32 and their ADCs. How to work with them?
« Reply #6 on: October 09, 2025, 03:30:05 am »
It is not about the voltage range. You need to figure out your current range and how that will map to the voltage range and sampled bits.

Stated number of bits is not the only important characteristic. You need to look at ENOB/INL/DNL. All those things affect the final result and how much infraction you can extract.

3.3 ksps is a sample every 0.3 ms.

Good catch on my late eve math.  That would indeed be plenty fast.  As for resolution, I agree, all that really matters is the output value, in which as mentioned +/- 0.15A between 5-20A, with a transducer that is 0-5V for currents of 0-100A.  Inrush is expected to be up to 80A, but I don't care if it's off 10A up there, I just consider that "in inrush state" for this device.  How long it's up there is more important, but that can also be off by 200ms and be just fine. 

It would be my preference to just use the ADC in the ESP, since more components is more design work, but if I will spend weeks trying to make that ADC do much, I can start to see value in a separate ADC.  Sort of sad they did not bring the heat with quality ADCs, but I sort of wonder if Espressif will fix that in future chips.  Something I am sort of thinking about with this design. 
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12498
  • Country: us
    • Personal site
Re: ESP32 and their ADCs. How to work with them?
« Reply #7 on: October 09, 2025, 03:42:03 am »
I'm really confused. Do you need to measure up to 20 A or 100 A? At 0.15 A resolution, the first one can be done with 8-bit ADC, the second one would need at least 10 bits. If you need something non-linear, things get more complicated.

ESP32 has estimated ENOB of ~6 bits. So, it wont work for your application, it is way too noisy. You can do a lot of averaging, and may be you can bring it up to 8 bits. But I would certainly experiment first before committing to the design.
Alex
 

Offline PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 3410
  • Country: au
Re: ESP32 and their ADCs. How to work with them?
« Reply #8 on: October 09, 2025, 03:48:35 am »
I really don't need anything more than +/- .1A, or maybe even less on the sensor.  Primarily being used to determine if a device is running or not. 
...
 As for resolution, I agree, all that really matters is the output value, in which as mentioned +/- 0.15A between 5-20A, with a transducer that is 0-5V for currents of 0-100A.  Inrush is expected to be up to 80A, but I don't care if it's off 10A up there, I just consider that "in inrush state" for this device.  How long it's up there is more important, but that can also be off by 200ms and be just fine.
I'm not sure where your 1mV came from?
0.15A in 20A is one part in 133, and you could consider a dual-slope (variable gain) approach, if you are ok with 10A errors at 80A levels.
You really just need to scale the current to be 'in range' for your ADC.
Current sense amps are quite cheap/good these days.

« Last Edit: October 09, 2025, 03:53:01 am by PCB.Wiz »
 

Offline PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 3410
  • Country: au
Re: ESP32 and their ADCs. How to work with them?
« Reply #9 on: October 09, 2025, 03:52:19 am »
Sort of sad they did not bring the heat with quality ADCs, but I sort of wonder if Espressif will fix that in future chips.  Something I am sort of thinking about with this design.

Their focus was on other things, and generally ADC's on MCUs struggle due to a lot of other things in close proximity.

There was a recent post on here suggesting later model ESP32 are better on the ADC?
 

Offline viperTopic starter

  • Frequent Contributor
  • **
  • Posts: 306
  • Country: us
Re: ESP32 and their ADCs. How to work with them?
« Reply #10 on: October 09, 2025, 04:08:10 am »
I'm really confused. Do you need to measure up to 20 A or 100 A? At 0.15 A resolution, the first one can be done with 8-bit ADC, the second one would need at least 10 bits. If you need something non-linear, things get more complicated.

ESP32 has estimated ENOB of ~6 bits. So, it wont work for your application, it is way too noisy. You can do a lot of averaging, and may be you can bring it up to 8 bits. But I would certainly experiment first before committing to the design.

Appreciate, and I will trying to refine my answer so it's more understandable.  I need a current response between 0-100A.  However, tighter resolutions are only needed between that 5-20A region.  Outside of that region, the resolution cab be very lax. 

It does sound like I will struggle with the ESP ADC and should just plan to add a discrete device. 

PCB.wiz, you mentioned good/cheap current sense amps, what did you have in mind? 

Also, to all, since talking on this, these sensors are being built custom.  Actually we specifically requested the DC output so we know they have a burden in them and cannot blow up if open line.  We could go back to mA output if that somehow solves an issue or makes this easier.  ? 
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12498
  • Country: us
    • Personal site
Re: ESP32 and their ADCs. How to work with them?
« Reply #11 on: October 09, 2025, 04:11:52 am »
INA226 and similar integrated solutions would be way better.
Alex
 

Offline Mr.B

  • Supporter
  • ****
  • Posts: 1319
  • Country: nz
Re: ESP32 and their ADCs. How to work with them?
« Reply #12 on: October 09, 2025, 04:51:07 am »
It does sound like I will struggle with the ESP ADC and should just plan to add a discrete device. 

As @ataradov said earlier, the ADC on ESP32 is next to useless.
The only thing I use it for is rough battery % indication.
Like: 20%, 40%, 60%, 80%, Full.
Nothing more.

As others have said, use a dedicated ADC or the INA226 (which works great as far as I am concerned.)
Where are we going, and why are we in a handbasket?
 

Offline PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 3410
  • Country: au
Re: ESP32 and their ADCs. How to work with them?
« Reply #13 on: October 09, 2025, 05:14:36 am »
PCB.wiz, you mentioned good/cheap current sense amps, what did you have in mind? 
Parts like the INA226 have i2c ADC included, and they will give very high performance.

Another approach is to use two INA180 or similar current amplifiers with different gains, and sum the outputs. That's might get into 'good enough' territory.
Like this :


That results in two gain regions : For mixing x50 and x200 amplifiers, at 25% of full scale current, it has reached ~62.3% of voltage full scale, and the upper 25%-100% of current is compressed into the remaining 32.7% of voltage. The slope change here is 5:1 as first both amplifiers are active, and then only the low gain one is active.
The red line is mixing 100x and 50x, as another example.
« Last Edit: October 09, 2025, 05:16:11 am by PCB.Wiz »
 

Offline viperTopic starter

  • Frequent Contributor
  • **
  • Posts: 306
  • Country: us
Re: ESP32 and their ADCs. How to work with them?
« Reply #14 on: October 09, 2025, 03:44:14 pm »
Not to be closed minded here but I am sort of hovering the TLA2021, or actually probably the TLA2022 because they are the same price and the 2022 has a PGA which may help somewhere down the line.  As opposed to the INA226, this is only a 12bit, and less features, but to be honest, it seems like it would serve the job?  We just don't need extreme accuracy and I have to fight to hold the budget down. 

I did want to ask on these chips, one thing we need or want is the entire circuit wakes up with an input on the ADC, indicating something has started running.  However, I need to determine if this chip can wake up from sleep mode in that way, but regardless the chip power consumption as 'active' is only 150uA so we can budget for that if we must. 
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 30368
  • Country: nl
    • NCT Developments
Re: ESP32 and their ADCs. How to work with them?
« Reply #15 on: October 09, 2025, 03:50:23 pm »
You can't get 1 mV resolution on a 5 V signal even in theory with 12 bit ADC, even assuming ADC is ideal.

ESP32 ADCs are notoriously bad. If you need more than rough battery voltage reading, use external ADC.
No. There are easy ways around the limitations of the ESP32 ADC. Basically these ADCs work from 50mV to around 3V in a 3.3V range. So limit the input signal to that range. Secondly, the internal reference is pretty bad but if you sample an external reference you can scale the readings accordingly. I've used an ESP32 in a cost sensitive application and the internal ADCs give me plenty of accuracy; the limitation is in the external components and reference. Not the ADC.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12498
  • Country: us
    • Personal site
Re: ESP32 and their ADCs. How to work with them?
« Reply #16 on: October 09, 2025, 03:57:20 pm »
TLA2022 is weird. It does not specify ENOB in any way and the datasheet in general seems to be light on performance details. I would evaluate it before putting into a product.

This device can't wake up on the conversion result. You will have to periodically wake up and get the conversion data. There are ADCs out there that have window comparator. They would autonomously convert the input and compare it to set thresholds. If the threshold is crossed, they would generate an interrupt that can wake up the MCU.
Alex
 
The following users thanked this post: viper

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17830
  • Country: fr
Re: ESP32 and their ADCs. How to work with them?
« Reply #17 on: October 09, 2025, 04:02:29 pm »
I would rather recommend the ADS1014 if the max sample rate is ok. Proven and straightforward.
 

Offline viperTopic starter

  • Frequent Contributor
  • **
  • Posts: 306
  • Country: us
Re: ESP32 and their ADCs. How to work with them?
« Reply #18 on: October 09, 2025, 09:00:47 pm »
Appreciate the feedback guys!  Very helpful.  I realize there are much better ADCs but honestly the price is quite high for these!  Can get an entire MCU for the cost of an ADC.  Still studying that 2021, or actually likely the 2022 just to have the PGA if ever needed.  Running a few numbers, it seems like it can work but I need to do some scope testing with the sensor to see how smooth the DC output really is.  Hell, the ADC cost rolls in what a decent precision reference would cost anyway, and keeping the analog out of the MCU is probably a good safety strategy. 

Right now trying to figure out the input filtering requirement.  Trying to keep it simple and treat like it will be a low impedance deal. 
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 30368
  • Country: nl
    • NCT Developments
Re: ESP32 and their ADCs. How to work with them?
« Reply #19 on: October 09, 2025, 09:38:40 pm »
In the design I worked on, I used the INA2180 dual current amplifier (2x INA180) as my application needed to measure current both ways but you can use a single current amplifier and two measurement ranges by using two ADC inputs. The ESP32's ADC can have different measurement ranges so there is your PGA. I used a fixed DC offset to keep the signal outside the range where the ADCs inside the ESP32 have a large offset. External filtering and filtering in software gets rid of noise pretty well. For a 6A range there is about 40mA of noise / offset in my design but the design uses a very low shunt resistance.

A reference doesn't have to cost much. But ofcourse it depends on the required accuracy which you have not specified. Aiming at better than 0.5% will require more expensive resistors and cost starts to add up. If you aim for better than 2%, the reference inside a voltage regulator will do just fine as your reference voltage.

« Last Edit: October 09, 2025, 10:24:05 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline viperTopic starter

  • Frequent Contributor
  • **
  • Posts: 306
  • Country: us
Re: ESP32 and their ADCs. How to work with them?
« Reply #20 on: October 09, 2025, 10:42:48 pm »
TLA2022 is weird. It does not specify ENOB in any way and the datasheet in general seems to be light on performance details. I would evaluate it before putting into a product.

This device can't wake up on the conversion result. You will have to periodically wake up and get the conversion data. There are ADCs out there that have window comparator. They would autonomously convert the input and compare it to set thresholds. If the threshold is crossed, they would generate an interrupt that can wake up the MCU.

As luck might have it, I realized the resources/pricing on some of this is much more inline from PCB houses, so that has now shifted me towards getting what I need rather than fitting the budget. 

With that said, might i spin this down to any other recommendations?  I would probably like to stick with TI only because all our other ICs are, so more familiar with their data sheets and pin names.  You mentioned the INA226.  I noticed it of course has way more features than needed.  But....  I mean it literally costs no more to get that.  I guess because we are only reading a 5v sensor, we connect as VBUS after some filtering, and work out the scaling? 

I guess I'd need to make sure we can reduce the SPS largely.  Less than 500 is more than enough for this and as I understand, reducing SPS can help with signal quality issues.  I'll do a little digging
 
 

Offline viperTopic starter

  • Frequent Contributor
  • **
  • Posts: 306
  • Country: us
Re: ESP32 and their ADCs. How to work with them?
« Reply #21 on: October 10, 2025, 01:48:33 am »
At the moment, strongly considering the ADS1115.  It has more options than the lesser 1113, but by the price, this one is more popular.  16 bit, serious accuracy, good operating and stand-by current, and most importantly, has the window comparator so I can wake things up on an input trip. 

To be honest, this seems like that TLA2022 with just the little extra that I need.  I do notice the SPS is low, but still probably 2x the speed I really need. 

Thoughts?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->