-
Notifications
You must be signed in to change notification settings - Fork 11
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.
Since doing all these measurements generates a lot of heat that influences temperature measurements they are taken first, when the die is still comparatively cool due to the last deep sleep phase.
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).
![](miscellaneous/graph_explanation.png)
For every one of the measurements, battery, external voltage and temperature, these two values are used for the compensation. By using these values the measurements reported by ATTiny Daemon can be reasonably correct.
Let us assume that you have measured two values Vm1 and Vm2 and that the ATTiny has reported the values Vt1 and Vt2.. By viewing the values from the ATTiny 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 ATTiny to the actual values measured. Using this and the standard linear equation ax+b we can compute the coefficient a and the constant b. Writing this (even though it is simple) as a normal formula in github markdown is a futile exercise, so look it up.
Then you can use one of the many online calculators to do this, or use the following excel file that I prepared for your convenience: Calculate Coefficient and Constant