//factors: gain_current has 2^29, ADC has 2^7 steps per mV
//hence shift by 36 necessary, 6 as part of multiplication by 1E6
+//gain_current is defined as 2^29/(Gain*Current)
+//offset_res is defined as difference of offset resistor to 100 Ohm
+//output is difference to 100 Ohm in mOhm
int16_t adc_to_res(int16_t adc, uint8_t chan) {
int32_t value;
value = (int32_t)adc * (uint32_t)calib_settings.gain_current;
- value >>= 14;
+ value /= 16384;
value *= 15625;
- value >>= 16;
+ value /= 65536;
value += calib_settings.offset_res[chan];
return (int16_t)value;
}
int32_t res_to_temp(int16_t res) {
int32_t result = -1;
int32_t t = (int32_t)res * 41919;
- result += t >> 14;
+ result += t / 16384;
t = (int32_t)res * res;
- t >>= 7;
+ t /= 128;
t *= 135;
- result += t >> 20;
+ result += t / 1048576;
return result;
}