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