Library to support temperature sensor conversions and lookups

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?

UserRevisionLine numberNew contents of line
mahphalke 1:f65f6fadda5d 1 /*!
mahphalke 1:f65f6fadda5d 2 *****************************************************************************
mahphalke 1:f65f6fadda5d 3 @file: ptxxx.cpp
mahphalke 1:f65f6fadda5d 4
mahphalke 1:f65f6fadda5d 5 @brief:
mahphalke 1:f65f6fadda5d 6
mahphalke 1:f65f6fadda5d 7 @details:
mahphalke 1:f65f6fadda5d 8 -----------------------------------------------------------------------------
mahphalke 1:f65f6fadda5d 9 Copyright (c) 2018, 2020 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 "ptxxx.h"
mahphalke 1:f65f6fadda5d 19
mahphalke 1:f65f6fadda5d 20 #define PT1000_RESISTANCE_TO_TEMP(x) ((x-1000.0)/(0.385))
mahphalke 1:f65f6fadda5d 21
mahphalke 1:f65f6fadda5d 22
mahphalke 1:f65f6fadda5d 23 // Forward function declarations
mahphalke 1:f65f6fadda5d 24 float convertPT1000ToTemperature(const float resistance);
mahphalke 1:f65f6fadda5d 25
mahphalke 1:f65f6fadda5d 26 //class member methods
mahphalke 1:f65f6fadda5d 27
mahphalke 1:f65f6fadda5d 28 float PT100::convertResistanceToTemperature(float resistance)
mahphalke 1:f65f6fadda5d 29 {
mahphalke 1:f65f6fadda5d 30
mahphalke 1:f65f6fadda5d 31 return ( convertPT1000ToTemperature(resistance * 10) );
mahphalke 1:f65f6fadda5d 32 }
mahphalke 1:f65f6fadda5d 33
mahphalke 1:f65f6fadda5d 34
mahphalke 1:f65f6fadda5d 35 float PT1000::convertResistanceToTemperature(float resistance)
mahphalke 1:f65f6fadda5d 36 {
mahphalke 1:f65f6fadda5d 37
mahphalke 1:f65f6fadda5d 38 return ( convertPT1000ToTemperature(resistance) );
mahphalke 1:f65f6fadda5d 39 }
mahphalke 1:f65f6fadda5d 40
mahphalke 1:f65f6fadda5d 41 float convertPT1000ToTemperature(const float resistance)
mahphalke 1:f65f6fadda5d 42 {
mahphalke 1:f65f6fadda5d 43 float temperature = 25.0;
mahphalke 1:f65f6fadda5d 44
mahphalke 1:f65f6fadda5d 45 #ifdef USE_LINEAR_RTD_TEMP_EQ
mahphalke 1:f65f6fadda5d 46 temperature = PT1000_RESISTANCE_TO_TEMP(resistance);
mahphalke 1:f65f6fadda5d 47 #else
mahphalke 1:f65f6fadda5d 48
mahphalke 1:f65f6fadda5d 49 #define A (3.9083*pow(10,-3))
mahphalke 1:f65f6fadda5d 50 #define B (-5.775*pow(10,-7))
mahphalke 1:f65f6fadda5d 51 /*if(resistance < 100.0)
mahphalke 1:f65f6fadda5d 52 temperature = -242.02 + 2.228 * resistance + (2.5859 * pow(10, -3)) * pow(resistance, 2) - (48260 * pow(10, -6)) * pow(resistance, 3) - (2.8183 * pow(10, -3)) * pow(resistance, 4) + (1.5243 * pow(10, -10)) * pow(resistance, 5);
mahphalke 1:f65f6fadda5d 53 else*/
mahphalke 1:f65f6fadda5d 54 temperature = ((-A + sqrt(double(pow(A,
mahphalke 1:f65f6fadda5d 55 2) - 4 * B * (1 - resistance / 1000.0))) ) / (2 * B));
mahphalke 1:f65f6fadda5d 56 #endif
mahphalke 1:f65f6fadda5d 57 return temperature;
mahphalke 1:f65f6fadda5d 58 }
mahphalke 1:f65f6fadda5d 59
mahphalke 1:f65f6fadda5d 60
mahphalke 1:f65f6fadda5d 61
mahphalke 1:f65f6fadda5d 62
mahphalke 1:f65f6fadda5d 63
mahphalke 1:f65f6fadda5d 64