From da0a4d3d586f965a6431f544d64812809f5cc57f Mon Sep 17 00:00:00 2001 From: Jan Michel Date: Wed, 5 Aug 2015 18:11:33 +0200 Subject: [PATCH] further describing calibration values --- pt100/tempmeas.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pt100/tempmeas.c b/pt100/tempmeas.c index 72decf0..8a1b0c9 100644 --- a/pt100/tempmeas.c +++ b/pt100/tempmeas.c @@ -7,12 +7,15 @@ uint8_t measurement_step; //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; } @@ -24,12 +27,12 @@ int16_t adc_to_res(int16_t adc, uint8_t chan) { 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; } -- 2.43.0