Library to support temperature sensor conversions and lookups
ptc_ky81_110.cpp@2:bcfa5a2f21c9, 2021-03-19 (annotated)
- Committer:
- mahphalke
- Date:
- Fri Mar 19 08:09:19 2021 +0000
- Revision:
- 2:bcfa5a2f21c9
- Parent:
- 1:f65f6fadda5d
Fixed line ending issues
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: ptc_ky81_110.cpp |
mahphalke | 1:f65f6fadda5d | 4 | |
mahphalke | 1:f65f6fadda5d | 5 | @brief: This file contains functionality for PTC KY81/110 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 "thermistor.h" |
mahphalke | 1:f65f6fadda5d | 18 | #include "ptc_ky81_110.h" |
mahphalke | 1:f65f6fadda5d | 19 | |
mahphalke | 1:f65f6fadda5d | 20 | #ifdef DEFINE_LOOKUP_TABLES |
mahphalke | 1:f65f6fadda5d | 21 | /* PTC look-up table. Values are resistance in ohm for temperature |
mahphalke | 1:f65f6fadda5d | 22 | * range from -10 to 80C with +/-1C tolerance. |
mahphalke | 1:f65f6fadda5d | 23 | * @note This table is derived based on the look-up table specified |
mahphalke | 1:f65f6fadda5d | 24 | * in the datasheet of KY81/110 part. The linear interpolation |
mahphalke | 1:f65f6fadda5d | 25 | * has been used to obtain 1C step size. |
mahphalke | 1:f65f6fadda5d | 26 | **/ |
mahphalke | 1:f65f6fadda5d | 27 | const uint32_t ptc_ky81_110::lut[] = { |
mahphalke | 1:f65f6fadda5d | 28 | 747, 753, 760, 767, 774, 781, 787, 794, 801, 808, 815, 822, 829, 836, |
mahphalke | 1:f65f6fadda5d | 29 | 843, 850, 857, 864, 871, 878, 886, 893, 901, 908, 916, 923, 931, 938, |
mahphalke | 1:f65f6fadda5d | 30 | 946, 953, 961, 968, 976, 984, 992, 1000, 1008, 1016, 1024, 1032, 1040, |
mahphalke | 1:f65f6fadda5d | 31 | 1048, 1056, 1064, 1072, 1081, 1089, 1097, 1105, 1113, 1122, 1130, 1139, |
mahphalke | 1:f65f6fadda5d | 32 | 1148, 1156, 1165, 1174, 1182, 1191, 1200, 1209, 1218, 1227, 1236, 1245, |
mahphalke | 1:f65f6fadda5d | 33 | 1254, 1263, 1272, 1281, 1290, 1299, 1308, 1317, 1326, 1336, 1345, 1354, |
mahphalke | 1:f65f6fadda5d | 34 | 1364, 1373, 1382, 1392, 1401, 1411, 1421, 1431, 1441, 1450, 1460, 1470, |
mahphalke | 1:f65f6fadda5d | 35 | 1480, 1490 |
mahphalke | 1:f65f6fadda5d | 36 | }; |
mahphalke | 1:f65f6fadda5d | 37 | #endif |
mahphalke | 1:f65f6fadda5d | 38 | |
mahphalke | 1:f65f6fadda5d | 39 | |
mahphalke | 1:f65f6fadda5d | 40 | /*! |
mahphalke | 1:f65f6fadda5d | 41 | * @brief This is a constructor for ptc_ky81_110 class |
mahphalke | 1:f65f6fadda5d | 42 | * @return none |
mahphalke | 1:f65f6fadda5d | 43 | */ |
mahphalke | 1:f65f6fadda5d | 44 | ptc_ky81_110::ptc_ky81_110() |
mahphalke | 1:f65f6fadda5d | 45 | { |
mahphalke | 1:f65f6fadda5d | 46 | temperature_coeff = 0.79; /* Temperature coefficient for KY81/110 */ |
mahphalke | 1:f65f6fadda5d | 47 | |
mahphalke | 1:f65f6fadda5d | 48 | #ifdef DEFINE_LOOKUP_TABLES |
mahphalke | 1:f65f6fadda5d | 49 | ptc_ky81_110::lut_offset = -10; /* Min temperature obtained through LUT */ |
mahphalke | 1:f65f6fadda5d | 50 | ptc_ky81_110::lut_size = 90; /* Temperature range defined in LUT |
mahphalke | 1:f65f6fadda5d | 51 | [lut_offset : lut_size - lut_offset] */ |
mahphalke | 1:f65f6fadda5d | 52 | #endif |
mahphalke | 1:f65f6fadda5d | 53 | } |
mahphalke | 1:f65f6fadda5d | 54 | |
mahphalke | 1:f65f6fadda5d | 55 | |
mahphalke | 1:f65f6fadda5d | 56 | /*! |
mahphalke | 1:f65f6fadda5d | 57 | * @brief Convert the thermistor resistance into equivalent temperature |
mahphalke | 1:f65f6fadda5d | 58 | * @param resistance[in] - thermistor resistance |
mahphalke | 1:f65f6fadda5d | 59 | * @return Thermistor temperature value |
mahphalke | 1:f65f6fadda5d | 60 | * @note Resistance at room temperature is 1000 ohms (1K) |
mahphalke | 1:f65f6fadda5d | 61 | */ |
mahphalke | 1:f65f6fadda5d | 62 | float ptc_ky81_110::convert(const float resistance) |
mahphalke | 1:f65f6fadda5d | 63 | { |
mahphalke | 1:f65f6fadda5d | 64 | return (((resistance - 1000) / 1000) * (100.0 / temperature_coeff)) + 25.0; |
mahphalke | 1:f65f6fadda5d | 65 | } |
mahphalke | 1:f65f6fadda5d | 66 | |
mahphalke | 1:f65f6fadda5d | 67 | |
mahphalke | 1:f65f6fadda5d | 68 | #ifdef DEFINE_LOOKUP_TABLES |
mahphalke | 1:f65f6fadda5d | 69 | /*! |
mahphalke | 1:f65f6fadda5d | 70 | * @brief Convert the thermistor resistance into equivalent temperature using |
mahphalke | 1:f65f6fadda5d | 71 | * lookup table for KY81/110 NTC |
mahphalke | 1:f65f6fadda5d | 72 | * @param resistance[in] - thermistor resistance |
mahphalke | 1:f65f6fadda5d | 73 | * @return Thermistor temperature value |
mahphalke | 1:f65f6fadda5d | 74 | */ |
mahphalke | 1:f65f6fadda5d | 75 | float ptc_ky81_110::lookup(const float resistance) |
mahphalke | 1:f65f6fadda5d | 76 | { |
mahphalke | 1:f65f6fadda5d | 77 | return thermistor::lookup(lut, resistance, lut_size, lut_offset); |
mahphalke | 1:f65f6fadda5d | 78 | } |
mahphalke | 1:f65f6fadda5d | 79 | #endif |