Mahesh Phalke / tempsensors_prv
Committer:
mahphalke
Date:
Fri Feb 19 16:05:58 2021 +0530
Revision:
0:854742598c2c
Child:
1:851dbb04c1e5
Added temperature sensor library source files

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mahphalke 0:854742598c2c 1 /*!
mahphalke 0:854742598c2c 2 *****************************************************************************
mahphalke 0:854742598c2c 3 @file: ptc_ky81_110.cpp
mahphalke 0:854742598c2c 4
mahphalke 0:854742598c2c 5 @brief: This file contains functionality for PTC KY81/110 model
mahphalke 0:854742598c2c 6
mahphalke 0:854742598c2c 7 @details:
mahphalke 0:854742598c2c 8 -----------------------------------------------------------------------------
mahphalke 0:854742598c2c 9 Copyright (c) 2020 Analog Devices, Inc. All rights reserved.
mahphalke 0:854742598c2c 10
mahphalke 0:854742598c2c 11 This software is proprietary to Analog Devices, Inc. and its licensors.
mahphalke 0:854742598c2c 12 By using this software you agree to the terms of the associated
mahphalke 0:854742598c2c 13 Analog Devices Software License Agreement.
mahphalke 0:854742598c2c 14
mahphalke 0:854742598c2c 15 *****************************************************************************/
mahphalke 0:854742598c2c 16
mahphalke 0:854742598c2c 17 #include "thermistor.h"
mahphalke 0:854742598c2c 18 #include "ptc_ky81_110.h"
mahphalke 0:854742598c2c 19
mahphalke 0:854742598c2c 20 #ifdef DEFINE_LOOKUP_TABLES
mahphalke 0:854742598c2c 21 /* PTC look-up table. Values are resistance in ohm for temperature
mahphalke 0:854742598c2c 22 * range from -10 to 80C with +/-1C tolerance.
mahphalke 0:854742598c2c 23 * @note This table is derived based on the look-up table specified
mahphalke 0:854742598c2c 24 * in the datasheet of KY81/110 part. The linear interpolation
mahphalke 0:854742598c2c 25 * has been used to obtain 1C step size.
mahphalke 0:854742598c2c 26 **/
mahphalke 0:854742598c2c 27 const uint32_t ptc_ky81_110::lut[] = {
mahphalke 0:854742598c2c 28 747, 753, 760, 767, 774, 781, 787, 794, 801, 808, 815, 822, 829, 836,
mahphalke 0:854742598c2c 29 843, 850, 857, 864, 871, 878, 886, 893, 901, 908, 916, 923, 931, 938,
mahphalke 0:854742598c2c 30 946, 953, 961, 968, 976, 984, 992, 1000, 1008, 1016, 1024, 1032, 1040,
mahphalke 0:854742598c2c 31 1048, 1056, 1064, 1072, 1081, 1089, 1097, 1105, 1113, 1122, 1130, 1139,
mahphalke 0:854742598c2c 32 1148, 1156, 1165, 1174, 1182, 1191, 1200, 1209, 1218, 1227, 1236, 1245,
mahphalke 0:854742598c2c 33 1254, 1263, 1272, 1281, 1290, 1299, 1308, 1317, 1326, 1336, 1345, 1354,
mahphalke 0:854742598c2c 34 1364, 1373, 1382, 1392, 1401, 1411, 1421, 1431, 1441, 1450, 1460, 1470,
mahphalke 0:854742598c2c 35 1480, 1490
mahphalke 0:854742598c2c 36 };
mahphalke 0:854742598c2c 37 #endif
mahphalke 0:854742598c2c 38
mahphalke 0:854742598c2c 39
mahphalke 0:854742598c2c 40 /*!
mahphalke 0:854742598c2c 41 * @brief This is a constructor for ptc_ky81_110 class
mahphalke 0:854742598c2c 42 * @return none
mahphalke 0:854742598c2c 43 */
mahphalke 0:854742598c2c 44 ptc_ky81_110::ptc_ky81_110()
mahphalke 0:854742598c2c 45 {
mahphalke 0:854742598c2c 46 temperature_coeff = 0.79; /* Temperature coefficient for KY81/110 */
mahphalke 0:854742598c2c 47
mahphalke 0:854742598c2c 48 #ifdef DEFINE_LOOKUP_TABLES
mahphalke 0:854742598c2c 49 ptc_ky81_110::lut_offset = -10; /* Min temperature obtained through LUT */
mahphalke 0:854742598c2c 50 ptc_ky81_110::lut_size = 90; /* Temperature range defined in LUT
mahphalke 0:854742598c2c 51 [lut_offset : lut_size - lut_offset] */
mahphalke 0:854742598c2c 52 #endif
mahphalke 0:854742598c2c 53 }
mahphalke 0:854742598c2c 54
mahphalke 0:854742598c2c 55
mahphalke 0:854742598c2c 56 /*!
mahphalke 0:854742598c2c 57 * @brief Convert the thermistor resistance into equivalent temperature
mahphalke 0:854742598c2c 58 * @param resistance[in] - thermistor resistance
mahphalke 0:854742598c2c 59 * @return Thermistor temperature value
mahphalke 0:854742598c2c 60 * @note Resistance at room temperature is 1000 ohms (1K)
mahphalke 0:854742598c2c 61 */
mahphalke 0:854742598c2c 62 float ptc_ky81_110::convert(const float resistance)
mahphalke 0:854742598c2c 63 {
mahphalke 0:854742598c2c 64 return (((resistance - 1000) / 1000) * (100.0 / temperature_coeff)) + 25.0;
mahphalke 0:854742598c2c 65 }
mahphalke 0:854742598c2c 66
mahphalke 0:854742598c2c 67
mahphalke 0:854742598c2c 68 #ifdef DEFINE_LOOKUP_TABLES
mahphalke 0:854742598c2c 69 /*!
mahphalke 0:854742598c2c 70 * @brief Convert the thermistor resistance into equivalent temperature using
mahphalke 0:854742598c2c 71 * lookup table for KY81/110 NTC
mahphalke 0:854742598c2c 72 * @param resistance[in] - thermistor resistance
mahphalke 0:854742598c2c 73 * @return Thermistor temperature value
mahphalke 0:854742598c2c 74 */
mahphalke 0:854742598c2c 75 float ptc_ky81_110::lookup(const float resistance)
mahphalke 0:854742598c2c 76 {
mahphalke 0:854742598c2c 77 return thermistor::lookup(lut, resistance, lut_size, lut_offset);
mahphalke 0:854742598c2c 78 }
mahphalke 0:854742598c2c 79 #endif