ESP32 How to correct the ADC
See: Original_Output.jpg
Is it possible to get precise results from ESP32-ADC ?
Here we build a LookUpTable to correct this behavior
Sense is:
Read value Y and correct it like:
Y = ADC_LUT[Y]
FOR ME IT WORKS VERY WELL. (See: Correct_with_LUT.jpg)
I estimate the ESP32-DAC produces correct values.
====================== NOTE ===================================================
We know that is not true, but it is linear upto (about) output-value = 200)
To be more precise: measure the ouput voltage of 200 with a good external voltmeter
and calculate a slope factor. See: ESP32_DAC_WITH_MY_LUT.ino
With that I get good real world values up to 2.5 V !
===============================================================================
Then I want to build a LUT:
- Send a value X to DAC
- Read back value Y from ADC. (pins 25 and 35 are connected)
- Value Y (0..4095) mostly is too low. We need a LUT (0..4095) to correct the measured value.
- Correct the value: Y =LUT[Y]
- Plot the value Y which should match X now. (Attention: Y should be > about 70 !)
Because the DAC uses 8 bit I have to interpolate to get the LookUpTable 0..4095.
But the errors caused by that are much less than the usual noise.
I am really surprised how good the results are. Look at the image.
Here is the program. How to use: (Arduino_IDE, ESP32, Esp32_Correct_DA2.ino)
- Connect pin25 and pin 35
- Start the program
- Start the Serial Plotter
- Wait some minutes - you will see garbage (from the printout of results)
- See the corrected values as image (Correct_with_LUT.jpg). The correction is made for YOUR ESP32.
Second run: - Comment out #define GRAPH <<<<<<<<<<<<<<<<<<
- Start the program again
- Wait some minutes.
- When the program stops you get 2 arrays to include in your sources (well, use only one of them):
float ADC_LUT[4096] = { .... with best precision and int ADC_LUT[4096] = { ... less precision, but with less memory footprint
In your source: (Y: 0...4095)
Y=readAnalog(); Y=ADC_LUT[Y]; (look at the program)
ESP32_WITH_MY_LUT.ino is a demo program (to use with Serial Plotter).
It contains MY corrections. If you start it you may see the differences of YOUR ESP32 to mine.
Then use it with your own built and replaced ADC_LUT.
Here you can set your measured value for DAC(200) and then all results will give you real world voltages
with a precision of /- 0.01V upto 2.5 V
Advantages of a LookUpTable: Using it is much faster than using a fitted polynom and it should show better precision