Library to support temperature sensor conversions and lookups
Diff: ntc_10k_44031.cpp
- Revision:
- 4:d8246c20aed2
- Parent:
- 2:bcfa5a2f21c9
--- a/ntc_10k_44031.cpp Tue May 25 15:28:17 2021 +0530 +++ b/ntc_10k_44031.cpp Thu Jul 01 13:41:18 2021 +0530 @@ -18,6 +18,15 @@ #include "thermistor.h" #include "ntc_10k_44031.h" +/* Convert the temperature using Beta factor specified for 44031 10K NTC */ +//#define NTC_10K_44031_CONVERT_USING_BETA_VALUE + +#if defined(NTC_10K_44031_CONVERT_USING_BETA_VALUE) +#define NTC_10K_44031_RESISTANCE_AT_25C 10000 // 10K +#define NTC_10K_44031_ROOM_TEMP_IN_KELVIN 298.15 +#define NTC_10K_44031_BETA_VALUE 3694 +#endif + #ifdef DEFINE_LOOKUP_TABLES /* 10K NTC look-up table. Values are resistance in ohm for temperature * range from -10 to 80C with +/-1C tolerance. @@ -61,13 +70,20 @@ /*! * @brief Convert the thermistor resistance into equivalent temperature using - * Steinhart-Hart equation for 10K 44031 NTC + * Steinhart-Hart equation Or Beta value for 10K 44031 NTC * @param resistance[in] - thermistor resistance - * @return Thermistor temperature value + * @return Thermistor temperature value in Celcius */ float ntc_10k_44031rc::convert(const float resistance) { +#if defined(NTC_10K_44031_CONVERT_USING_BETA_VALUE) + float temperature; + temperature = (1 / ((log(resistance / NTC_10K_44031_RESISTANCE_AT_25C) / + NTC_10K_44031_BETA_VALUE) + (1 / NTC_10K_44031_ROOM_TEMP_IN_KELVIN))) - 273.15; + return temperature; +#else return thermistor::convert(resistance, coeff_A, coeff_B, coeff_C); +#endif }