Value Conversion
The ICOtronic library streams the data as unsigned 16-bit integer values. To get the actual measured physical values,
we go through two conversion steps.
Step 1: 16-bit ADC Value to Voltage
The streamed uint16 is a direct linear map from
an ADC value of \(0\) up to \({2^{16} - 1}\) to
a voltage value from \(0\) up to \(V_{ref}\) Volt.
This means we can reverse the conversion by inverting the linear map.
We will define the coefficients \(k_1\) and \(d_1\) as the factor and offset of going from bit-value to voltage respectively.
As the linear map is direct and without an offset, we can set:
The first conversion only depends on the used reference voltage.
For example, if we assume a reference voltage \(V_{ref}\) of 3.3 Volt then an ADC value of \(2^{15}\) (roughly half of \({2^{16} - 1}\)) would translate to about 1.65 Volt:
For the same reference voltage the maximum value of \(2^{16} - 1\) would translate to exactly 3.3 Volt:
Step 2: Voltage to Physical Value
Each used sensor has a datasheet and associated linear coefficients to get from voltage output to the measured physical values.
We will define \(k_2\) and \(d_2\) as the linear coefficients of going from voltage to physical measurement.
We use \(p_{min}\)/\(p_{max}\) do denote the minimum/maximum physical value (e.g. \(℃\), multiples of \(g_0\), Watt) and \(U_{min}\)/\(U_{max}\) to denote the minimum/maximum voltage value.
Please note, that we assumed \(U_{min}\) is \(0~V\) and \(U_{max}\) is \(V_{ref}\) in step 1. If that is not the case, the calculation of step 1 is false. The calculation in step 2 does (at least in theory) also take negative minimum voltage values in account.
For example, let us assume that we map a voltage of 0 V up to 3.3 V from a physical value of \(-100 · g_0\) up to a value of \(100 · g_0\). Here a value of 1.65 Volt should map to \(0 · g_0\):