A collection of Analog Devices drivers for the mbed platform
For additional information check out the mbed page of the Analog Devices wiki: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
libraries/Thermocouple/Thermocouple.h@33:c3ec596a29c2, 2016-11-07 (annotated)
- Committer:
- Adrian Suciu
- Date:
- Mon Nov 07 16:27:12 2016 +0200
- Revision:
- 33:c3ec596a29c2
Added CN0391, CN0396 and CN0397 shields
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Adrian Suciu |
33:c3ec596a29c2 | 1 | #include "mbed.h" |
| Adrian Suciu |
33:c3ec596a29c2 | 2 | #ifndef _THERMOCOUPLE_H_ |
| Adrian Suciu |
33:c3ec596a29c2 | 3 | #define _THERMOCOUPLE_H_ |
| Adrian Suciu |
33:c3ec596a29c2 | 4 | |
| Adrian Suciu |
33:c3ec596a29c2 | 5 | #define DEFINE_LOOKUP_TABLES |
| Adrian Suciu |
33:c3ec596a29c2 | 6 | #ifdef DEFINE_LOOKUP_TABLES |
| Adrian Suciu |
33:c3ec596a29c2 | 7 | #define TYPE_B_LUT |
| Adrian Suciu |
33:c3ec596a29c2 | 8 | #define TYPE_E_LUT |
| Adrian Suciu |
33:c3ec596a29c2 | 9 | #define TYPE_J_LUT |
| Adrian Suciu |
33:c3ec596a29c2 | 10 | #define TYPE_K_LUT |
| Adrian Suciu |
33:c3ec596a29c2 | 11 | #define TYPE_N_LUT |
| Adrian Suciu |
33:c3ec596a29c2 | 12 | #define TYPE_R_LUT |
| Adrian Suciu |
33:c3ec596a29c2 | 13 | #define TYPE_S_LUT |
| Adrian Suciu |
33:c3ec596a29c2 | 14 | #define TYPE_T_LUT |
| Adrian Suciu |
33:c3ec596a29c2 | 15 | #endif |
| Adrian Suciu |
33:c3ec596a29c2 | 16 | |
| Adrian Suciu |
33:c3ec596a29c2 | 17 | class Thermocouple |
| Adrian Suciu |
33:c3ec596a29c2 | 18 | { |
| Adrian Suciu |
33:c3ec596a29c2 | 19 | private: |
| Adrian Suciu |
33:c3ec596a29c2 | 20 | |
| Adrian Suciu |
33:c3ec596a29c2 | 21 | public: |
| Adrian Suciu |
33:c3ec596a29c2 | 22 | typedef struct { |
| Adrian Suciu |
33:c3ec596a29c2 | 23 | float min_voltage_range; |
| Adrian Suciu |
33:c3ec596a29c2 | 24 | float max_voltage_range; |
| Adrian Suciu |
33:c3ec596a29c2 | 25 | float coef[16]; |
| Adrian Suciu |
33:c3ec596a29c2 | 26 | float power[16]; |
| Adrian Suciu |
33:c3ec596a29c2 | 27 | int n; |
| Adrian Suciu |
33:c3ec596a29c2 | 28 | } thermocouple_poly_subrange; |
| Adrian Suciu |
33:c3ec596a29c2 | 29 | Thermocouple(); |
| Adrian Suciu |
33:c3ec596a29c2 | 30 | virtual ~Thermocouple(); |
| Adrian Suciu |
33:c3ec596a29c2 | 31 | static float convert(float voltage, const thermocouple_poly_subrange range[], const int n); |
| Adrian Suciu |
33:c3ec596a29c2 | 32 | static float lookup(const int32_t *lut, float voltage, uint16_t size, int16_t offset); |
| Adrian Suciu |
33:c3ec596a29c2 | 33 | virtual float convert(float voltage) = 0; |
| Adrian Suciu |
33:c3ec596a29c2 | 34 | virtual float convert_inv(float temp) = 0; |
| Adrian Suciu |
33:c3ec596a29c2 | 35 | virtual float lookup(float voltage) = 0; |
| Adrian Suciu |
33:c3ec596a29c2 | 36 | virtual float lookup_inv(float temp) = 0; |
| Adrian Suciu |
33:c3ec596a29c2 | 37 | |
| Adrian Suciu |
33:c3ec596a29c2 | 38 | }; |
| Adrian Suciu |
33:c3ec596a29c2 | 39 | |
| Adrian Suciu |
33:c3ec596a29c2 | 40 | |
| Adrian Suciu |
33:c3ec596a29c2 | 41 | |
| Adrian Suciu |
33:c3ec596a29c2 | 42 | |
| Adrian Suciu |
33:c3ec596a29c2 | 43 | class Thermocouple_Type_B : public Thermocouple |
| Adrian Suciu |
33:c3ec596a29c2 | 44 | { |
| Adrian Suciu |
33:c3ec596a29c2 | 45 | public: |
| Adrian Suciu |
33:c3ec596a29c2 | 46 | ~Thermocouple_Type_B(); |
| Adrian Suciu |
33:c3ec596a29c2 | 47 | static const thermocouple_poly_subrange inv_poly[2]; |
| Adrian Suciu |
33:c3ec596a29c2 | 48 | static const int inv_poly_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 49 | float convert_inv(float temp); |
| Adrian Suciu |
33:c3ec596a29c2 | 50 | |
| Adrian Suciu |
33:c3ec596a29c2 | 51 | static const thermocouple_poly_subrange poly[2]; |
| Adrian Suciu |
33:c3ec596a29c2 | 52 | static const int poly_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 53 | float convert(float voltage); |
| Adrian Suciu |
33:c3ec596a29c2 | 54 | #ifdef TYPE_B_LUT |
| Adrian Suciu |
33:c3ec596a29c2 | 55 | static const int32_t lut[]; |
| Adrian Suciu |
33:c3ec596a29c2 | 56 | static const int16_t lut_offset; |
| Adrian Suciu |
33:c3ec596a29c2 | 57 | static const uint16_t lut_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 58 | float lookup(float voltage); |
| Adrian Suciu |
33:c3ec596a29c2 | 59 | float lookup_inv(float temp); |
| Adrian Suciu |
33:c3ec596a29c2 | 60 | #endif |
| Adrian Suciu |
33:c3ec596a29c2 | 61 | }; |
| Adrian Suciu |
33:c3ec596a29c2 | 62 | |
| Adrian Suciu |
33:c3ec596a29c2 | 63 | |
| Adrian Suciu |
33:c3ec596a29c2 | 64 | class Thermocouple_Type_E : public Thermocouple |
| Adrian Suciu |
33:c3ec596a29c2 | 65 | { |
| Adrian Suciu |
33:c3ec596a29c2 | 66 | public: |
| Adrian Suciu |
33:c3ec596a29c2 | 67 | ~Thermocouple_Type_E(); |
| Adrian Suciu |
33:c3ec596a29c2 | 68 | static const thermocouple_poly_subrange inv_poly[2]; |
| Adrian Suciu |
33:c3ec596a29c2 | 69 | static const int inv_poly_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 70 | float convert_inv(float temp); |
| Adrian Suciu |
33:c3ec596a29c2 | 71 | |
| Adrian Suciu |
33:c3ec596a29c2 | 72 | static const thermocouple_poly_subrange poly[2]; |
| Adrian Suciu |
33:c3ec596a29c2 | 73 | static const int poly_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 74 | float convert(float voltage); |
| Adrian Suciu |
33:c3ec596a29c2 | 75 | #ifdef TYPE_E_LUT |
| Adrian Suciu |
33:c3ec596a29c2 | 76 | static const int32_t lut[]; |
| Adrian Suciu |
33:c3ec596a29c2 | 77 | static const int16_t lut_offset; |
| Adrian Suciu |
33:c3ec596a29c2 | 78 | static const uint16_t lut_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 79 | float lookup(float voltage); |
| Adrian Suciu |
33:c3ec596a29c2 | 80 | float lookup_inv(float temp); |
| Adrian Suciu |
33:c3ec596a29c2 | 81 | #endif |
| Adrian Suciu |
33:c3ec596a29c2 | 82 | }; |
| Adrian Suciu |
33:c3ec596a29c2 | 83 | |
| Adrian Suciu |
33:c3ec596a29c2 | 84 | |
| Adrian Suciu |
33:c3ec596a29c2 | 85 | class Thermocouple_Type_J : public Thermocouple |
| Adrian Suciu |
33:c3ec596a29c2 | 86 | { |
| Adrian Suciu |
33:c3ec596a29c2 | 87 | public: |
| Adrian Suciu |
33:c3ec596a29c2 | 88 | ~Thermocouple_Type_J(); |
| Adrian Suciu |
33:c3ec596a29c2 | 89 | static const thermocouple_poly_subrange inv_poly[2]; |
| Adrian Suciu |
33:c3ec596a29c2 | 90 | static const int inv_poly_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 91 | float convert_inv(float temp); |
| Adrian Suciu |
33:c3ec596a29c2 | 92 | |
| Adrian Suciu |
33:c3ec596a29c2 | 93 | static const thermocouple_poly_subrange poly[3]; |
| Adrian Suciu |
33:c3ec596a29c2 | 94 | static const int poly_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 95 | float convert(float voltage); |
| Adrian Suciu |
33:c3ec596a29c2 | 96 | #ifdef TYPE_J_LUT |
| Adrian Suciu |
33:c3ec596a29c2 | 97 | static const int32_t lut[]; |
| Adrian Suciu |
33:c3ec596a29c2 | 98 | static const int16_t lut_offset; |
| Adrian Suciu |
33:c3ec596a29c2 | 99 | static const uint16_t lut_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 100 | float lookup(float voltage); |
| Adrian Suciu |
33:c3ec596a29c2 | 101 | float lookup_inv(float temp); |
| Adrian Suciu |
33:c3ec596a29c2 | 102 | #endif |
| Adrian Suciu |
33:c3ec596a29c2 | 103 | }; |
| Adrian Suciu |
33:c3ec596a29c2 | 104 | |
| Adrian Suciu |
33:c3ec596a29c2 | 105 | |
| Adrian Suciu |
33:c3ec596a29c2 | 106 | class Thermocouple_Type_K : public Thermocouple |
| Adrian Suciu |
33:c3ec596a29c2 | 107 | { |
| Adrian Suciu |
33:c3ec596a29c2 | 108 | public: |
| Adrian Suciu |
33:c3ec596a29c2 | 109 | ~Thermocouple_Type_K(); |
| Adrian Suciu |
33:c3ec596a29c2 | 110 | static const thermocouple_poly_subrange inv_poly[2]; |
| Adrian Suciu |
33:c3ec596a29c2 | 111 | static const int inv_poly_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 112 | float convert_inv(float temp); |
| Adrian Suciu |
33:c3ec596a29c2 | 113 | |
| Adrian Suciu |
33:c3ec596a29c2 | 114 | static const thermocouple_poly_subrange poly[3]; |
| Adrian Suciu |
33:c3ec596a29c2 | 115 | static const int poly_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 116 | float convert(float voltage); |
| Adrian Suciu |
33:c3ec596a29c2 | 117 | #ifdef TYPE_K_LUT |
| Adrian Suciu |
33:c3ec596a29c2 | 118 | static const int32_t lut[]; |
| Adrian Suciu |
33:c3ec596a29c2 | 119 | static const int16_t lut_offset; |
| Adrian Suciu |
33:c3ec596a29c2 | 120 | static const uint16_t lut_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 121 | float lookup(float voltage); |
| Adrian Suciu |
33:c3ec596a29c2 | 122 | float lookup_inv(float temp); |
| Adrian Suciu |
33:c3ec596a29c2 | 123 | #endif |
| Adrian Suciu |
33:c3ec596a29c2 | 124 | }; |
| Adrian Suciu |
33:c3ec596a29c2 | 125 | |
| Adrian Suciu |
33:c3ec596a29c2 | 126 | |
| Adrian Suciu |
33:c3ec596a29c2 | 127 | class Thermocouple_Type_N : public Thermocouple |
| Adrian Suciu |
33:c3ec596a29c2 | 128 | { |
| Adrian Suciu |
33:c3ec596a29c2 | 129 | public: |
| Adrian Suciu |
33:c3ec596a29c2 | 130 | ~Thermocouple_Type_N(); |
| Adrian Suciu |
33:c3ec596a29c2 | 131 | static const thermocouple_poly_subrange inv_poly[2]; |
| Adrian Suciu |
33:c3ec596a29c2 | 132 | static const int inv_poly_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 133 | float convert_inv(float temp); |
| Adrian Suciu |
33:c3ec596a29c2 | 134 | |
| Adrian Suciu |
33:c3ec596a29c2 | 135 | static const thermocouple_poly_subrange poly[3]; |
| Adrian Suciu |
33:c3ec596a29c2 | 136 | static const int poly_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 137 | float convert(float voltage); |
| Adrian Suciu |
33:c3ec596a29c2 | 138 | #ifdef TYPE_N_LUT |
| Adrian Suciu |
33:c3ec596a29c2 | 139 | static const int32_t lut[]; |
| Adrian Suciu |
33:c3ec596a29c2 | 140 | static const int16_t lut_offset; |
| Adrian Suciu |
33:c3ec596a29c2 | 141 | static const uint16_t lut_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 142 | float lookup(float voltage); |
| Adrian Suciu |
33:c3ec596a29c2 | 143 | float lookup_inv(float temp); |
| Adrian Suciu |
33:c3ec596a29c2 | 144 | #endif |
| Adrian Suciu |
33:c3ec596a29c2 | 145 | }; |
| Adrian Suciu |
33:c3ec596a29c2 | 146 | |
| Adrian Suciu |
33:c3ec596a29c2 | 147 | |
| Adrian Suciu |
33:c3ec596a29c2 | 148 | class Thermocouple_Type_R : public Thermocouple |
| Adrian Suciu |
33:c3ec596a29c2 | 149 | { |
| Adrian Suciu |
33:c3ec596a29c2 | 150 | public: |
| Adrian Suciu |
33:c3ec596a29c2 | 151 | ~Thermocouple_Type_R(); |
| Adrian Suciu |
33:c3ec596a29c2 | 152 | static const thermocouple_poly_subrange inv_poly[3]; |
| Adrian Suciu |
33:c3ec596a29c2 | 153 | static const int inv_poly_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 154 | float convert_inv(float temp); |
| Adrian Suciu |
33:c3ec596a29c2 | 155 | |
| Adrian Suciu |
33:c3ec596a29c2 | 156 | static const thermocouple_poly_subrange poly[4]; |
| Adrian Suciu |
33:c3ec596a29c2 | 157 | static const int poly_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 158 | float convert(float voltage); |
| Adrian Suciu |
33:c3ec596a29c2 | 159 | #ifdef TYPE_R_LUT |
| Adrian Suciu |
33:c3ec596a29c2 | 160 | static const int32_t lut[]; |
| Adrian Suciu |
33:c3ec596a29c2 | 161 | static const int16_t lut_offset; |
| Adrian Suciu |
33:c3ec596a29c2 | 162 | static const uint16_t lut_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 163 | float lookup(float voltage); |
| Adrian Suciu |
33:c3ec596a29c2 | 164 | float lookup_inv(float temp); |
| Adrian Suciu |
33:c3ec596a29c2 | 165 | #endif |
| Adrian Suciu |
33:c3ec596a29c2 | 166 | }; |
| Adrian Suciu |
33:c3ec596a29c2 | 167 | |
| Adrian Suciu |
33:c3ec596a29c2 | 168 | |
| Adrian Suciu |
33:c3ec596a29c2 | 169 | class Thermocouple_Type_S : public Thermocouple |
| Adrian Suciu |
33:c3ec596a29c2 | 170 | { |
| Adrian Suciu |
33:c3ec596a29c2 | 171 | public: |
| Adrian Suciu |
33:c3ec596a29c2 | 172 | ~Thermocouple_Type_S(); |
| Adrian Suciu |
33:c3ec596a29c2 | 173 | static const thermocouple_poly_subrange inv_poly[3]; |
| Adrian Suciu |
33:c3ec596a29c2 | 174 | static const int inv_poly_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 175 | float convert_inv(float temp); |
| Adrian Suciu |
33:c3ec596a29c2 | 176 | |
| Adrian Suciu |
33:c3ec596a29c2 | 177 | static const thermocouple_poly_subrange poly[4]; |
| Adrian Suciu |
33:c3ec596a29c2 | 178 | static const int poly_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 179 | float convert(float voltage); |
| Adrian Suciu |
33:c3ec596a29c2 | 180 | #ifdef TYPE_S_LUT |
| Adrian Suciu |
33:c3ec596a29c2 | 181 | static const int32_t lut[]; |
| Adrian Suciu |
33:c3ec596a29c2 | 182 | static const int16_t lut_offset; |
| Adrian Suciu |
33:c3ec596a29c2 | 183 | static const uint16_t lut_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 184 | float lookup(float voltage); |
| Adrian Suciu |
33:c3ec596a29c2 | 185 | float lookup_inv(float temp); |
| Adrian Suciu |
33:c3ec596a29c2 | 186 | #endif |
| Adrian Suciu |
33:c3ec596a29c2 | 187 | }; |
| Adrian Suciu |
33:c3ec596a29c2 | 188 | |
| Adrian Suciu |
33:c3ec596a29c2 | 189 | |
| Adrian Suciu |
33:c3ec596a29c2 | 190 | class Thermocouple_Type_T : public Thermocouple |
| Adrian Suciu |
33:c3ec596a29c2 | 191 | { |
| Adrian Suciu |
33:c3ec596a29c2 | 192 | public: |
| Adrian Suciu |
33:c3ec596a29c2 | 193 | ~Thermocouple_Type_T(); |
| Adrian Suciu |
33:c3ec596a29c2 | 194 | static const thermocouple_poly_subrange inv_poly[2]; |
| Adrian Suciu |
33:c3ec596a29c2 | 195 | static const int inv_poly_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 196 | float convert_inv(float temp); |
| Adrian Suciu |
33:c3ec596a29c2 | 197 | |
| Adrian Suciu |
33:c3ec596a29c2 | 198 | static const thermocouple_poly_subrange poly[2]; |
| Adrian Suciu |
33:c3ec596a29c2 | 199 | static const int poly_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 200 | float convert(float voltage); |
| Adrian Suciu |
33:c3ec596a29c2 | 201 | #ifdef TYPE_T_LUT |
| Adrian Suciu |
33:c3ec596a29c2 | 202 | static const int32_t lut[]; |
| Adrian Suciu |
33:c3ec596a29c2 | 203 | static const int16_t lut_offset; |
| Adrian Suciu |
33:c3ec596a29c2 | 204 | static const uint16_t lut_size; |
| Adrian Suciu |
33:c3ec596a29c2 | 205 | float lookup(float voltage); |
| Adrian Suciu |
33:c3ec596a29c2 | 206 | float lookup_inv(float temp); |
| Adrian Suciu |
33:c3ec596a29c2 | 207 | #endif |
| Adrian Suciu |
33:c3ec596a29c2 | 208 | }; |
| Adrian Suciu |
33:c3ec596a29c2 | 209 | |
| Adrian Suciu |
33:c3ec596a29c2 | 210 | |
| Adrian Suciu |
33:c3ec596a29c2 | 211 | |
| Adrian Suciu |
33:c3ec596a29c2 | 212 | #endif |
CN0357 - Toxic gas measurement
CN0216 - Weight Scale