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.
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_core_cpp.txt@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 "thermocouple.h" |
| Adrian Suciu |
33:c3ec596a29c2 | 2 | |
| Adrian Suciu |
33:c3ec596a29c2 | 3 | // http://srdata.nist.gov/its90/download/allcoeff.tab |
| Adrian Suciu |
33:c3ec596a29c2 | 4 | |
| Adrian Suciu |
33:c3ec596a29c2 | 5 | Thermocouple::Thermocouple(){} |
| Adrian Suciu |
33:c3ec596a29c2 | 6 | Thermocouple::~Thermocouple() {} |
| Adrian Suciu |
33:c3ec596a29c2 | 7 | |
| Adrian Suciu |
33:c3ec596a29c2 | 8 | float Thermocouple::lookup(const int32_t *lut, float voltage, uint16_t size, int16_t offset) { |
| Adrian Suciu |
33:c3ec596a29c2 | 9 | uint16_t first = 0; |
| Adrian Suciu |
33:c3ec596a29c2 | 10 | uint16_t last = size - 1; |
| Adrian Suciu |
33:c3ec596a29c2 | 11 | uint16_t middle = (first + last) / 2; |
| Adrian Suciu |
33:c3ec596a29c2 | 12 | int32_t integer_voltage = int32_t(voltage*1000); |
| Adrian Suciu |
33:c3ec596a29c2 | 13 | while (first <= last) { |
| Adrian Suciu |
33:c3ec596a29c2 | 14 | if (lut[middle] < integer_voltage) |
| Adrian Suciu |
33:c3ec596a29c2 | 15 | first = middle + 1; |
| Adrian Suciu |
33:c3ec596a29c2 | 16 | else if (lut[middle] == integer_voltage) { |
| Adrian Suciu |
33:c3ec596a29c2 | 17 | return static_cast<float>(middle + offset); |
| Adrian Suciu |
33:c3ec596a29c2 | 18 | } else |
| Adrian Suciu |
33:c3ec596a29c2 | 19 | last = middle - 1; |
| Adrian Suciu |
33:c3ec596a29c2 | 20 | |
| Adrian Suciu |
33:c3ec596a29c2 | 21 | middle = (first + last) / 2; |
| Adrian Suciu |
33:c3ec596a29c2 | 22 | } |
| Adrian Suciu |
33:c3ec596a29c2 | 23 | if (first > last) |
| Adrian Suciu |
33:c3ec596a29c2 | 24 | return static_cast<float>(first+offset); |
| Adrian Suciu |
33:c3ec596a29c2 | 25 | |
| Adrian Suciu |
33:c3ec596a29c2 | 26 | return 0; // should never get here |
| Adrian Suciu |
33:c3ec596a29c2 | 27 | } |
| Adrian Suciu |
33:c3ec596a29c2 | 28 | |
| Adrian Suciu |
33:c3ec596a29c2 | 29 | float Thermocouple::convert(float voltage, const thermocouple_poly_subrange range[], const int n) { |
| Adrian Suciu |
33:c3ec596a29c2 | 30 | int range_id = 0; |
| Adrian Suciu |
33:c3ec596a29c2 | 31 | float temperature=0; |
| Adrian Suciu |
33:c3ec596a29c2 | 32 | for(range_id = 0 ; range_id<n;range_id++) |
| Adrian Suciu |
33:c3ec596a29c2 | 33 | { |
| Adrian Suciu |
33:c3ec596a29c2 | 34 | if(voltage > range[range_id].min_voltage_range && voltage <= range[range_id].max_voltage_range) |
| Adrian Suciu |
33:c3ec596a29c2 | 35 | break; |
| Adrian Suciu |
33:c3ec596a29c2 | 36 | } |
| Adrian Suciu |
33:c3ec596a29c2 | 37 | |
| Adrian Suciu |
33:c3ec596a29c2 | 38 | for (int i = 0; i < range[range_id].n; i++) { |
| Adrian Suciu |
33:c3ec596a29c2 | 39 | temperature += (range[range_id].coef[i] * pow(10,range[range_id].power[i])) * pow(voltage, i); |
| Adrian Suciu |
33:c3ec596a29c2 | 40 | } |
| Adrian Suciu |
33:c3ec596a29c2 | 41 | return temperature; |
| Adrian Suciu |
33:c3ec596a29c2 | 42 | } |
| Adrian Suciu |
33:c3ec596a29c2 | 43 |
CN0357 - Toxic gas measurement
CN0216 - Weight Scale