Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
thermocouple.cpp
00001 /*! 00002 ***************************************************************************** 00003 @file: thermcouple.cpp 00004 00005 @brief: 00006 00007 @details: 00008 ----------------------------------------------------------------------------- 00009 Copyright (c) 2018, 2020 Analog Devices, Inc. All rights reserved. 00010 00011 This software is proprietary to Analog Devices, Inc. and its licensors. 00012 By using this software you agree to the terms of the associated 00013 Analog Devices Software License Agreement. 00014 00015 *****************************************************************************/ 00016 00017 #include <math.h> 00018 #include "thermocouple.h" 00019 00020 // http://srdata.nist.gov/its90/download/allcoeff.tab 00021 00022 Thermocouple::Thermocouple() {} 00023 Thermocouple::~Thermocouple() {} 00024 00025 float Thermocouple::lookup(const int32_t *lut, float voltage, uint16_t size, 00026 int16_t offset) 00027 { 00028 uint16_t first = 0; 00029 uint16_t last = size - 1; 00030 uint16_t middle = (first + last) / 2; 00031 int32_t integer_voltage = int32_t(voltage*1000); 00032 while (first <= last) { 00033 if (lut[middle] < integer_voltage) 00034 first = middle + 1; 00035 else if (lut[middle] == integer_voltage) { 00036 return static_cast<float>(middle + offset); 00037 } else 00038 last = middle - 1; 00039 00040 middle = (first + last) / 2; 00041 } 00042 if (first > last) 00043 return static_cast<float>(first+offset); 00044 00045 return 0; // should never get here 00046 } 00047 00048 float Thermocouple::convert(float voltage, 00049 const thermocouple_poly_subrange range[], const int n) 00050 { 00051 int range_id = 0; 00052 float temperature=0; 00053 for(range_id = 0 ; range_id<n; range_id++) { 00054 if(voltage > range[range_id].min_voltage_range 00055 && voltage <= range[range_id].max_voltage_range) 00056 break; 00057 } 00058 00059 for (int i = 0; i < range[range_id].n; i++) { 00060 temperature += (range[range_id].coef[i] * pow(10, 00061 range[range_id].power[i])) * pow(voltage, i); 00062 } 00063 return temperature; 00064 } 00065 00066 00067 00068 00069 const int Thermocouple_Type_B::inv_poly_size = 2; 00070 const Thermocouple::thermocouple_poly_subrange Thermocouple_Type_B::inv_poly[2] 00071 = { 00072 { 00073 0.000, 630.615,// characteristic curve for temp range between 0.000, and 630.615, 00074 {0.000000000000,-0.246508183460,0.590404211710,-0.132579316360,0.156682919010,-0.169445292400,0.629903470940,}, 00075 { 0, -3, -5, -8, -11, -14, -18,}, 00076 7 00077 }, 00078 { 00079 630.615, 1820.000,// characteristic curve for temp range between 630.615, and 1820.000, 00080 {-0.389381686210,0.285717474700,-0.848851047850,0.157852801640,-0.168353448640,0.111097940130,-0.445154310330,0.989756408210,-0.937913302890,}, 00081 { 1, -1, -4, -6, -9, -12, -16, -20, -24,}, 00082 9 00083 } 00084 }; 00085 00086 float Thermocouple_Type_B::convert_inv(float temp) 00087 { 00088 return Thermocouple::convert(temp, inv_poly, inv_poly_size); 00089 } 00090 00091 float Thermocouple_Type_B::lookup_inv(float temp) 00092 { 00093 #ifdef TYPE_B_LUT 00094 if((temp+lut_offset)>lut_size) 00095 return lut[lut_size-1]; 00096 else 00097 return lut[(uint16_t)temp+lut_offset]; 00098 #else 00099 /* NOT IMPLEMENTED */ 00100 return 0; 00101 #endif 00102 } 00103 const int Thermocouple_Type_B::poly_size = 2; 00104 const Thermocouple::thermocouple_poly_subrange Thermocouple_Type_B::poly[2] = { 00105 { 00106 0.291, 2.431, // characteristic curve for mV range between 0.291 and 2.431 00107 { 9.8423321, 6.9971500, -8.4765304, 1.0052644, -8.3345952, 4.5508542, -1.5523037, 2.9886750, -2.4742860,}, 00108 { 1, 2, 2, 3, 2, 2, 2, 1, 0,}, 00109 9 00110 }, 00111 { 00112 2.431, 13.820, // characteristic curve for mV range between 2.431 and 13.820 00113 { 2.1315071, 2.8510504, -5.2742887, 9.9160804, -1.2965303, 1.1195870, -6.0625199, 1.8661696, -2.4878585,}, 00114 { 2, 2, 1, 0, 0, -1, -3, -4, -6,}, 00115 9 00116 } 00117 }; 00118 00119 Thermocouple_Type_B::~Thermocouple_Type_B() 00120 { 00121 00122 } 00123 00124 float Thermocouple_Type_B::convert(float voltage) 00125 { 00126 return Thermocouple::convert(voltage, poly, poly_size); 00127 } 00128 00129 float Thermocouple_Type_B::lookup(float voltage) 00130 { 00131 #ifdef TYPE_B_LUT 00132 return Thermocouple::lookup(lut, voltage, lut_size, lut_offset); 00133 #else 00134 /* NOT IMPLEMENTED */ 00135 return 0; 00136 #endif 00137 } 00138 const int Thermocouple_Type_E::inv_poly_size = 2; 00139 const Thermocouple::thermocouple_poly_subrange Thermocouple_Type_E::inv_poly[2] 00140 = { 00141 { 00142 -270.000, 0.000,// characteristic curve for temp range between -270.000, and 0.000, 00143 {0.000000000000,0.586655087080,0.454109771240,-0.779980486860,-0.258001608430,-0.594525830570,-0.932140586670,-0.102876055340,-0.803701236210,-0.439794973910,-0.164147763550,-0.396736195160,-0.558273287210,-0.346578420130,}, 00144 { 0, -1, -4, -6, -7, -9, -11, -12, -15, -17, -19, -22, -25, -28,}, 00145 14 00146 }, 00147 { 00148 0.000, 1000.000,// characteristic curve for temp range between 0.000, and 1000.000, 00149 {0.000000000000,0.586655087100,0.450322755820,0.289084072120,-0.330568966520,0.650244032700,-0.191974955040,-0.125366004970,0.214892175690,-0.143880417820,0.359608994810,}, 00150 { 0, -1, -4, -7, -9, -12, -15, -17, -20, -23, -27,}, 00151 11 00152 } 00153 }; 00154 00155 float Thermocouple_Type_E::convert_inv(float temp) 00156 { 00157 return Thermocouple::convert(temp, inv_poly, inv_poly_size); 00158 } 00159 00160 float Thermocouple_Type_E::lookup_inv(float temp) 00161 { 00162 #ifdef TYPE_E_LUT 00163 if((temp+lut_offset)>lut_size) 00164 return lut[lut_size-1]; 00165 else 00166 return lut[(uint16_t)temp+lut_offset]; 00167 #else 00168 /* NOT IMPLEMENTED */ 00169 return 0; 00170 #endif 00171 } 00172 const int Thermocouple_Type_E::poly_size = 2; 00173 const Thermocouple::thermocouple_poly_subrange Thermocouple_Type_E::poly[2] = { 00174 { 00175 -8.825, 0.000, // characteristic curve for mV range between -8.825 and 0.000 00176 { 0.0000000, 1.6977288, -4.3514970, -1.5859697, -9.2502871, -2.6084314, -4.1360199, -3.4034030, -1.1564890, 0.0000000,}, 00177 { 0, 1, -1, -1, -2, -2, -3, -4, -5, 0,}, 00178 10 00179 }, 00180 { 00181 0.000, 76.373, // characteristic curve for mV range between 0.000 and 76.373 00182 { 0.0000000, 1.7057035, -2.3301759, 6.5435585, -7.3562749, -1.7896001, 8.4036165, -1.3735879, 1.0629823, -3.2447087,}, 00183 { 0, 1, -1, -3, -5, -6, -8, -9, -11, -14,}, 00184 10 00185 } 00186 }; 00187 00188 Thermocouple_Type_E::~Thermocouple_Type_E() 00189 { 00190 00191 } 00192 00193 float Thermocouple_Type_E::convert(float voltage) 00194 { 00195 return Thermocouple::convert(voltage, poly, poly_size); 00196 } 00197 00198 float Thermocouple_Type_E::lookup(float voltage) 00199 { 00200 #ifdef TYPE_E_LUT 00201 return Thermocouple::lookup(lut, voltage, lut_size, lut_offset); 00202 #else 00203 /* NOT IMPLEMENTED */ 00204 return 0; 00205 #endif 00206 } 00207 const int Thermocouple_Type_J::inv_poly_size = 2; 00208 const Thermocouple::thermocouple_poly_subrange Thermocouple_Type_J::inv_poly[2] 00209 = { 00210 { 00211 -210.000, 760.000,// characteristic curve for temp range between -210.000, and 760.000, 00212 {0.000000000000,0.503811878150,0.304758369300,-0.856810657200,0.132281952950,-0.170529583370,0.209480906970,-0.125383953360,0.156317256970,}, 00213 { 0, -1, -4, -7, -9, -12, -15, -18, -22,}, 00214 9 00215 }, 00216 { 00217 760.000, 1200.000,// characteristic curve for temp range between 760.000, and 1200.000, 00218 {0.296456256810,-0.149761277860,0.317871039240,-0.318476867010,0.157208190040,-0.306913690560,}, 00219 { 3, 1, -2, -5, -8, -12,}, 00220 6 00221 } 00222 }; 00223 00224 float Thermocouple_Type_J::convert_inv(float temp) 00225 { 00226 return Thermocouple::convert(temp, inv_poly, inv_poly_size); 00227 } 00228 00229 float Thermocouple_Type_J::lookup_inv(float temp) 00230 { 00231 #ifdef TYPE_J_LUT 00232 if((temp+lut_offset)>lut_size) 00233 return lut[lut_size-1]; 00234 else 00235 return lut[(uint16_t)temp+lut_offset]; 00236 #else 00237 /* NOT IMPLEMENTED */ 00238 return 0; 00239 #endif 00240 } 00241 const int Thermocouple_Type_J::poly_size = 3; 00242 const Thermocouple::thermocouple_poly_subrange Thermocouple_Type_J::poly[3] = { 00243 { 00244 -8.095, 0.000, // characteristic curve for mV range between -8.095 and 0.000 00245 { 0.0000000, 1.9528268, -1.2286185, -1.0752178, -5.9086933, -1.7256713, -2.8131513, -2.3963370, -8.3823321,}, 00246 { 0, 1, 0, 0, -1, -1, -2, -3, -5,}, 00247 9 00248 }, 00249 { 00250 0.000, 42.919, // characteristic curve for mV range between 0.000 and 42.919 00251 { 0.000000, 1.978425, -2.001204, 1.036969, -2.549687, 3.585153, -5.344285, 5.099890, 0.000000,}, 00252 { 0, 1, -1, -2, -4, -6, -8, -10, 0,}, 00253 9 00254 }, 00255 { 00256 42.919, 69.553, // characteristic curve for mV range between 42.919 and 69.553 00257 {-3.11358187, 3.00543684,-9.94773230, 1.70276630,-1.43033468, 4.73886084, 0.00000000, 0.00000000, 0.00000000,}, 00258 { 3, 2, 0, -1, -3, -6, 0, 0, 0,}, 00259 9 00260 } 00261 }; 00262 00263 Thermocouple_Type_J::~Thermocouple_Type_J() 00264 { 00265 00266 } 00267 00268 float Thermocouple_Type_J::convert(float voltage) 00269 { 00270 return Thermocouple::convert(voltage, poly, poly_size); 00271 } 00272 00273 float Thermocouple_Type_J::lookup(float voltage) 00274 { 00275 #ifdef TYPE_J_LUT 00276 return Thermocouple::lookup(lut, voltage, lut_size, lut_offset); 00277 #else 00278 /* NOT IMPLEMENTED */ 00279 return 0; 00280 #endif 00281 } 00282 const int Thermocouple_Type_K::inv_poly_size = 2; 00283 const Thermocouple::thermocouple_poly_subrange Thermocouple_Type_K::inv_poly[2] 00284 = { 00285 { 00286 -270.000, 0.000,// characteristic curve for temp range between -270.000, and 0.000, 00287 {0.000000000000,0.394501280250,0.236223735980,-0.328589067840,-0.499048287770,-0.675090591730,-0.574103274280,-0.310888728940,-0.104516093650,-0.198892668780,-0.163226974860,}, 00288 { 0, -1, -4, -6, -8, -10, -12, -14, -16, -19, -22,}, 00289 11 00290 }, 00291 { 00292 0.000, 1372.000,// characteristic curve for temp range between 0.000, and 1372.000, 00293 {-0.176004136860,0.389212049750,0.185587700320,-0.994575928740,0.318409457190,-0.560728448890,0.560750590590,-0.320207200030,0.971511471520,-0.121047212750,}, 00294 { -1, -1, -4, -7, -9, -12, -15, -18, -22, -25,}, 00295 10 00296 } 00297 }; 00298 00299 float Thermocouple_Type_K::convert_inv(float temp) 00300 { 00301 return Thermocouple::convert(temp, inv_poly, inv_poly_size); 00302 } 00303 00304 float Thermocouple_Type_K::lookup_inv(float temp) 00305 { 00306 #ifdef TYPE_K_LUT 00307 if((temp+lut_offset)>lut_size) 00308 return lut[lut_size-1]; 00309 else 00310 return lut[(uint16_t)temp+lut_offset]; 00311 #else 00312 /* NOT IMPLEMENTED */ 00313 return 0; 00314 #endif 00315 } 00316 const int Thermocouple_Type_K::poly_size = 3; 00317 const Thermocouple::thermocouple_poly_subrange Thermocouple_Type_K::poly[3] = { 00318 { 00319 -5.891, 0.000, // characteristic curve for mV range between -5.891 and 0.000 00320 { 0.0000000, 2.5173462, -1.1662878, -1.0833638, -8.9773540, -3.7342377, -8.6632643, -1.0450598, -5.1920577, 0.0000000,}, 00321 { 0, 1, 0, 0, -1, -1, -2, -2, -4, 0,}, 00322 10 00323 }, 00324 { 00325 0.000, 20.644, // characteristic curve for mV range between 0.000 and 20.644 00326 { 0.000000, 2.508355, 7.860106, -2.503131, 8.315270, -1.228034, 9.804036, -4.413030, 1.057734, -1.052755,}, 00327 { 0, 1, -2, -1, -2, -2, -4, -5, -6, -8,}, 00328 10 00329 }, 00330 { 00331 20.644, 54.886, // characteristic curve for mV range between 20.644 and 54.886 00332 { -1.318058, 4.830222, -1.646031, 5.464731, -9.650715, 8.802193, -3.110810, 0.000000, 0.000000, 0.000000,}, 00333 { 2, 1, 0, -2, -4, -6, -8, 0, 0, 0,}, 00334 10 00335 } 00336 }; 00337 00338 Thermocouple_Type_K::~Thermocouple_Type_K() 00339 { 00340 00341 } 00342 00343 float Thermocouple_Type_K::convert(float voltage) 00344 { 00345 return Thermocouple::convert(voltage, poly, poly_size); 00346 } 00347 00348 float Thermocouple_Type_K::lookup(float voltage) 00349 { 00350 #ifdef TYPE_K_LUT 00351 return Thermocouple::lookup(lut, voltage, lut_size, lut_offset); 00352 #else 00353 /* NOT IMPLEMENTED */ 00354 return 0; 00355 #endif 00356 } 00357 const int Thermocouple_Type_N::inv_poly_size = 2; 00358 const Thermocouple::thermocouple_poly_subrange Thermocouple_Type_N::inv_poly[2] 00359 = { 00360 { 00361 -270.000, 0.000,// characteristic curve for temp range between -270.000, and 0.000, 00362 {0.000000000000,0.261591059620,0.109574842280,-0.938411115540,-0.464120397590,-0.263033577160,-0.226534380030,-0.760893007910,-0.934196678350,}, 00363 { 0, -1, -4, -7, -10, -11, -13, -16, -19,}, 00364 9 00365 }, 00366 { 00367 0.000, 1300.000,// characteristic curve for temp range between 0.000, and 1300.000, 00368 {0.000000000000,0.259293946010,0.157101418800,0.438256272370,-0.252611697940,0.643118193390,-0.100634715190,0.997453389920,-0.608632456070,0.208492293390,-0.306821961510,}, 00369 { 0, -1, -4, -7, -9, -12, -14, -18, -21, -24, -28,}, 00370 11 00371 } 00372 }; 00373 00374 float Thermocouple_Type_N::convert_inv(float temp) 00375 { 00376 return Thermocouple::convert(temp, inv_poly, inv_poly_size); 00377 } 00378 00379 float Thermocouple_Type_N::lookup_inv(float temp) 00380 { 00381 #ifdef TYPE_N_LUT 00382 if((temp+lut_offset)>lut_size) 00383 return lut[lut_size-1]; 00384 else 00385 return lut[(uint16_t)temp+lut_offset]; 00386 #else 00387 /* NOT IMPLEMENTED */ 00388 return 0; 00389 #endif 00390 } 00391 const int Thermocouple_Type_N::poly_size = 3; 00392 const Thermocouple::thermocouple_poly_subrange Thermocouple_Type_N::poly[3] = { 00393 { 00394 -3.990, 0.000, // characteristic curve for mV range between -3.990 and 0.000 00395 { 0.0000000, 3.8436847, 1.1010485, 5.2229312, 7.2060525, 5.8488586, 2.7754916, 7.7075166, 1.1582665, 7.3138868,}, 00396 { 0, 1, 0, 0, 0, 0, 0, -1, -1, -3,}, 00397 10 00398 }, 00399 { 00400 0.000, 20.613, // characteristic curve for mV range between 0.000 and 20.613 00401 { 0.00000, 3.86896, -1.08267, 4.70205, -2.12169, -1.17272, 5.39280, -7.98156, 0.00000, 0.00000,}, 00402 { 0, 1, 0, -2, -6, -4, -6, -8, 0, 0,}, 00403 10 00404 }, 00405 { 00406 20.613, 47.513, // characteristic curve for mV range between 20.613 and 47.513 00407 { 1.972485, 3.300943, -3.915159, 9.855391, -1.274371, 7.767022, 0.000000, 0.000000, 0.000000, 0.000000,}, 00408 { 1, 1, -1, -3, -4, -7, 0, 0, 0, 0,}, 00409 10 00410 } 00411 }; 00412 00413 Thermocouple_Type_N::~Thermocouple_Type_N() 00414 { 00415 00416 } 00417 00418 float Thermocouple_Type_N::convert(float voltage) 00419 { 00420 return Thermocouple::convert(voltage, poly, poly_size); 00421 } 00422 00423 float Thermocouple_Type_N::lookup(float voltage) 00424 { 00425 #ifdef TYPE_N_LUT 00426 return Thermocouple::lookup(lut, voltage, lut_size, lut_offset); 00427 #else 00428 /* NOT IMPLEMENTED */ 00429 return 0; 00430 #endif 00431 } 00432 const int Thermocouple_Type_R::inv_poly_size = 3; 00433 const Thermocouple::thermocouple_poly_subrange Thermocouple_Type_R::inv_poly[3] 00434 = { 00435 { 00436 -50.000, 1064.180,// characteristic curve for temp range between -50.000, and 1064.180, 00437 {0.000000000000,0.528961729765,0.139166589782,-0.238855693017,0.356916001063,-0.462347666298,0.500777441034,-0.373105886191,0.157716482367,-0.281038625251,}, 00438 { 0, -2, -4, -7, -10, -13, -16, -19, -22, -26,}, 00439 10 00440 }, 00441 { 00442 1064.180, 1664.500,// characteristic curve for temp range between 1064.180, and 1664.500, 00443 {0.295157925316,-0.252061251332,0.159564501865,-0.764085947576,0.205305291024,-0.293359668173,}, 00444 { 1, -2, -4, -8, -11, -15,}, 00445 6 00446 }, 00447 { 00448 1664.500, 1768.100,// characteristic curve for temp range between 1664.500, and 1768.100, 00449 {0.152232118209,-0.268819888545,0.171280280471,-0.345895706453,-0.934633971046,}, 00450 { 3, 0, -3, -7, -14,}, 00451 5 00452 } 00453 }; 00454 00455 float Thermocouple_Type_R::convert_inv(float temp) 00456 { 00457 return Thermocouple::convert(temp, inv_poly, inv_poly_size); 00458 } 00459 00460 float Thermocouple_Type_R::lookup_inv(float temp) 00461 { 00462 #ifdef TYPE_R_LUT 00463 if((temp+lut_offset)>lut_size) 00464 return lut[lut_size-1]; 00465 else 00466 return lut[(uint16_t)temp+lut_offset]; 00467 #else 00468 /* NOT IMPLEMENTED */ 00469 return 0; 00470 #endif 00471 } 00472 const int Thermocouple_Type_R::poly_size = 4; 00473 const Thermocouple::thermocouple_poly_subrange Thermocouple_Type_R::poly[4] = { 00474 { 00475 -0.226, 1.923, // characteristic curve for mV range between -0.226 and 1.923 00476 { 0.0000000, 1.8891380, -9.3835290, 1.3068619, -2.2703580, 3.5145659, -3.8953900, 2.8239471, -1.2607281, 3.1353611, -3.3187769,}, 00477 { 0, 2, 1, 2, 2, 2, 2, 2, 2, 1, 0,}, 00478 11 00479 }, 00480 { 00481 1.923, 13.228, // characteristic curve for mV range between 1.923 and 13.228 00482 {1.334584505,1.472644573,-1.844024844,4.031129726,-6.249428360,6.468412046,-4.458750426,1.994710149,-5.313401790,6.481976217,0.000000000,}, 00483 { 1, 2, 1, 0, -1, -2, -3, -4, -6, -8, 0,}, 00484 11 00485 }, 00486 { 00487 11.361, 19.739, // characteristic curve for mV range between 11.361 and 19.739 00488 {-8.199599416,1.553962042,-8.342197663,4.279433549,-1.191577910,1.492290091,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,}, 00489 { 1, 2, 0, -1, -2, -4, 0, 0, 0, 0, 0,}, 00490 11 00491 }, 00492 { 00493 19.739, 21.103, // characteristic curve for mV range between 19.739 and 21.103 00494 {3.406177836,-7.023729171,5.582903813,-1.952394635,2.560740231,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,}, 00495 { 4, 3, 2, 1, -1, 0, 0, 0, 0, 0, 0,}, 00496 11 00497 } 00498 }; 00499 00500 Thermocouple_Type_R::~Thermocouple_Type_R() 00501 { 00502 00503 } 00504 00505 float Thermocouple_Type_R::convert(float voltage) 00506 { 00507 return Thermocouple::convert(voltage, poly, poly_size); 00508 } 00509 00510 float Thermocouple_Type_R::lookup(float voltage) 00511 { 00512 #ifdef TYPE_R_LUT 00513 return Thermocouple::lookup(lut, voltage, lut_size, lut_offset); 00514 #else 00515 /* NOT IMPLEMENTED */ 00516 return 0; 00517 #endif 00518 } 00519 const int Thermocouple_Type_S::inv_poly_size = 3; 00520 const Thermocouple::thermocouple_poly_subrange Thermocouple_Type_S::inv_poly[3] 00521 = { 00522 { 00523 -50.000, 1064.180,// characteristic curve for temp range between -50.000, and 1064.180, 00524 {0.000000000000,0.540313308631,0.125934289740,-0.232477968689,0.322028823036,-0.331465196389,0.255744251786,-0.125068871393,0.271443176145,}, 00525 { 0, -2, -4, -7, -10, -13, -16, -19, -23,}, 00526 9 00527 }, 00528 { 00529 1064.180, 1664.500,// characteristic curve for temp range between 1064.180, and 1664.500, 00530 {0.132900444085,0.334509311344,0.654805192818,-0.164856259209,0.129989605174,}, 00531 { 1, -2, -5, -8, -13,}, 00532 5 00533 }, 00534 { 00535 1664.500, 1768.100,// characteristic curve for temp range between 1664.500, and 1768.100, 00536 {0.146628232636,-0.258430516752,0.163693574641,-0.330439046987,-0.943223690612,}, 00537 { 3, 0, -3, -7, -14,}, 00538 5 00539 } 00540 }; 00541 00542 float Thermocouple_Type_S::convert_inv(float temp) 00543 { 00544 return Thermocouple::convert(temp, inv_poly, inv_poly_size); 00545 } 00546 00547 float Thermocouple_Type_S::lookup_inv(float temp) 00548 { 00549 #ifdef TYPE_S_LUT 00550 if((temp+lut_offset)>lut_size) 00551 return lut[lut_size-1]; 00552 else 00553 return lut[(uint16_t)temp+lut_offset]; 00554 #else 00555 /* NOT IMPLEMENTED */ 00556 return 0; 00557 #endif 00558 } 00559 const int Thermocouple_Type_S::poly_size = 4; 00560 const Thermocouple::thermocouple_poly_subrange Thermocouple_Type_S::poly[4] = { 00561 { 00562 -0.235, 1.874, // characteristic curve for mV range between -0.235 and 1.874 00563 { 0.00000000, 1.84949460,-8.00504062, 1.02237430,-1.52248592, 1.88821343,-1.59085941, 8.23027880,-2.34181944, 2.79786260,}, 00564 { 0, 2, 1, 2, 2, 2, 2, 1, 1, 0,}, 00565 10 00566 }, 00567 { 00568 1.874, 11.950, // characteristic curve for mV range between 1.874 and 11.950 00569 {1.291507177,1.466298863,-1.534713402,3.145945973,-4.163257839,3.187963771,-1.291637500,2.183475087,-1.447379511,8.211272125,}, 00570 { 1, 2, 1, 0, -1, -2, -3, -5, -7, -9,}, 00571 10 00572 }, 00573 { 00574 10.332, 17.536, // characteristic curve for mV range between 10.332 and 17.536 00575 {-8.087801117,1.621573104,-8.536869453,4.719686976,-1.441693666,2.081618890,0.000000000,0.000000000,0.000000000,0.000000000,}, 00576 { 1, 2, 0, -1, -2, -4, 0, 0, 0, 0,}, 00577 10 00578 }, 00579 { 00580 17.536, 18.693, // characteristic curve for mV range between 17.536 and 18.693 00581 {5.333875126,-1.235892298,1.092657613,-4.265693686,6.247205420,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,}, 00582 { 4, 4, 3, 1, -1, 0, 0, 0, 0, 0,}, 00583 10 00584 } 00585 }; 00586 00587 Thermocouple_Type_S::~Thermocouple_Type_S() 00588 { 00589 00590 } 00591 00592 float Thermocouple_Type_S::convert(float voltage) 00593 { 00594 return Thermocouple::convert(voltage, poly, poly_size); 00595 } 00596 00597 float Thermocouple_Type_S::lookup(float voltage) 00598 { 00599 #ifdef TYPE_S_LUT 00600 return Thermocouple::lookup(lut, voltage, lut_size, lut_offset); 00601 #else 00602 /* NOT IMPLEMENTED */ 00603 return 0; 00604 #endif 00605 } 00606 const int Thermocouple_Type_T::inv_poly_size = 2; 00607 const Thermocouple::thermocouple_poly_subrange Thermocouple_Type_T::inv_poly[2] 00608 = { 00609 { 00610 -270.000, 0.000,// characteristic curve for temp range between -270.000, and 0.000, 00611 {0.000000000000,0.387481063640,0.441944343470,0.118443231050,0.200329735540,0.901380195590,0.226511565930,0.360711542050,0.384939398830,0.282135219250,0.142515947790,0.487686622860,0.107955392700,0.139450270620,0.797951539270,}, 00612 { 0, -1, -4, -6, -7, -9, -10, -12, -14, -16, -18, -21, -23, -26, -30,}, 00613 15 00614 }, 00615 { 00616 0.000, 400.000,// characteristic curve for temp range between 0.000, and 400.000, 00617 {0.000000000000,0.387481063640,0.332922278800,0.206182434040,-0.218822568460,0.109968809280,-0.308157587720,0.454791352900,-0.275129016730,}, 00618 { 0, -1, -4, -6, -8, -10, -13, -16, -19,}, 00619 9 00620 } 00621 }; 00622 00623 float Thermocouple_Type_T::convert_inv(float temp) 00624 { 00625 return Thermocouple::convert(temp, inv_poly, inv_poly_size); 00626 } 00627 00628 float Thermocouple_Type_T::lookup_inv(float temp) 00629 { 00630 #ifdef TYPE_T_LUT 00631 if((temp+lut_offset)>lut_size) 00632 return lut[lut_size-1]; 00633 else 00634 return lut[(uint16_t)temp+lut_offset]; 00635 #else 00636 /* NOT IMPLEMENTED */ 00637 return 0; 00638 #endif 00639 } 00640 const int Thermocouple_Type_T::poly_size = 2; 00641 const Thermocouple::thermocouple_poly_subrange Thermocouple_Type_T::poly[2] = { 00642 { 00643 -5.603, 0.000, // characteristic curve for mV range between -5.603 and 0.000 00644 { 0.0000000, 2.5949192, -2.1316967, 7.9018692, 4.2527777, 1.3304473, 2.0241446, 1.2668171,}, 00645 { 0, 1, -1, -1, -1, -1, -2, -3,}, 00646 8 00647 }, 00648 { 00649 0.000, 20.872, // characteristic curve for mV range between 0.000 and 20.872 00650 { 0.000000, 2.592800, -7.602961, 4.637791, -2.165394, 6.048144, -7.293422, 0.000000,}, 00651 { 0, 1, -1, -2, -3, -5, -7, 0,}, 00652 8 00653 } 00654 }; 00655 00656 Thermocouple_Type_T::~Thermocouple_Type_T() 00657 { 00658 00659 } 00660 00661 float Thermocouple_Type_T::convert(float voltage) 00662 { 00663 return Thermocouple::convert(voltage, poly, poly_size); 00664 } 00665 00666 float Thermocouple_Type_T::lookup(float voltage) 00667 { 00668 #ifdef TYPE_T_LUT 00669 return Thermocouple::lookup(lut, voltage, lut_size, lut_offset); 00670 #else 00671 /* NOT IMPLEMENTED */ 00672 return 0; 00673 #endif 00674 }
Generated on Thu Jul 21 2022 10:03:15 by
1.7.2