ADC Accuracy on ESP32C3

While working on the wind direction vane for my weather station, I gathered some data on the accuracy of the ADC.

The wind vane contains 8 reed-switches arranged in an 8-pointed star shape on a small circular PCB. A small magnet in the rotating part of the vane actuates one of these reed switches, or, if it is roughly half way between two of them, it will actuate 2 adjacent reed switches together. Each reed switch has a different value resistor in series with it. If 2 adjacent reed switches are both active, their 2 resistors combine in parallel. So, the vane can have one of 16 different resistance values, depending on the wind direction.

I connected a fixed 10K resistor "R1" between the the XIAO ESP32C3's 3.3V pin and the A0 pin, and the vane "R2" was connected between A0 and ground, to make a voltage divider.

I wrote a short code to take the average of 1,000 values from digitalRead(A0) with 1ms delay between each reading and write the averages to serial monitor.

This is what I found:

Direction Vcc R1 R2 Expected V Actual V Diff V Expected ADC Actual ADC Diff ADC
112.5 3.28 10000 688 0.21 0.21 -0.5% 263 282 7.1%
67.5 3.28 10000 891 0.27 0.27 0.6% 335 361 7.7%
90 3.28 10000 1000 0.30 0.30 0.6% 372 400 7.4%
157.5 3.28 10000 1405 0.40 0.41 1.5% 505 543 7.6%
135 3.28 10000 2200 0.59 0.59 -0.2% 738 796 7.8%
202.5 3.28 10000 3129 0.78 0.79 1.1% 976 1058 8.4%
180 3.28 10000 3890 0.92 0.92 0.2% 1147 1244 8.5%
22.5 3.28 10000 6568 1.30 1.30 0.0% 1623 1774 9.3%
45 3.28 10000 8200 1.48 1.48 0.1% 1845 2024 9.7%
247.5 3.28 10000 14115 1.92 1.92 0.0% 2397 2643 10.3%
225 3.28 10000 16000 2.02 2.02 0.1% 2520 2779 10.3%
337.5 3.28 10000 22239 2.26 2.26 -0.1% 2825 3116 10.3%
0 3.28 10000 33000 2.52 2.52 0.1% 3143 3486 10.9%
292.5 3.28 10000 43459 2.67 2.66 -0.2% 3329 3719 11.7%
315 3.28 10000 68200 2.86 2.86 0.0% 3571 4050 13.4%
270 3.28 10000 119800 3.03 3.02 -0.2% 3780 4095 8.3%

At best, the ADC readings were 7% higher than I expected, and as the input voltage increased, the error got increasingly worse until, at an input voltage of just over 3V, the ADC hit its maximum 4095 reading.

I expected 4095 to correspond to around 3.3V.

I have read that the ESP32C3's ADC is not ratiometric, but may be based on it's internal voltage reference (1.1V).

As far as I can see, there are no voltage dividers on the XIAO's internal schematic, so I assume there is some configuration done to allow anaglodRead() to read up to around 3.3V for the analog input pins.

Could these inaccuracies be due to the inaccuracy of the chip's internal voltage reference, and is there some way to calibrate and correct for it?

Correct. That makes the result also a bit dependent on the stability of the 3.3volt supply.
For extreme cases you can power the voltage divider from a separate regulator.

The linearity seems pretty good already.
But since you have the actual test data...
You can use multiMap() to iron out the wrinkles.
All you need for that is two equal-sized arrays, one with A/D value and one with mV values.
You can cut off the extreme at the lower end of the A/D range by adding a ground-lift resistor to the sensor.
But all of this seems overkill for a 16-position sensor.
Leo..

It's linear enough at most voltages. I just need to avoid getting too close to 3V where the linearity is not so good.

So I put 2.33K in series with the 10K to reduce voltage at all directions below 3V. This seems to be working ok but further testing required.

Happy new year!

Hi Paul, happy new year!
I did some simple tests comparing the ESP32 ADC against an ADS1115 in two ways
1: generating a voltage with the ESP32 DAC (its extremely good) and
2: generating a voltage with PWM and a filter (again very linear)

The zero error needs a correction, and as you say the non-linearity is worse at the top end.


I've also done some tests looking at the stability of a 3.3V regulator, - I cant find them at present but as I recall I was surprised how good they were.
Job for the new year - repeat those tests!

Hi , happy new year , to every body.
I am very interested in this post , doing the same tests but my curve tend to bend down at the upper values.

Did you use ?

analogReadMilliVolts(pin) ;

or

analogRead(pin);

I should point out that @johnerrington is testing an ESP32 (presumably one of the older models) whereas I am testing an ESP32C3.

Both chips are from the same manufacturer (Expressif) but use different CPU cores (Xtensa Vs RISC-V). So their ADC circuits could also be quite different designs and we shouldn't necessarily expect to see the same characteristics between models.

I used analogRead() in my tests.

Have written a windRose() function in the past which might be useful (after some modification).

char _windRose2[17][4] = { "N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW", "N"};

char * windrose(double degrees)
{
  uint8_t idx = (degrees + 11.25) * 0.044444444444444;  //  1.0 / 22.5
  return _windRose2[idx];
}

It is part of my AngleConvertor library,
(the array has the postfix 2 as remnant of past experiments)

Extensive comparisons of ESP32-x ADC performance.