Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: tempsensors adi_console_menu platform_drivers
app/ad7124_temperature_sensor.cpp@3:f20f09251190, 2021-03-19 (annotated)
- Committer:
- mahphalke
- Date:
- Fri Mar 19 14:34:05 2021 +0530
- Revision:
- 3:f20f09251190
- Parent:
- 1:c863d7e9e272
Updates w.r.t temperature measurement display schemes
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mahphalke | 1:c863d7e9e272 | 1 | |
| mahphalke | 1:c863d7e9e272 | 2 | /***************************************************************************//* |
| mahphalke | 1:c863d7e9e272 | 3 | * @file ad7124_temperature_sensor.cpp |
| mahphalke | 1:c863d7e9e272 | 4 | * @brief AD7124 temperature sensor functionality |
| mahphalke | 1:c863d7e9e272 | 5 | * @details |
| mahphalke | 1:c863d7e9e272 | 6 | ****************************************************************************** |
| mahphalke | 1:c863d7e9e272 | 7 | * Copyright (c) 2021 Analog Devices, Inc. All Rights Reserved. |
| mahphalke | 1:c863d7e9e272 | 8 | * |
| mahphalke | 1:c863d7e9e272 | 9 | * This software is proprietary to Analog Devices, Inc. and its licensors. |
| mahphalke | 1:c863d7e9e272 | 10 | * By using this software you agree to the terms of the associated |
| mahphalke | 1:c863d7e9e272 | 11 | * Analog Devices Software License Agreement. |
| mahphalke | 1:c863d7e9e272 | 12 | ******************************************************************************/ |
| mahphalke | 1:c863d7e9e272 | 13 | |
| mahphalke | 1:c863d7e9e272 | 14 | /******************************************************************************/ |
| mahphalke | 1:c863d7e9e272 | 15 | /***************************** Include Files **********************************/ |
| mahphalke | 1:c863d7e9e272 | 16 | /******************************************************************************/ |
| mahphalke | 1:c863d7e9e272 | 17 | |
| mahphalke | 1:c863d7e9e272 | 18 | #include <stdint.h> |
| mahphalke | 1:c863d7e9e272 | 19 | #include <math.h> |
| mahphalke | 1:c863d7e9e272 | 20 | |
| mahphalke | 1:c863d7e9e272 | 21 | #include <thermocouple.h> |
| mahphalke | 1:c863d7e9e272 | 22 | #include <ptxxx.h> |
| mahphalke | 1:c863d7e9e272 | 23 | #include <ntc_10k_44031.h> |
| mahphalke | 1:c863d7e9e272 | 24 | #include <ptc_ky81_110.h> |
| mahphalke | 1:c863d7e9e272 | 25 | |
| mahphalke | 1:c863d7e9e272 | 26 | #include "ad7124_temperature_sensor.h" |
| mahphalke | 1:c863d7e9e272 | 27 | |
| mahphalke | 1:c863d7e9e272 | 28 | #ifdef __cplusplus |
| mahphalke | 1:c863d7e9e272 | 29 | extern "C" |
| mahphalke | 1:c863d7e9e272 | 30 | { |
| mahphalke | 1:c863d7e9e272 | 31 | #endif // _cplusplus |
| mahphalke | 1:c863d7e9e272 | 32 | |
| mahphalke | 1:c863d7e9e272 | 33 | #include "ad7124_regs_configs.h" |
| mahphalke | 1:c863d7e9e272 | 34 | #include "ad7124_support.h" |
| mahphalke | 1:c863d7e9e272 | 35 | |
| mahphalke | 1:c863d7e9e272 | 36 | #ifdef __cplusplus // Closing extern c |
| mahphalke | 1:c863d7e9e272 | 37 | } |
| mahphalke | 1:c863d7e9e272 | 38 | #endif // _cplusplus |
| mahphalke | 1:c863d7e9e272 | 39 | |
| mahphalke | 1:c863d7e9e272 | 40 | /******************************************************************************/ |
| mahphalke | 1:c863d7e9e272 | 41 | /********************* Macros and Constants Definitions ***********************/ |
| mahphalke | 1:c863d7e9e272 | 42 | /******************************************************************************/ |
| mahphalke | 1:c863d7e9e272 | 43 | |
| mahphalke | 1:c863d7e9e272 | 44 | /* NTC thermistor Rsense value (in ohms) */ |
| mahphalke |
3:f20f09251190 | 45 | #define NTC_RSENSE 10000U |
| mahphalke |
3:f20f09251190 | 46 | |
| mahphalke |
3:f20f09251190 | 47 | /* RTD Rref Resistance value (in ohms) */ |
| mahphalke |
3:f20f09251190 | 48 | #define RTD_RREF 5110U |
| mahphalke | 1:c863d7e9e272 | 49 | |
| mahphalke | 1:c863d7e9e272 | 50 | /* PTC thermistor Ref Resistance value (in ohms) */ |
| mahphalke |
3:f20f09251190 | 51 | #define PTC_RREF 5110U |
| mahphalke | 1:c863d7e9e272 | 52 | |
| mahphalke | 1:c863d7e9e272 | 53 | /******************************************************************************/ |
| mahphalke | 1:c863d7e9e272 | 54 | /******************** Variables and User Defined Data Types *******************/ |
| mahphalke | 1:c863d7e9e272 | 55 | /******************************************************************************/ |
| mahphalke | 1:c863d7e9e272 | 56 | |
| mahphalke | 1:c863d7e9e272 | 57 | /* Calibration constant (iout ratio) for RTD resistance measurement */ |
| mahphalke | 1:c863d7e9e272 | 58 | static float calibration_iout_ratio = 1; |
| mahphalke | 1:c863d7e9e272 | 59 | |
| mahphalke | 1:c863d7e9e272 | 60 | /******************************************************************************/ |
| mahphalke | 1:c863d7e9e272 | 61 | /************************** Functions Definitions *****************************/ |
| mahphalke | 1:c863d7e9e272 | 62 | /******************************************************************************/ |
| mahphalke | 1:c863d7e9e272 | 63 | |
| mahphalke | 1:c863d7e9e272 | 64 | /*! |
| mahphalke | 1:c863d7e9e272 | 65 | * @brief Convert the ADC raw value into equivalent RTD resistance |
| mahphalke | 1:c863d7e9e272 | 66 | * @param adc_raw[in]- ADC raw sample |
| mahphalke |
3:f20f09251190 | 67 | * @param gain[in] - RTD gain |
| mahphalke | 1:c863d7e9e272 | 68 | * @return RTD resistance value |
| mahphalke | 1:c863d7e9e272 | 69 | * @note RTD is biased with constant excitation current. Below formula |
| mahphalke | 1:c863d7e9e272 | 70 | * is based on ratiometric measurement, where fixed value of RTD RREF |
| mahphalke | 1:c863d7e9e272 | 71 | * (reference resistor) and gain is taken into account |
| mahphalke | 1:c863d7e9e272 | 72 | */ |
| mahphalke |
3:f20f09251190 | 73 | static float convert_adc_raw_into_rtd_resistance(int32_t adc_raw, uint8_t gain) |
| mahphalke | 1:c863d7e9e272 | 74 | { |
| mahphalke | 1:c863d7e9e272 | 75 | float rtd_res; |
| mahphalke | 1:c863d7e9e272 | 76 | |
| mahphalke | 1:c863d7e9e272 | 77 | /* Below equation is for bipolar inputs as all ADC configurations for |
| mahphalke | 1:c863d7e9e272 | 78 | * sensor measurement are having default bipolar mode */ |
| mahphalke | 1:c863d7e9e272 | 79 | rtd_res = (((float)adc_raw - (1 << (AD7124_ADC_N_BITS - 1))) * |
| mahphalke | 1:c863d7e9e272 | 80 | (calibration_iout_ratio * RTD_RREF)) / (( |
| mahphalke |
3:f20f09251190 | 81 | AD7124_PGA_GAIN(gain)) * (1 << (AD7124_ADC_N_BITS - 1))); |
| mahphalke | 1:c863d7e9e272 | 82 | |
| mahphalke | 1:c863d7e9e272 | 83 | return rtd_res; |
| mahphalke | 1:c863d7e9e272 | 84 | } |
| mahphalke | 1:c863d7e9e272 | 85 | |
| mahphalke | 1:c863d7e9e272 | 86 | |
| mahphalke | 1:c863d7e9e272 | 87 | /*! |
| mahphalke | 1:c863d7e9e272 | 88 | * @brief Store the RTD calibration Iout ratio for 3-wire RTD calibration |
| mahphalke | 1:c863d7e9e272 | 89 | * based measurement |
| mahphalke | 1:c863d7e9e272 | 90 | * @param iout_ratio[in]- Iout1/Iout0 ratio |
| mahphalke | 1:c863d7e9e272 | 91 | * @param status[in] - Calibration ratio set/reset flag |
| mahphalke | 1:c863d7e9e272 | 92 | * @return none |
| mahphalke | 1:c863d7e9e272 | 93 | */ |
| mahphalke | 1:c863d7e9e272 | 94 | void store_rtd_calibrated_iout_ratio(float iout_ratio, bool status) |
| mahphalke | 1:c863d7e9e272 | 95 | { |
| mahphalke | 1:c863d7e9e272 | 96 | if (status) { |
| mahphalke | 1:c863d7e9e272 | 97 | calibration_iout_ratio = 1 + iout_ratio; |
| mahphalke | 1:c863d7e9e272 | 98 | } else { |
| mahphalke | 1:c863d7e9e272 | 99 | calibration_iout_ratio = 1; |
| mahphalke | 1:c863d7e9e272 | 100 | } |
| mahphalke | 1:c863d7e9e272 | 101 | } |
| mahphalke | 1:c863d7e9e272 | 102 | |
| mahphalke | 1:c863d7e9e272 | 103 | |
| mahphalke | 1:c863d7e9e272 | 104 | /*! |
| mahphalke | 1:c863d7e9e272 | 105 | * @brief Convert the ADC raw value into equivalent PTC thermistor resistance |
| mahphalke | 1:c863d7e9e272 | 106 | * @param adc_raw[in]- ADC raw sample |
| mahphalke | 1:c863d7e9e272 | 107 | * @return PTC resistance value |
| mahphalke | 1:c863d7e9e272 | 108 | * @note PTC is biased with constant excitation current. Below formula |
| mahphalke | 1:c863d7e9e272 | 109 | * is based on ratiometric measurement, where fixed value of PTC RREF |
| mahphalke | 1:c863d7e9e272 | 110 | * (reference resistor) and gain is taken into account |
| mahphalke | 1:c863d7e9e272 | 111 | */ |
| mahphalke | 1:c863d7e9e272 | 112 | static float convert_adc_raw_into_ptc_resistance(int32_t adc_raw) |
| mahphalke | 1:c863d7e9e272 | 113 | { |
| mahphalke | 1:c863d7e9e272 | 114 | float ptc_res; |
| mahphalke | 1:c863d7e9e272 | 115 | |
| mahphalke | 1:c863d7e9e272 | 116 | /* Below equation is for bipolar inputs as all ADC configurations for |
| mahphalke | 1:c863d7e9e272 | 117 | * sensor measurement are having default bipolar mode */ |
| mahphalke | 1:c863d7e9e272 | 118 | ptc_res = (((float)adc_raw - (1 << (AD7124_ADC_N_BITS - 1))) * PTC_RREF) / (( |
| mahphalke | 1:c863d7e9e272 | 119 | AD7124_PGA_GAIN(THERMISTOR_GAIN_VALUE)) * (1 << (AD7124_ADC_N_BITS - 1))); |
| mahphalke | 1:c863d7e9e272 | 120 | |
| mahphalke | 1:c863d7e9e272 | 121 | return ptc_res; |
| mahphalke | 1:c863d7e9e272 | 122 | } |
| mahphalke | 1:c863d7e9e272 | 123 | |
| mahphalke | 1:c863d7e9e272 | 124 | |
| mahphalke | 1:c863d7e9e272 | 125 | /*! |
| mahphalke | 1:c863d7e9e272 | 126 | * @brief Convert the ADC raw value into equivalent NTC thermistor voltage |
| mahphalke | 1:c863d7e9e272 | 127 | * @param adc_raw[in]- ADC raw sample |
| mahphalke | 1:c863d7e9e272 | 128 | * @return NTC Thermistor voltage value |
| mahphalke | 1:c863d7e9e272 | 129 | * @note The NTC is biased with constant ADC reference voltage. Below formula |
| mahphalke | 1:c863d7e9e272 | 130 | * is based on ratiometric measurement, where fixed value of ADC REF |
| mahphalke | 1:c863d7e9e272 | 131 | * and gain is taken into account |
| mahphalke | 1:c863d7e9e272 | 132 | */ |
| mahphalke | 1:c863d7e9e272 | 133 | static float convert_adc_raw_into_ntc_voltage(int32_t adc_raw) |
| mahphalke | 1:c863d7e9e272 | 134 | { |
| mahphalke | 1:c863d7e9e272 | 135 | float ntc_voltage; |
| mahphalke | 1:c863d7e9e272 | 136 | |
| mahphalke | 1:c863d7e9e272 | 137 | /* Below equation is for bipolar inputs as all ADC configurations for |
| mahphalke | 1:c863d7e9e272 | 138 | * sensor measurement are having default bipolar mode */ |
| mahphalke | 1:c863d7e9e272 | 139 | ntc_voltage = (((float)adc_raw - (1 << (AD7124_ADC_N_BITS - 1))) * |
| mahphalke | 1:c863d7e9e272 | 140 | AD7124_REF_VOLTAGE) / (( |
| mahphalke | 1:c863d7e9e272 | 141 | AD7124_PGA_GAIN(THERMISTOR_GAIN_VALUE)) * (1 << (AD7124_ADC_N_BITS - 1))); |
| mahphalke | 1:c863d7e9e272 | 142 | |
| mahphalke | 1:c863d7e9e272 | 143 | return ntc_voltage; |
| mahphalke | 1:c863d7e9e272 | 144 | } |
| mahphalke | 1:c863d7e9e272 | 145 | |
| mahphalke | 1:c863d7e9e272 | 146 | |
| mahphalke | 1:c863d7e9e272 | 147 | /*! |
| mahphalke | 1:c863d7e9e272 | 148 | * @brief Convert the NTC thermistor voltage into equivalent resistance |
| mahphalke | 1:c863d7e9e272 | 149 | * @param voltage[in]- NTC Thermistor voltage |
| mahphalke | 1:c863d7e9e272 | 150 | * @return NTC Thermistor resistance value |
| mahphalke | 1:c863d7e9e272 | 151 | */ |
| mahphalke | 1:c863d7e9e272 | 152 | static float convert_ntc_voltage_into_resistance(float ntc_voltage) |
| mahphalke | 1:c863d7e9e272 | 153 | { |
| mahphalke | 1:c863d7e9e272 | 154 | float ntc_resistance = (ntc_voltage * NTC_RSENSE) / (AD7124_REF_VOLTAGE - |
| mahphalke | 1:c863d7e9e272 | 155 | ntc_voltage); |
| mahphalke | 1:c863d7e9e272 | 156 | return ntc_resistance; |
| mahphalke | 1:c863d7e9e272 | 157 | } |
| mahphalke | 1:c863d7e9e272 | 158 | |
| mahphalke | 1:c863d7e9e272 | 159 | |
| mahphalke | 1:c863d7e9e272 | 160 | /** |
| mahphalke | 1:c863d7e9e272 | 161 | * @brief Converts raw ADC code to millivolts |
| mahphalke | 1:c863d7e9e272 | 162 | * @param raw_adc_code[in] Raw ADC code |
| mahphalke | 1:c863d7e9e272 | 163 | * @return voltage in millivolts |
| mahphalke | 1:c863d7e9e272 | 164 | * @details This converts the raw ADC code to millivolts for thermocouple channel, |
| mahphalke | 1:c863d7e9e272 | 165 | * based on the AD7124 Eval board configuration |
| mahphalke | 1:c863d7e9e272 | 166 | */ |
| mahphalke | 1:c863d7e9e272 | 167 | static float convert_raw_adc_into_tc_mv(uint32_t raw_adc_code) |
| mahphalke | 1:c863d7e9e272 | 168 | { |
| mahphalke | 1:c863d7e9e272 | 169 | return (((((float)raw_adc_code - (1 << (AD7124_ADC_N_BITS - 1))) / |
| mahphalke | 1:c863d7e9e272 | 170 | (AD7124_PGA_GAIN(THERMOCOUPLE_GAIN_VALUE) * |
| mahphalke | 1:c863d7e9e272 | 171 | (1 << (AD7124_ADC_N_BITS - 1)))) * AD7124_REF_VOLTAGE) * 1000); |
| mahphalke | 1:c863d7e9e272 | 172 | } |
| mahphalke | 1:c863d7e9e272 | 173 | |
| mahphalke | 1:c863d7e9e272 | 174 | |
| mahphalke |
3:f20f09251190 | 175 | |
| mahphalke |
3:f20f09251190 | 176 | /** |
| mahphalke |
3:f20f09251190 | 177 | * @brief Get the RTD reference resistor value |
| mahphalke |
3:f20f09251190 | 178 | * @return RTD reference resistor value |
| mahphalke |
3:f20f09251190 | 179 | */ |
| mahphalke |
3:f20f09251190 | 180 | uint32_t get_rtd_rref(void) |
| mahphalke |
3:f20f09251190 | 181 | { |
| mahphalke |
3:f20f09251190 | 182 | return RTD_RREF; |
| mahphalke |
3:f20f09251190 | 183 | } |
| mahphalke |
3:f20f09251190 | 184 | |
| mahphalke |
3:f20f09251190 | 185 | |
| mahphalke | 1:c863d7e9e272 | 186 | /** |
| mahphalke | 1:c863d7e9e272 | 187 | * @brief Convert ADC raw value into TC temperature |
| mahphalke | 1:c863d7e9e272 | 188 | * @param tc_sample[in] Raw TC sample |
| mahphalke | 1:c863d7e9e272 | 189 | * @param cjc_sample[in] Raw CJC sample |
| mahphalke | 1:c863d7e9e272 | 190 | * @param cjc_sensor[in] CJC sensor type |
| mahphalke |
3:f20f09251190 | 191 | * @param cjc_temp[in] CJC temperature value |
| mahphalke | 1:c863d7e9e272 | 192 | * @return TC temperature |
| mahphalke | 1:c863d7e9e272 | 193 | */ |
| mahphalke | 1:c863d7e9e272 | 194 | float get_tc_temperature(float tc_sample, float cjc_sample, |
| mahphalke |
3:f20f09251190 | 195 | cjc_sensor_type cjc_sensor, float *cjc_temp) |
| mahphalke | 1:c863d7e9e272 | 196 | { |
| mahphalke | 1:c863d7e9e272 | 197 | Thermocouple_Type_T tcSensor; |
| mahphalke | 1:c863d7e9e272 | 198 | float tc_mv; |
| mahphalke | 1:c863d7e9e272 | 199 | float tc_temperature; |
| mahphalke | 1:c863d7e9e272 | 200 | float cjc_temperature; |
| mahphalke | 1:c863d7e9e272 | 201 | |
| mahphalke | 1:c863d7e9e272 | 202 | tc_mv = convert_raw_adc_into_tc_mv(tc_sample); |
| mahphalke | 1:c863d7e9e272 | 203 | tc_temperature = tcSensor.convert(tc_mv); |
| mahphalke | 1:c863d7e9e272 | 204 | |
| mahphalke | 1:c863d7e9e272 | 205 | if (cjc_sensor == PT100_4WIRE_RTD) { |
| mahphalke |
3:f20f09251190 | 206 | cjc_temperature = get_rtd_temperature(cjc_sample, RTD_4WIRE_GAIN_VALUE); |
| mahphalke | 1:c863d7e9e272 | 207 | } else if (cjc_sensor == THERMISTOR_PTC_KY81_110) { |
| mahphalke | 1:c863d7e9e272 | 208 | cjc_temperature = get_ptc_thermistor_temperature(cjc_sample); |
| mahphalke |
3:f20f09251190 | 209 | } else if (cjc_sensor == PT1000_2WIRE_RTD) { |
| mahphalke | 1:c863d7e9e272 | 210 | PT1000 rtd_sensor; |
| mahphalke | 1:c863d7e9e272 | 211 | float rtd_resistance; |
| mahphalke | 1:c863d7e9e272 | 212 | |
| mahphalke |
3:f20f09251190 | 213 | rtd_resistance = convert_adc_raw_into_rtd_resistance(cjc_sample, |
| mahphalke |
3:f20f09251190 | 214 | RTD_PT1000_GAIN_VALUE); |
| mahphalke | 1:c863d7e9e272 | 215 | cjc_temperature = rtd_sensor.convertResistanceToTemperature(rtd_resistance); |
| mahphalke | 1:c863d7e9e272 | 216 | } else { |
| mahphalke | 1:c863d7e9e272 | 217 | return 0; |
| mahphalke | 1:c863d7e9e272 | 218 | } |
| mahphalke | 1:c863d7e9e272 | 219 | |
| mahphalke |
3:f20f09251190 | 220 | /* Get the CJC temperature */ |
| mahphalke |
3:f20f09251190 | 221 | *cjc_temp = cjc_temperature; |
| mahphalke |
3:f20f09251190 | 222 | |
| mahphalke | 1:c863d7e9e272 | 223 | /* NOTE The simplest approach of adding the CJC temperature to TC temperature is taken here. |
| mahphalke | 1:c863d7e9e272 | 224 | * A better method is to convert RTD back to thermocouple mV, and add that to TC value |
| mahphalke | 1:c863d7e9e272 | 225 | * then do the thermocouple to degC conversion. |
| mahphalke | 1:c863d7e9e272 | 226 | * */ |
| mahphalke | 1:c863d7e9e272 | 227 | return (tc_temperature + cjc_temperature); |
| mahphalke | 1:c863d7e9e272 | 228 | } |
| mahphalke | 1:c863d7e9e272 | 229 | |
| mahphalke | 1:c863d7e9e272 | 230 | |
| mahphalke | 1:c863d7e9e272 | 231 | /** |
| mahphalke | 1:c863d7e9e272 | 232 | * @brief Convert ADC raw value into RTD temperature |
| mahphalke | 1:c863d7e9e272 | 233 | * @param rtd_sample[in] Raw RTD sample |
| mahphalke |
3:f20f09251190 | 234 | * @pram gain[in] RTD gain |
| mahphalke | 1:c863d7e9e272 | 235 | * @return RTD temperature |
| mahphalke | 1:c863d7e9e272 | 236 | * @note Fixed PT100 RTD sensor is used |
| mahphalke | 1:c863d7e9e272 | 237 | */ |
| mahphalke |
3:f20f09251190 | 238 | float get_rtd_temperature(int32_t rtd_sample, uint8_t gain) |
| mahphalke | 1:c863d7e9e272 | 239 | { |
| mahphalke | 1:c863d7e9e272 | 240 | PT100 rtd_sensor; |
| mahphalke | 1:c863d7e9e272 | 241 | float rtd_resistance; |
| mahphalke | 1:c863d7e9e272 | 242 | |
| mahphalke |
3:f20f09251190 | 243 | rtd_resistance = convert_adc_raw_into_rtd_resistance(rtd_sample, gain); |
| mahphalke | 1:c863d7e9e272 | 244 | |
| mahphalke | 1:c863d7e9e272 | 245 | return rtd_sensor.convertResistanceToTemperature(rtd_resistance); |
| mahphalke | 1:c863d7e9e272 | 246 | } |
| mahphalke | 1:c863d7e9e272 | 247 | |
| mahphalke | 1:c863d7e9e272 | 248 | |
| mahphalke | 1:c863d7e9e272 | 249 | /** |
| mahphalke | 1:c863d7e9e272 | 250 | * @brief Convert ADC raw value into NTC temperature |
| mahphalke | 1:c863d7e9e272 | 251 | * @param ntc_sample[in] Raw NTC sample |
| mahphalke | 1:c863d7e9e272 | 252 | * @return NTC temperature |
| mahphalke | 1:c863d7e9e272 | 253 | * @note Fixed NTC 10K 44031RC sensor is used |
| mahphalke | 1:c863d7e9e272 | 254 | */ |
| mahphalke | 1:c863d7e9e272 | 255 | float get_ntc_thermistor_temperature(int32_t ntc_sample) |
| mahphalke | 1:c863d7e9e272 | 256 | { |
| mahphalke | 1:c863d7e9e272 | 257 | ntc_10k_44031rc ntc_thermistor; |
| mahphalke | 1:c863d7e9e272 | 258 | float ntc_voltage; |
| mahphalke | 1:c863d7e9e272 | 259 | float ntc_resistance; |
| mahphalke | 1:c863d7e9e272 | 260 | |
| mahphalke | 1:c863d7e9e272 | 261 | ntc_voltage = convert_adc_raw_into_ntc_voltage(ntc_sample); |
| mahphalke | 1:c863d7e9e272 | 262 | ntc_resistance = convert_ntc_voltage_into_resistance(ntc_voltage); |
| mahphalke | 1:c863d7e9e272 | 263 | |
| mahphalke | 1:c863d7e9e272 | 264 | return ntc_thermistor.convert(ntc_resistance); |
| mahphalke | 1:c863d7e9e272 | 265 | } |
| mahphalke | 1:c863d7e9e272 | 266 | |
| mahphalke | 1:c863d7e9e272 | 267 | |
| mahphalke | 1:c863d7e9e272 | 268 | /** |
| mahphalke | 1:c863d7e9e272 | 269 | * @brief Convert ADC raw value into PTC temperature |
| mahphalke | 1:c863d7e9e272 | 270 | * @param ptc_sample[in] Raw PTC sample |
| mahphalke | 1:c863d7e9e272 | 271 | * @return PTC temperature |
| mahphalke | 1:c863d7e9e272 | 272 | * @note Fixed PTC KY81/110 Thermistor sensor is used |
| mahphalke | 1:c863d7e9e272 | 273 | */ |
| mahphalke | 1:c863d7e9e272 | 274 | float get_ptc_thermistor_temperature(int32_t ptc_sample) |
| mahphalke | 1:c863d7e9e272 | 275 | { |
| mahphalke | 1:c863d7e9e272 | 276 | ptc_ky81_110 ptc_thermistor; |
| mahphalke | 1:c863d7e9e272 | 277 | float ptc_resistance; |
| mahphalke | 1:c863d7e9e272 | 278 | |
| mahphalke | 1:c863d7e9e272 | 279 | ptc_resistance = convert_adc_raw_into_ptc_resistance(ptc_sample); |
| mahphalke | 1:c863d7e9e272 | 280 | |
| mahphalke | 1:c863d7e9e272 | 281 | return ptc_thermistor.convert(ptc_resistance); |
| mahphalke | 1:c863d7e9e272 | 282 | } |