Library to support temperature sensor conversions and lookups

Committer:
mahphalke
Date:
Mon Feb 22 05:08:54 2021 +0000
Revision:
1:f65f6fadda5d
Child:
2:bcfa5a2f21c9
Added library files

Who changed what in which revision?

UserRevisionLine numberNew 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 1:f65f6fadda5d 21 #ifdef DEFINE_LOOKUP_TABLES
mahphalke 1:f65f6fadda5d 22 /* 10K NTC look-up table. Values are resistance in ohm for temperature
mahphalke 1:f65f6fadda5d 23 * range from -10 to 80C with +/-1C tolerance.
mahphalke 1:f65f6fadda5d 24 * @note This function uses Steinhart-Hart equation for deriving look-up table.
mahphalke 1:f65f6fadda5d 25 **/
mahphalke 1:f65f6fadda5d 26 const uint32_t ntc_10k_44031rc::lut[] = {
mahphalke 1:f65f6fadda5d 27 47561, 45285, 43131, 41091, 39158, 37327, 35591, 33946, 32385,
mahphalke 1:f65f6fadda5d 28 30905, 29500, 28166, 26900, 25697, 24555, 23470, 22438, 21457,
mahphalke 1:f65f6fadda5d 29 20524, 19637, 18792, 17989, 17224, 16495, 15801, 15140, 14510,
mahphalke 1:f65f6fadda5d 30 13910, 13337, 12791, 12271, 11774, 11299, 10847, 10414, 10002,
mahphalke 1:f65f6fadda5d 31 9607, 9231, 8870, 8526, 8197, 7882, 7581, 7293, 7018,
mahphalke 1:f65f6fadda5d 32 6754, 6501, 6259, 6028, 5806, 5593, 5389, 5194, 5006,
mahphalke 1:f65f6fadda5d 33 4827, 4654, 4489, 4331, 4178, 4032, 3892, 3757, 3628,
mahphalke 1:f65f6fadda5d 34 3503, 3384, 3269, 3159, 3053, 2951, 2852, 2758, 2667,
mahphalke 1:f65f6fadda5d 35 2580, 2496, 2415, 2337, 2262, 2189, 2120, 2053, 1988,
mahphalke 1:f65f6fadda5d 36 1926, 1866, 1808, 1752, 1698, 1646, 1596, 1548, 1501,
mahphalke 1:f65f6fadda5d 37 1456
mahphalke 1:f65f6fadda5d 38 };
mahphalke 1:f65f6fadda5d 39 #endif
mahphalke 1:f65f6fadda5d 40
mahphalke 1:f65f6fadda5d 41
mahphalke 1:f65f6fadda5d 42 /*!
mahphalke 1:f65f6fadda5d 43 * @brief This is a constructor for ntc_10k_44031rc class
mahphalke 1:f65f6fadda5d 44 * @return none
mahphalke 1:f65f6fadda5d 45 */
mahphalke 1:f65f6fadda5d 46 ntc_10k_44031rc::ntc_10k_44031rc()
mahphalke 1:f65f6fadda5d 47 {
mahphalke 1:f65f6fadda5d 48 /* Coefficients of Steinhart-Hart equation for 10K NTC to convert
mahphalke 1:f65f6fadda5d 49 * NTC resistance into equivalent temperature */
mahphalke 1:f65f6fadda5d 50 ntc_10k_44031rc::coeff_A = 1.032*pow(10, -3);
mahphalke 1:f65f6fadda5d 51 ntc_10k_44031rc::coeff_B = 2.387*pow(10, -4);
mahphalke 1:f65f6fadda5d 52 ntc_10k_44031rc::coeff_C = 1.580*pow(10, -7);
mahphalke 1:f65f6fadda5d 53
mahphalke 1:f65f6fadda5d 54 #ifdef DEFINE_LOOKUP_TABLES
mahphalke 1:f65f6fadda5d 55 ntc_10k_44031rc::lut_offset = -10; /* Min temperature obtained through LUT */
mahphalke 1:f65f6fadda5d 56 ntc_10k_44031rc::lut_size = 90; /* Temperature range defined in LUT
mahphalke 1:f65f6fadda5d 57 [lut_offset : lut_size - lut_offset] */
mahphalke 1:f65f6fadda5d 58 #endif
mahphalke 1:f65f6fadda5d 59 }
mahphalke 1:f65f6fadda5d 60
mahphalke 1:f65f6fadda5d 61
mahphalke 1:f65f6fadda5d 62 /*!
mahphalke 1:f65f6fadda5d 63 * @brief Convert the thermistor resistance into equivalent temperature using
mahphalke 1:f65f6fadda5d 64 * Steinhart-Hart equation for 10K 44031 NTC
mahphalke 1:f65f6fadda5d 65 * @param resistance[in] - thermistor resistance
mahphalke 1:f65f6fadda5d 66 * @return Thermistor temperature value
mahphalke 1:f65f6fadda5d 67 */
mahphalke 1:f65f6fadda5d 68 float ntc_10k_44031rc::convert(const float resistance)
mahphalke 1:f65f6fadda5d 69 {
mahphalke 1:f65f6fadda5d 70 return thermistor::convert(resistance, coeff_A, coeff_B, coeff_C);
mahphalke 1:f65f6fadda5d 71 }
mahphalke 1:f65f6fadda5d 72
mahphalke 1:f65f6fadda5d 73
mahphalke 1:f65f6fadda5d 74 #ifdef DEFINE_LOOKUP_TABLES
mahphalke 1:f65f6fadda5d 75 /*!
mahphalke 1:f65f6fadda5d 76 * @brief Convert the thermistor resistance into equivalent temperature using
mahphalke 1:f65f6fadda5d 77 * lookup table for 10K 44031 NTC
mahphalke 1:f65f6fadda5d 78 * @param resistance[in] - thermistor resistance
mahphalke 1:f65f6fadda5d 79 * @return Thermistor temperature value
mahphalke 1:f65f6fadda5d 80 */
mahphalke 1:f65f6fadda5d 81 float ntc_10k_44031rc::lookup(const float resistance)
mahphalke 1:f65f6fadda5d 82 {
mahphalke 1:f65f6fadda5d 83 return thermistor::lookup(lut, resistance, lut_size, lut_offset);
mahphalke 1:f65f6fadda5d 84 }
mahphalke 1:f65f6fadda5d 85 #endif
mahphalke 1:f65f6fadda5d 86