Professionals Know This!

by Fernando Koyanagi in Circuits > Microcontrollers

1697 Views, 2 Favorites, 0 Comments

Professionals Know This!

Os profissionais sabem isso!

Today we are going to talk about “ ESP32 automated ADC calibration ”. It may seem like a very technical subject, but I think it's very important for you to know a little about it.

This is because it is not just about the ESP32, or even the ADC calibration only, but rather of everything that involves analog sensors that you might want to read.

Most sensors are not linear, so we are going to introduce an automated prototype calibrator for analog digital converters. Also, we are going to make a correction of an ESP32 AD.

Introduction

01.png

There is a video in which I talk a little about this subject: Didn't you know? ESP32 ADC adjustment. Now, let's talk in an automated way that prevents you from doing the entire polynomial regression process. Check it out!

Resources Used

07.png

· Jumpers

· 1x Protoboard

· 1x ESP WROOM 32 DevKit

· 1x USB cable

· 2x 10k resistors

· 1x 6k8 resistor or 1x 10k mechanical potentiometer for adjusting the voltage divider

· 1x X9C103 - 10k digital potentiometer

· 1x LM358 - Operational amplifier

Circuit Used

08.png

In this circuit, the LM358 is an operational amplifier in the “voltage buffer” configuration, isolating the two voltage dividers so that one does not influence the other. This allows to obtain a simpler expression since R1 and R2 can, with a good approximation, no longer be considered in parallel with RB.

Output Voltage Depends on the Variation of the Digital Potentiometer X9C103

09.png

Based on the expression we obtained for the circuit, this is the voltage curve at its output when we vary the digital potentiometer from 0 to 10k.

Controlling the X9C103

10.png

· To control our X9C103 digital potentiometer we will feed it with 5V, coming from the same USB that powers the ESP32, connecting in VCC .

· We connect the UP / DOWN pin to GPIO12.

· We connect the pin INCREMENT to GPIO13.

· We connect DEVICE SELECT (CS) and VSS to GND.

· We connect VH / RH to the 5V supply.

· We connect VL / RL to GND.

· We connect RW / VW to the voltage buffer input.

Connections

11.png

Capture on the Oscilloscope of the Up and Down Ramps

12.png

We can observe the two ramps generated by the ESP32 code.

The values of the rise ramp are captured and sent to the C# software for evaluation and determination of the correction curve.

Expected Versus Read

13.png

Correction

14.png

We will use the error curve to correct the ADC. For this, we will feed a program made in C#, with the values of the ADC. It will calculate the difference between the value read and the expected, thus creating an ERROR curve as a function of the ADC value.

Knowing the behavior of this curve, we will know the error and we will be able to correct it.

To know this curve, the C# program will use a library that will perform a polynomial regression (like those performed in previous videos).

Expected Versus Read After Correction

15.png

Program Execution in C#

161.png

Wait for the Ramp START Message

162.png
17.png

ESP32 Source Code - Example of a Correction Function and Its Use

code1.jpg

Comparison With Previous Techniques

19.png

ESP32 SOURCE CODE - Declarations and Setup ( )

code2.jpg

ESP32 SOURCE CODE - Loop ( )

code3.jpg

ESP32 SOURCE CODE - Loop ( )

code4.jpg

ESP32 SOURCE CODE - Pulse ( )

code5.jpg

SOURCE CODE OF THE PROGRAM IN C# - Program Execution in C #

26.png

SOURCE CODE OF THE PROGRAM IN C# - Libraries

27.png

SOURCE CODE OF THE PROGRAM IN C # - Namespace , Class and Global

28.png

SOURCE CODE OF THE PROGRAM IN C# - RegPol ()

code6.jpg

30.png

Download the Files