Library to support temperature sensor conversions and lookups
thermocouple.h@2:bcfa5a2f21c9, 2021-03-19 (annotated)
- Committer:
- mahphalke
- Date:
- Fri Mar 19 08:09:19 2021 +0000
- Revision:
- 2:bcfa5a2f21c9
- Parent:
- 1:f65f6fadda5d
Fixed line ending issues
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mahphalke | 1:f65f6fadda5d | 1 | /*! |
mahphalke | 1:f65f6fadda5d | 2 | ***************************************************************************** |
mahphalke | 1:f65f6fadda5d | 3 | @file: thermocouple.h |
mahphalke | 1:f65f6fadda5d | 4 | |
mahphalke | 1:f65f6fadda5d | 5 | @brief: |
mahphalke | 1:f65f6fadda5d | 6 | |
mahphalke | 1:f65f6fadda5d | 7 | @details: |
mahphalke | 1:f65f6fadda5d | 8 | ----------------------------------------------------------------------------- |
mahphalke | 1:f65f6fadda5d | 9 | Copyright (c) 2018, 2020 Analog Devices, Inc. All rights reserved. |
mahphalke | 1:f65f6fadda5d | 10 | |
mahphalke | 1:f65f6fadda5d | 11 | This software is proprietary to Analog Devices, Inc. and its licensors. |
mahphalke | 1:f65f6fadda5d | 12 | By using this software you agree to the terms of the associated |
mahphalke | 1:f65f6fadda5d | 13 | Analog Devices Software License Agreement. |
mahphalke | 1:f65f6fadda5d | 14 | |
mahphalke | 1:f65f6fadda5d | 15 | *****************************************************************************/ |
mahphalke | 1:f65f6fadda5d | 16 | |
mahphalke | 1:f65f6fadda5d | 17 | #include "stdint.h" |
mahphalke | 1:f65f6fadda5d | 18 | |
mahphalke | 1:f65f6fadda5d | 19 | #ifndef _THERMOCOUPLE_H_ |
mahphalke | 1:f65f6fadda5d | 20 | #define _THERMOCOUPLE_H_ |
mahphalke | 1:f65f6fadda5d | 21 | |
mahphalke | 1:f65f6fadda5d | 22 | #define DEFINE_LOOKUP_TABLES |
mahphalke | 1:f65f6fadda5d | 23 | #ifdef DEFINE_LOOKUP_TABLES |
mahphalke | 1:f65f6fadda5d | 24 | #define TYPE_B_LUT |
mahphalke | 1:f65f6fadda5d | 25 | #define TYPE_E_LUT |
mahphalke | 1:f65f6fadda5d | 26 | #define TYPE_J_LUT |
mahphalke | 1:f65f6fadda5d | 27 | #define TYPE_K_LUT |
mahphalke | 1:f65f6fadda5d | 28 | #define TYPE_N_LUT |
mahphalke | 1:f65f6fadda5d | 29 | #define TYPE_R_LUT |
mahphalke | 1:f65f6fadda5d | 30 | #define TYPE_S_LUT |
mahphalke | 1:f65f6fadda5d | 31 | #define TYPE_T_LUT |
mahphalke | 1:f65f6fadda5d | 32 | #endif |
mahphalke | 1:f65f6fadda5d | 33 | |
mahphalke | 1:f65f6fadda5d | 34 | class Thermocouple |
mahphalke | 1:f65f6fadda5d | 35 | { |
mahphalke | 1:f65f6fadda5d | 36 | private: |
mahphalke | 1:f65f6fadda5d | 37 | |
mahphalke | 1:f65f6fadda5d | 38 | public: |
mahphalke | 1:f65f6fadda5d | 39 | typedef struct { |
mahphalke | 1:f65f6fadda5d | 40 | float min_voltage_range; |
mahphalke | 1:f65f6fadda5d | 41 | float max_voltage_range; |
mahphalke | 1:f65f6fadda5d | 42 | float coef[16]; |
mahphalke | 1:f65f6fadda5d | 43 | float power[16]; |
mahphalke | 1:f65f6fadda5d | 44 | int n; |
mahphalke | 1:f65f6fadda5d | 45 | } thermocouple_poly_subrange; |
mahphalke | 1:f65f6fadda5d | 46 | Thermocouple(); |
mahphalke | 1:f65f6fadda5d | 47 | virtual ~Thermocouple(); |
mahphalke | 1:f65f6fadda5d | 48 | static float convert(float voltage, const thermocouple_poly_subrange range[], |
mahphalke | 1:f65f6fadda5d | 49 | const int n); |
mahphalke | 1:f65f6fadda5d | 50 | static float lookup(const int32_t *lut, float voltage,uint16_t size, |
mahphalke | 1:f65f6fadda5d | 51 | int16_t offset); |
mahphalke | 1:f65f6fadda5d | 52 | virtual float convert(float voltage) = 0; |
mahphalke | 1:f65f6fadda5d | 53 | virtual float convert_inv(float temp) = 0; |
mahphalke | 1:f65f6fadda5d | 54 | virtual float lookup(float voltage) = 0; |
mahphalke | 1:f65f6fadda5d | 55 | virtual float lookup_inv(float temp) = 0; |
mahphalke | 1:f65f6fadda5d | 56 | |
mahphalke | 1:f65f6fadda5d | 57 | }; |
mahphalke | 1:f65f6fadda5d | 58 | |
mahphalke | 1:f65f6fadda5d | 59 | |
mahphalke | 1:f65f6fadda5d | 60 | |
mahphalke | 1:f65f6fadda5d | 61 | |
mahphalke | 1:f65f6fadda5d | 62 | class Thermocouple_Type_B : public Thermocouple |
mahphalke | 1:f65f6fadda5d | 63 | { |
mahphalke | 1:f65f6fadda5d | 64 | public: |
mahphalke | 1:f65f6fadda5d | 65 | ~Thermocouple_Type_B(); |
mahphalke | 1:f65f6fadda5d | 66 | static const thermocouple_poly_subrange inv_poly[2]; |
mahphalke | 1:f65f6fadda5d | 67 | static const int inv_poly_size; |
mahphalke | 1:f65f6fadda5d | 68 | float convert_inv(float temp); |
mahphalke | 1:f65f6fadda5d | 69 | |
mahphalke | 1:f65f6fadda5d | 70 | static const thermocouple_poly_subrange poly[2]; |
mahphalke | 1:f65f6fadda5d | 71 | static const int poly_size; |
mahphalke | 1:f65f6fadda5d | 72 | float convert(float voltage); |
mahphalke | 1:f65f6fadda5d | 73 | #ifdef TYPE_B_LUT |
mahphalke | 1:f65f6fadda5d | 74 | static const int32_t lut[]; |
mahphalke | 1:f65f6fadda5d | 75 | static const int16_t lut_offset; |
mahphalke | 1:f65f6fadda5d | 76 | static const uint16_t lut_size; |
mahphalke | 1:f65f6fadda5d | 77 | float lookup(float voltage); |
mahphalke | 1:f65f6fadda5d | 78 | float lookup_inv(float temp); |
mahphalke | 1:f65f6fadda5d | 79 | #endif |
mahphalke | 1:f65f6fadda5d | 80 | }; |
mahphalke | 1:f65f6fadda5d | 81 | |
mahphalke | 1:f65f6fadda5d | 82 | |
mahphalke | 1:f65f6fadda5d | 83 | class Thermocouple_Type_E : public Thermocouple |
mahphalke | 1:f65f6fadda5d | 84 | { |
mahphalke | 1:f65f6fadda5d | 85 | public: |
mahphalke | 1:f65f6fadda5d | 86 | ~Thermocouple_Type_E(); |
mahphalke | 1:f65f6fadda5d | 87 | static const thermocouple_poly_subrange inv_poly[2]; |
mahphalke | 1:f65f6fadda5d | 88 | static const int inv_poly_size; |
mahphalke | 1:f65f6fadda5d | 89 | float convert_inv(float temp); |
mahphalke | 1:f65f6fadda5d | 90 | |
mahphalke | 1:f65f6fadda5d | 91 | static const thermocouple_poly_subrange poly[2]; |
mahphalke | 1:f65f6fadda5d | 92 | static const int poly_size; |
mahphalke | 1:f65f6fadda5d | 93 | float convert(float voltage); |
mahphalke | 1:f65f6fadda5d | 94 | #ifdef TYPE_E_LUT |
mahphalke | 1:f65f6fadda5d | 95 | static const int32_t lut[]; |
mahphalke | 1:f65f6fadda5d | 96 | static const int16_t lut_offset; |
mahphalke | 1:f65f6fadda5d | 97 | static const uint16_t lut_size; |
mahphalke | 1:f65f6fadda5d | 98 | float lookup(float voltage); |
mahphalke | 1:f65f6fadda5d | 99 | float lookup_inv(float temp); |
mahphalke | 1:f65f6fadda5d | 100 | #endif |
mahphalke | 1:f65f6fadda5d | 101 | }; |
mahphalke | 1:f65f6fadda5d | 102 | |
mahphalke | 1:f65f6fadda5d | 103 | |
mahphalke | 1:f65f6fadda5d | 104 | class Thermocouple_Type_J : public Thermocouple |
mahphalke | 1:f65f6fadda5d | 105 | { |
mahphalke | 1:f65f6fadda5d | 106 | public: |
mahphalke | 1:f65f6fadda5d | 107 | ~Thermocouple_Type_J(); |
mahphalke | 1:f65f6fadda5d | 108 | static const thermocouple_poly_subrange inv_poly[2]; |
mahphalke | 1:f65f6fadda5d | 109 | static const int inv_poly_size; |
mahphalke | 1:f65f6fadda5d | 110 | float convert_inv(float temp); |
mahphalke | 1:f65f6fadda5d | 111 | |
mahphalke | 1:f65f6fadda5d | 112 | static const thermocouple_poly_subrange poly[3]; |
mahphalke | 1:f65f6fadda5d | 113 | static const int poly_size; |
mahphalke | 1:f65f6fadda5d | 114 | float convert(float voltage); |
mahphalke | 1:f65f6fadda5d | 115 | #ifdef TYPE_J_LUT |
mahphalke | 1:f65f6fadda5d | 116 | static const int32_t lut[]; |
mahphalke | 1:f65f6fadda5d | 117 | static const int16_t lut_offset; |
mahphalke | 1:f65f6fadda5d | 118 | static const uint16_t lut_size; |
mahphalke | 1:f65f6fadda5d | 119 | float lookup(float voltage); |
mahphalke | 1:f65f6fadda5d | 120 | float lookup_inv(float temp); |
mahphalke | 1:f65f6fadda5d | 121 | #endif |
mahphalke | 1:f65f6fadda5d | 122 | }; |
mahphalke | 1:f65f6fadda5d | 123 | |
mahphalke | 1:f65f6fadda5d | 124 | |
mahphalke | 1:f65f6fadda5d | 125 | class Thermocouple_Type_K : public Thermocouple |
mahphalke | 1:f65f6fadda5d | 126 | { |
mahphalke | 1:f65f6fadda5d | 127 | public: |
mahphalke | 1:f65f6fadda5d | 128 | ~Thermocouple_Type_K(); |
mahphalke | 1:f65f6fadda5d | 129 | static const thermocouple_poly_subrange inv_poly[2]; |
mahphalke | 1:f65f6fadda5d | 130 | static const int inv_poly_size; |
mahphalke | 1:f65f6fadda5d | 131 | float convert_inv(float temp); |
mahphalke | 1:f65f6fadda5d | 132 | |
mahphalke | 1:f65f6fadda5d | 133 | static const thermocouple_poly_subrange poly[3]; |
mahphalke | 1:f65f6fadda5d | 134 | static const int poly_size; |
mahphalke | 1:f65f6fadda5d | 135 | float convert(float voltage); |
mahphalke | 1:f65f6fadda5d | 136 | #ifdef TYPE_K_LUT |
mahphalke | 1:f65f6fadda5d | 137 | static const int32_t lut[]; |
mahphalke | 1:f65f6fadda5d | 138 | static const int16_t lut_offset; |
mahphalke | 1:f65f6fadda5d | 139 | static const uint16_t lut_size; |
mahphalke | 1:f65f6fadda5d | 140 | float lookup(float voltage); |
mahphalke | 1:f65f6fadda5d | 141 | float lookup_inv(float temp); |
mahphalke | 1:f65f6fadda5d | 142 | #endif |
mahphalke | 1:f65f6fadda5d | 143 | }; |
mahphalke | 1:f65f6fadda5d | 144 | |
mahphalke | 1:f65f6fadda5d | 145 | |
mahphalke | 1:f65f6fadda5d | 146 | class Thermocouple_Type_N : public Thermocouple |
mahphalke | 1:f65f6fadda5d | 147 | { |
mahphalke | 1:f65f6fadda5d | 148 | public: |
mahphalke | 1:f65f6fadda5d | 149 | ~Thermocouple_Type_N(); |
mahphalke | 1:f65f6fadda5d | 150 | static const thermocouple_poly_subrange inv_poly[2]; |
mahphalke | 1:f65f6fadda5d | 151 | static const int inv_poly_size; |
mahphalke | 1:f65f6fadda5d | 152 | float convert_inv(float temp); |
mahphalke | 1:f65f6fadda5d | 153 | |
mahphalke | 1:f65f6fadda5d | 154 | static const thermocouple_poly_subrange poly[3]; |
mahphalke | 1:f65f6fadda5d | 155 | static const int poly_size; |
mahphalke | 1:f65f6fadda5d | 156 | float convert(float voltage); |
mahphalke | 1:f65f6fadda5d | 157 | #ifdef TYPE_N_LUT |
mahphalke | 1:f65f6fadda5d | 158 | static const int32_t lut[]; |
mahphalke | 1:f65f6fadda5d | 159 | static const int16_t lut_offset; |
mahphalke | 1:f65f6fadda5d | 160 | static const uint16_t lut_size; |
mahphalke | 1:f65f6fadda5d | 161 | float lookup(float voltage); |
mahphalke | 1:f65f6fadda5d | 162 | float lookup_inv(float temp); |
mahphalke | 1:f65f6fadda5d | 163 | #endif |
mahphalke | 1:f65f6fadda5d | 164 | }; |
mahphalke | 1:f65f6fadda5d | 165 | |
mahphalke | 1:f65f6fadda5d | 166 | |
mahphalke | 1:f65f6fadda5d | 167 | class Thermocouple_Type_R : public Thermocouple |
mahphalke | 1:f65f6fadda5d | 168 | { |
mahphalke | 1:f65f6fadda5d | 169 | public: |
mahphalke | 1:f65f6fadda5d | 170 | ~Thermocouple_Type_R(); |
mahphalke | 1:f65f6fadda5d | 171 | static const thermocouple_poly_subrange inv_poly[3]; |
mahphalke | 1:f65f6fadda5d | 172 | static const int inv_poly_size; |
mahphalke | 1:f65f6fadda5d | 173 | float convert_inv(float temp); |
mahphalke | 1:f65f6fadda5d | 174 | |
mahphalke | 1:f65f6fadda5d | 175 | static const thermocouple_poly_subrange poly[4]; |
mahphalke | 1:f65f6fadda5d | 176 | static const int poly_size; |
mahphalke | 1:f65f6fadda5d | 177 | float convert(float voltage); |
mahphalke | 1:f65f6fadda5d | 178 | #ifdef TYPE_R_LUT |
mahphalke | 1:f65f6fadda5d | 179 | static const int32_t lut[]; |
mahphalke | 1:f65f6fadda5d | 180 | static const int16_t lut_offset; |
mahphalke | 1:f65f6fadda5d | 181 | static const uint16_t lut_size; |
mahphalke | 1:f65f6fadda5d | 182 | float lookup(float voltage); |
mahphalke | 1:f65f6fadda5d | 183 | float lookup_inv(float temp); |
mahphalke | 1:f65f6fadda5d | 184 | #endif |
mahphalke | 1:f65f6fadda5d | 185 | }; |
mahphalke | 1:f65f6fadda5d | 186 | |
mahphalke | 1:f65f6fadda5d | 187 | |
mahphalke | 1:f65f6fadda5d | 188 | class Thermocouple_Type_S : public Thermocouple |
mahphalke | 1:f65f6fadda5d | 189 | { |
mahphalke | 1:f65f6fadda5d | 190 | public: |
mahphalke | 1:f65f6fadda5d | 191 | ~Thermocouple_Type_S(); |
mahphalke | 1:f65f6fadda5d | 192 | static const thermocouple_poly_subrange inv_poly[3]; |
mahphalke | 1:f65f6fadda5d | 193 | static const int inv_poly_size; |
mahphalke | 1:f65f6fadda5d | 194 | float convert_inv(float temp); |
mahphalke | 1:f65f6fadda5d | 195 | |
mahphalke | 1:f65f6fadda5d | 196 | static const thermocouple_poly_subrange poly[4]; |
mahphalke | 1:f65f6fadda5d | 197 | static const int poly_size; |
mahphalke | 1:f65f6fadda5d | 198 | float convert(float voltage); |
mahphalke | 1:f65f6fadda5d | 199 | #ifdef TYPE_S_LUT |
mahphalke | 1:f65f6fadda5d | 200 | static const int32_t lut[]; |
mahphalke | 1:f65f6fadda5d | 201 | static const int16_t lut_offset; |
mahphalke | 1:f65f6fadda5d | 202 | static const uint16_t lut_size; |
mahphalke | 1:f65f6fadda5d | 203 | float lookup(float voltage); |
mahphalke | 1:f65f6fadda5d | 204 | float lookup_inv(float temp); |
mahphalke | 1:f65f6fadda5d | 205 | #endif |
mahphalke | 1:f65f6fadda5d | 206 | }; |
mahphalke | 1:f65f6fadda5d | 207 | |
mahphalke | 1:f65f6fadda5d | 208 | |
mahphalke | 1:f65f6fadda5d | 209 | class Thermocouple_Type_T : public Thermocouple |
mahphalke | 1:f65f6fadda5d | 210 | { |
mahphalke | 1:f65f6fadda5d | 211 | public: |
mahphalke | 1:f65f6fadda5d | 212 | ~Thermocouple_Type_T(); |
mahphalke | 1:f65f6fadda5d | 213 | static const thermocouple_poly_subrange inv_poly[2]; |
mahphalke | 1:f65f6fadda5d | 214 | static const int inv_poly_size; |
mahphalke | 1:f65f6fadda5d | 215 | float convert_inv(float temp); |
mahphalke | 1:f65f6fadda5d | 216 | |
mahphalke | 1:f65f6fadda5d | 217 | static const thermocouple_poly_subrange poly[2]; |
mahphalke | 1:f65f6fadda5d | 218 | static const int poly_size; |
mahphalke | 1:f65f6fadda5d | 219 | float convert(float voltage); |
mahphalke | 1:f65f6fadda5d | 220 | #ifdef TYPE_T_LUT |
mahphalke | 1:f65f6fadda5d | 221 | static const int32_t lut[]; |
mahphalke | 1:f65f6fadda5d | 222 | static const int16_t lut_offset; |
mahphalke | 1:f65f6fadda5d | 223 | static const uint16_t lut_size; |
mahphalke | 1:f65f6fadda5d | 224 | float lookup(float voltage); |
mahphalke | 1:f65f6fadda5d | 225 | float lookup_inv(float temp); |
mahphalke | 1:f65f6fadda5d | 226 | #endif |
mahphalke | 1:f65f6fadda5d | 227 | }; |
mahphalke | 1:f65f6fadda5d | 228 | |
mahphalke | 1:f65f6fadda5d | 229 | #endif |