Skip to content

Compensating Measurement Errors

jbaumann edited this page Feb 19, 2022 · 1 revision

Compensating Measurement Errors

A single ADC measurement (either voltage or temperature) can be imprecise. There are differences in consecutive measurements coming from the inherent imprecision in the measurement process.

Much stronger though is the influence of the current draw on the battery's voltage level, especially if the battery is nearly discharged.

To compensate both effects multiple measurements are taken, the lowest and the highest measurement are discarded and the mean of the remaining values is used.

Currently 5 measurements are used for this approach.

Compensating for intrinsic measurement offsets and integral non-linearity

We use two values to compensate our measurements. We use a coefficient as a multiplier to change the gradient of the measurement curve and a constant to correct any offset (see the following diagram).

For every one of the measurements, battery and external voltage, these two values are used for the compensation. By using these values the measurements reported by the ESP32 can be good enough for our purposes. The ADCs of the ESP32 are not the best, so don't expect too much accuracy or precision.

Calculating the correct Values

Let us assume that you have measured two values Vm1 and Vm2 and that the ESP32 has reported the values Vt1 and Vt2.. By viewing the values from the ESP32 as the x values and the measured values as the y values we have two points that describe the projection from the values seen by the ESP32 to the actual values measured. Using this and the standard linear equation ax+b we can compute the coefficient a and the constant b.