Library to support temperature sensor conversions and lookups
ntc_10k_44031.cpp@4:d8246c20aed2, 2021-07-01 (annotated)
- Committer:
- mahphalke
- Date:
- Thu Jul 01 13:41:18 2021 +0530
- Revision:
- 4:d8246c20aed2
- Parent:
- 2:bcfa5a2f21c9
Adding equation to calculate 10K 44031 NTC temperature using Beta value
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: ntc_10k_44031.cpp |
mahphalke | 1:f65f6fadda5d | 4 | |
mahphalke | 1:f65f6fadda5d | 5 | @brief: This file contains functionality for 10K NTC 44021 model |
mahphalke | 1:f65f6fadda5d | 6 | |
mahphalke | 1:f65f6fadda5d | 7 | @details: |
mahphalke | 1:f65f6fadda5d | 8 | ----------------------------------------------------------------------------- |
mahphalke | 1:f65f6fadda5d | 9 | Copyright (c) 2021 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 <math.h> |
mahphalke | 1:f65f6fadda5d | 18 | #include "thermistor.h" |
mahphalke | 1:f65f6fadda5d | 19 | #include "ntc_10k_44031.h" |
mahphalke | 1:f65f6fadda5d | 20 | |
mahphalke |
4:d8246c20aed2 | 21 | /* Convert the temperature using Beta factor specified for 44031 10K NTC */ |
mahphalke |
4:d8246c20aed2 | 22 | //#define NTC_10K_44031_CONVERT_USING_BETA_VALUE |
mahphalke |
4:d8246c20aed2 | 23 | |
mahphalke |
4:d8246c20aed2 | 24 | #if defined(NTC_10K_44031_CONVERT_USING_BETA_VALUE) |
mahphalke |
4:d8246c20aed2 | 25 | #define NTC_10K_44031_RESISTANCE_AT_25C 10000 // 10K |
mahphalke |
4:d8246c20aed2 | 26 | #define NTC_10K_44031_ROOM_TEMP_IN_KELVIN 298.15 |
mahphalke |
4:d8246c20aed2 | 27 | #define NTC_10K_44031_BETA_VALUE 3694 |
mahphalke |
4:d8246c20aed2 | 28 | #endif |
mahphalke |
4:d8246c20aed2 | 29 | |
mahphalke | 1:f65f6fadda5d | 30 | #ifdef DEFINE_LOOKUP_TABLES |
mahphalke | 1:f65f6fadda5d | 31 | /* 10K NTC look-up table. Values are resistance in ohm for temperature |
mahphalke | 1:f65f6fadda5d | 32 | * range from -10 to 80C with +/-1C tolerance. |
mahphalke | 1:f65f6fadda5d | 33 | * @note This function uses Steinhart-Hart equation for deriving look-up table. |
mahphalke | 1:f65f6fadda5d | 34 | **/ |
mahphalke | 1:f65f6fadda5d | 35 | const uint32_t ntc_10k_44031rc::lut[] = { |
mahphalke | 1:f65f6fadda5d | 36 | 47561, 45285, 43131, 41091, 39158, 37327, 35591, 33946, 32385, |
mahphalke | 1:f65f6fadda5d | 37 | 30905, 29500, 28166, 26900, 25697, 24555, 23470, 22438, 21457, |
mahphalke | 1:f65f6fadda5d | 38 | 20524, 19637, 18792, 17989, 17224, 16495, 15801, 15140, 14510, |
mahphalke | 1:f65f6fadda5d | 39 | 13910, 13337, 12791, 12271, 11774, 11299, 10847, 10414, 10002, |
mahphalke | 1:f65f6fadda5d | 40 | 9607, 9231, 8870, 8526, 8197, 7882, 7581, 7293, 7018, |
mahphalke | 1:f65f6fadda5d | 41 | 6754, 6501, 6259, 6028, 5806, 5593, 5389, 5194, 5006, |
mahphalke | 1:f65f6fadda5d | 42 | 4827, 4654, 4489, 4331, 4178, 4032, 3892, 3757, 3628, |
mahphalke | 1:f65f6fadda5d | 43 | 3503, 3384, 3269, 3159, 3053, 2951, 2852, 2758, 2667, |
mahphalke | 1:f65f6fadda5d | 44 | 2580, 2496, 2415, 2337, 2262, 2189, 2120, 2053, 1988, |
mahphalke | 1:f65f6fadda5d | 45 | 1926, 1866, 1808, 1752, 1698, 1646, 1596, 1548, 1501, |
mahphalke | 1:f65f6fadda5d | 46 | 1456 |
mahphalke | 1:f65f6fadda5d | 47 | }; |
mahphalke | 1:f65f6fadda5d | 48 | #endif |
mahphalke | 1:f65f6fadda5d | 49 | |
mahphalke | 1:f65f6fadda5d | 50 | |
mahphalke | 1:f65f6fadda5d | 51 | /*! |
mahphalke | 1:f65f6fadda5d | 52 | * @brief This is a constructor for ntc_10k_44031rc class |
mahphalke | 1:f65f6fadda5d | 53 | * @return none |
mahphalke | 1:f65f6fadda5d | 54 | */ |
mahphalke | 1:f65f6fadda5d | 55 | ntc_10k_44031rc::ntc_10k_44031rc() |
mahphalke | 1:f65f6fadda5d | 56 | { |
mahphalke | 1:f65f6fadda5d | 57 | /* Coefficients of Steinhart-Hart equation for 10K NTC to convert |
mahphalke | 1:f65f6fadda5d | 58 | * NTC resistance into equivalent temperature */ |
mahphalke | 1:f65f6fadda5d | 59 | ntc_10k_44031rc::coeff_A = 1.032*pow(10, -3); |
mahphalke | 1:f65f6fadda5d | 60 | ntc_10k_44031rc::coeff_B = 2.387*pow(10, -4); |
mahphalke | 1:f65f6fadda5d | 61 | ntc_10k_44031rc::coeff_C = 1.580*pow(10, -7); |
mahphalke | 1:f65f6fadda5d | 62 | |
mahphalke | 1:f65f6fadda5d | 63 | #ifdef DEFINE_LOOKUP_TABLES |
mahphalke | 1:f65f6fadda5d | 64 | ntc_10k_44031rc::lut_offset = -10; /* Min temperature obtained through LUT */ |
mahphalke | 1:f65f6fadda5d | 65 | ntc_10k_44031rc::lut_size = 90; /* Temperature range defined in LUT |
mahphalke | 1:f65f6fadda5d | 66 | [lut_offset : lut_size - lut_offset] */ |
mahphalke | 1:f65f6fadda5d | 67 | #endif |
mahphalke | 1:f65f6fadda5d | 68 | } |
mahphalke | 1:f65f6fadda5d | 69 | |
mahphalke | 1:f65f6fadda5d | 70 | |
mahphalke | 1:f65f6fadda5d | 71 | /*! |
mahphalke | 1:f65f6fadda5d | 72 | * @brief Convert the thermistor resistance into equivalent temperature using |
mahphalke |
4:d8246c20aed2 | 73 | * Steinhart-Hart equation Or Beta value for 10K 44031 NTC |
mahphalke | 1:f65f6fadda5d | 74 | * @param resistance[in] - thermistor resistance |
mahphalke |
4:d8246c20aed2 | 75 | * @return Thermistor temperature value in Celcius |
mahphalke | 1:f65f6fadda5d | 76 | */ |
mahphalke | 1:f65f6fadda5d | 77 | float ntc_10k_44031rc::convert(const float resistance) |
mahphalke | 1:f65f6fadda5d | 78 | { |
mahphalke |
4:d8246c20aed2 | 79 | #if defined(NTC_10K_44031_CONVERT_USING_BETA_VALUE) |
mahphalke |
4:d8246c20aed2 | 80 | float temperature; |
mahphalke |
4:d8246c20aed2 | 81 | temperature = (1 / ((log(resistance / NTC_10K_44031_RESISTANCE_AT_25C) / |
mahphalke |
4:d8246c20aed2 | 82 | NTC_10K_44031_BETA_VALUE) + (1 / NTC_10K_44031_ROOM_TEMP_IN_KELVIN))) - 273.15; |
mahphalke |
4:d8246c20aed2 | 83 | return temperature; |
mahphalke |
4:d8246c20aed2 | 84 | #else |
mahphalke | 1:f65f6fadda5d | 85 | return thermistor::convert(resistance, coeff_A, coeff_B, coeff_C); |
mahphalke |
4:d8246c20aed2 | 86 | #endif |
mahphalke | 1:f65f6fadda5d | 87 | } |
mahphalke | 1:f65f6fadda5d | 88 | |
mahphalke | 1:f65f6fadda5d | 89 | |
mahphalke | 1:f65f6fadda5d | 90 | #ifdef DEFINE_LOOKUP_TABLES |
mahphalke | 1:f65f6fadda5d | 91 | /*! |
mahphalke | 1:f65f6fadda5d | 92 | * @brief Convert the thermistor resistance into equivalent temperature using |
mahphalke | 1:f65f6fadda5d | 93 | * lookup table for 10K 44031 NTC |
mahphalke | 1:f65f6fadda5d | 94 | * @param resistance[in] - thermistor resistance |
mahphalke | 1:f65f6fadda5d | 95 | * @return Thermistor temperature value |
mahphalke | 1:f65f6fadda5d | 96 | */ |
mahphalke | 1:f65f6fadda5d | 97 | float ntc_10k_44031rc::lookup(const float resistance) |
mahphalke | 1:f65f6fadda5d | 98 | { |
mahphalke | 1:f65f6fadda5d | 99 | return thermistor::lookup(lut, resistance, lut_size, lut_offset); |
mahphalke | 1:f65f6fadda5d | 100 | } |
mahphalke | 1:f65f6fadda5d | 101 | #endif |