Analog Devices / Mbed OS EVAL-AD4110

Dependencies:   tempsensors sdp_k1_sdram

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ad4110_temperature_sensor.cpp Source File

ad4110_temperature_sensor.cpp

00001 /***************************************************************************//*
00002  * @file    ad4110_temperature_sensor.cpp
00003  * @brief   AD4110 temperature sensor functionality
00004  * @details
00005 ******************************************************************************
00006  * Copyright (c) 2022 Analog Devices, Inc. All Rights Reserved.
00007  *
00008  * This software is proprietary to Analog Devices, Inc. and its licensors.
00009  * By using this software you agree to the terms of the associated
00010  * Analog Devices Software License Agreement.
00011 ******************************************************************************/
00012 
00013 /******************************************************************************/
00014 /***************************** Include Files **********************************/
00015 /******************************************************************************/
00016 
00017 #include <stdint.h>
00018 #include <ptxxx.h>
00019 #include <thermocouple.h>
00020 #include "ad4110_temperature_sensor.h"
00021 
00022 #ifdef __cplusplus
00023 extern "C"
00024 {
00025 #endif //  _cplusplus
00026 
00027 #include "app_config.h"
00028 #include "ad4110_support.h"
00029 
00030 #ifdef __cplusplus  // Closing extern c
00031 }
00032 #endif //  _cplusplus
00033 
00034 /******************************************************************************/
00035 /********************* Macros and Constants Definitions ***********************/
00036 /******************************************************************************/
00037 
00038 /* NTC thermistor Rsense value (in ohms) */
00039 #define NTC_RSENSE          10000U
00040 
00041 /* RTD Rref Resistance value (in ohms) */
00042 #define RTD_RREF            25000U
00043 
00044 /* Lead resistance value (in ohms)
00045 * NOTE: There is an RC filter configuration physically in series with the AIN+
00046 * and AIN- terminals, (10 + 10 ohms) that needs to be compensated for during conversion. */
00047 #define LEAD_RESISTANCE         20
00048 
00049 /* Scale factor for TMP36 used for CJC */
00050 #define TMP36_SCALE         0.03
00051 
00052 /******************************************************************************/
00053 /******************** Variables and User Defined Data Types *******************/
00054 /******************************************************************************/
00055 
00056 /******************************************************************************/
00057 /************************** Functions Definitions *****************************/
00058 /******************************************************************************/
00059 
00060 /**
00061  * @brief Convert ADC raw value into equivalent RTD temperature
00062  * @param rtd_sample[in] - Raw ADC sample for RTD sensor
00063  * @return RTD temperature
00064  * @note Fixed PT100 RTD sensor is used
00065  */
00066 float get_rtd_temperature(uint32_t rtd_sample)
00067 {
00068     PT100 rtd_sensor;
00069     float rtd_resistance;
00070 
00071     rtd_resistance = convert_adc_raw_into_rtd_resistance(rtd_sample, RTD_RREF);
00072     /* The lead resistance value is compensated to achieve accuracy in resistance and temperature
00073     measurement */
00074     rtd_resistance = rtd_resistance - LEAD_RESISTANCE;
00075     return rtd_sensor.convertResistanceToTemperature(rtd_resistance);
00076 }
00077 
00078 
00079 /**
00080  * @brief Convert ADC raw value into TC temperature
00081  * @param tc_sample[in] - Raw TC sample
00082  * @param tc_channel[in] - Thermocouple channel
00083  * @param cjc_sample[in] - Raw CJC sample
00084  * @param cjc_channel[in - CJC channel
00085  * @param cjc_temp[in, out] - CJC temperature value
00086  * @return TC temperature
00087  * @note T type thermocouple used, on board TMP36 is used for CJC.
00088  */
00089 float get_tc_temperature(uint32_t tc_sample, uint8_t tc_channel,
00090              uint32_t cjc_sample, uint8_t cjc_channel,
00091              float *cjc_temp)
00092 {
00093     Thermocouple_Type_T tcSensor;
00094     float tc_mv;
00095     volatile float cjc_mv;
00096     float tc_temperature;
00097     float cjc_temperature;
00098 
00099     /* Thermocouple temperature calculation */
00100     tc_mv = convert_adc_sample_into_voltage(tc_sample, tc_channel) * 1000;
00101     tc_temperature = tcSensor.convert(tc_mv);
00102 
00103     /* CJC Temperature calculation */
00104     cjc_mv = convert_adc_sample_into_voltage(cjc_sample, cjc_channel) * 1000;
00105     cjc_temperature  = TMP36_SCALE * cjc_mv;
00106 
00107     /* Get the CJC temperature */
00108     *cjc_temp = cjc_temperature;
00109 
00110     return (tc_temperature + cjc_temperature);
00111 }