diff --git a/content/zettels/temperature_sensors.md b/content/zettels/temperature_sensors.md index 8c6ff9a..9268103 100644 --- a/content/zettels/temperature_sensors.md +++ b/content/zettels/temperature_sensors.md @@ -220,41 +220,131 @@ Values for A, B, C and D are depending on the exact model (summarized in [Table %% Pt100 (3850 ppm/K) R0 = 100; % [Ohm] -A = 3.9083e-3; -B = -5.775e-7; -C = -4.183e-12; +A = 3.9083e-3; % [degC^-1] +B = -5.775e-7; % [degC^-2] +C = -4.183e-12; % [degC^-4] T1 = -200:0; % [degC] T2 = 0:850; % [degC] T = [T1,T2]; % [degC] R = [R0*(1 + A*T1 + B*T1.^2 + C*(T1-100).*T1.^3), R0*(1 + A*T2 + B*T2.^2)]; % [Ohm] - -figure; -plot(T, R) -xlabel('Temperature [${}^oC$]'); -ylabel('Resistance [$\Omega$]') ``` + + +{{< figure src="/ox-hugo/temperature_sensor_pt100_curve.png" caption="Figure 7: Resistance as a function of the temperature for a Pt100" >}} + For temperatures above 0 degrees, the temperature \\(T\\) can be easily computed from the measured resistance \\(R\\) using: \\[ T = \frac{-A + \sqrt{A^2 - 4 B ( 1 - R/R\_0 )}}{2 B} \\] For temperatures below 0 degrees, the equation is harder to solve analytically, and a lookup table is more appropriate. +Let's compare the temperature given by a Loopup table and the temperature given by the analytical formula in two cases: + +- linear interpolation with one point every degree +- cubic interpolation with one point every 10 degrees + +The error is less than 0.1mK over the full range, validating the use of a lookup table to convert the resistance to temperature ([Figure 8](#figure--fig:temperature-sensor-lut-errors)). + ```matlab -%% Compute the temperature as a function of the resistance -R_meas_1 = 18:100; -R_meas_2 = 100:390; +%% "Perfect" temperature and resistance +R0 = 100; % [Ohm] +A = 3.9083e-3; % [degC^-1] +B = -5.775e-7; % [degC^-2] +C = -4.183e-12; % [degC^-4] +T1 = -200:0.1:0; % [degC] +T2 = 0.1:0.1:850; % [degC] +T_true = [T1,T2]; % [degC] +R_true = [R0*(1 + A*T1 + B*T1.^2 + C*(T1-100).*T1.^3), R0*(1 + A*T2 + B*T2.^2)]; % [Ohm] -T_meas = [(-A + sqrt(A^2 - 4*B*(1 - R_meas_2/R0)))/(2*B)]; +%% Lookup table for Pt100 (3850 ppm/K) - Linear +dT = 1; +interp_method = 'linear'; -figure; -plot(R_meas_2, T_meas) -xlabel('Resistance [$\Omega$]') -ylabel('Temperature [${}^oC$]'); +T1 = -200:dT:0; % [degC] +T2 = dT:dT:850; % [degC] +T_lut_linear = [T1,T2]; % [degC] +R_lut_linear = [R0*(1 + A*T1 + B*T1.^2 + C*(T1-100).*T1.^3), R0*(1 + A*T2 + B*T2.^2)]; % [Ohm] + +T_meas_linear = interp1(R_lut_linear,T_lut_linear,R_true,interp_method); % interpolate the resistance using the LUT to find the corresponding temperature + +%% Lookup table for Pt100 (3850 ppm/K) - Makima +dT = 10; +interp_method = 'makima'; + +T1 = -200:dT:0; % [degC] +T2 = dT:dT:850; % [degC] +T_lut_makima = [T1,T2]; % [degC] +R_lut_makima = [R0*(1 + A*T1 + B*T1.^2 + C*(T1-100).*T1.^3), R0*(1 + A*T2 + B*T2.^2)]; % [Ohm] + +T_meas_makima = interp1(R_lut_makima,T_lut_makima,R_true,interp_method); % interpolate the resistance using the LUT to find the corresponding temperature ``` + + +{{< figure src="/ox-hugo/temperature_sensor_lut_errors.png" caption="Figure 8: Interpolation errors in two cases when using a LUT for a Pt100" >}} + + +### NTC thermistor {#ntc-thermistor} + +The resistance of the NTC thermistor as a function of the temperature can be well approximated with the following equation: +\\[ R\_t = R\_{25} \cdot e^{A + B/T + C/T^2 + D/T^3 \\] +where \\(T\\) is the temperature in kelvins, \\(R\_{25}\\) the nominal resistance at \\(25^oC\\), \\(A\\), \\(B\\), \\(C\\) and \\(D\\) are coefficients which are specific for a given thermistor. + +Typically, coefficients A, B, C and D are varying with temperature as shown in [Table 2](#table--tab:temperature-sensor-ntc-coefs). + + +