IIO firmware for the AD4110

Dependencies:   tempsensors sdp_k1_sdram

Committer:
Janani Sunil
Date:
Wed Jul 27 17:04:15 2022 +0530
Revision:
0:6ca37a8f8ba9
Initial implementation for AD4110 IIO Firmware

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Janani Sunil 0:6ca37a8f8ba9 1 /***************************************************************************//*
Janani Sunil 0:6ca37a8f8ba9 2 * @file ad4110_temperature_sensor.cpp
Janani Sunil 0:6ca37a8f8ba9 3 * @brief AD4110 temperature sensor functionality
Janani Sunil 0:6ca37a8f8ba9 4 * @details
Janani Sunil 0:6ca37a8f8ba9 5 ******************************************************************************
Janani Sunil 0:6ca37a8f8ba9 6 * Copyright (c) 2022 Analog Devices, Inc. All Rights Reserved.
Janani Sunil 0:6ca37a8f8ba9 7 *
Janani Sunil 0:6ca37a8f8ba9 8 * This software is proprietary to Analog Devices, Inc. and its licensors.
Janani Sunil 0:6ca37a8f8ba9 9 * By using this software you agree to the terms of the associated
Janani Sunil 0:6ca37a8f8ba9 10 * Analog Devices Software License Agreement.
Janani Sunil 0:6ca37a8f8ba9 11 ******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 12
Janani Sunil 0:6ca37a8f8ba9 13 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 14 /***************************** Include Files **********************************/
Janani Sunil 0:6ca37a8f8ba9 15 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 16
Janani Sunil 0:6ca37a8f8ba9 17 #include <stdint.h>
Janani Sunil 0:6ca37a8f8ba9 18 #include <ptxxx.h>
Janani Sunil 0:6ca37a8f8ba9 19 #include <thermocouple.h>
Janani Sunil 0:6ca37a8f8ba9 20 #include "ad4110_temperature_sensor.h"
Janani Sunil 0:6ca37a8f8ba9 21
Janani Sunil 0:6ca37a8f8ba9 22 #ifdef __cplusplus
Janani Sunil 0:6ca37a8f8ba9 23 extern "C"
Janani Sunil 0:6ca37a8f8ba9 24 {
Janani Sunil 0:6ca37a8f8ba9 25 #endif // _cplusplus
Janani Sunil 0:6ca37a8f8ba9 26
Janani Sunil 0:6ca37a8f8ba9 27 #include "app_config.h"
Janani Sunil 0:6ca37a8f8ba9 28 #include "ad4110_support.h"
Janani Sunil 0:6ca37a8f8ba9 29
Janani Sunil 0:6ca37a8f8ba9 30 #ifdef __cplusplus // Closing extern c
Janani Sunil 0:6ca37a8f8ba9 31 }
Janani Sunil 0:6ca37a8f8ba9 32 #endif // _cplusplus
Janani Sunil 0:6ca37a8f8ba9 33
Janani Sunil 0:6ca37a8f8ba9 34 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 35 /********************* Macros and Constants Definitions ***********************/
Janani Sunil 0:6ca37a8f8ba9 36 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 37
Janani Sunil 0:6ca37a8f8ba9 38 /* NTC thermistor Rsense value (in ohms) */
Janani Sunil 0:6ca37a8f8ba9 39 #define NTC_RSENSE 10000U
Janani Sunil 0:6ca37a8f8ba9 40
Janani Sunil 0:6ca37a8f8ba9 41 /* RTD Rref Resistance value (in ohms) */
Janani Sunil 0:6ca37a8f8ba9 42 #define RTD_RREF 25000U
Janani Sunil 0:6ca37a8f8ba9 43
Janani Sunil 0:6ca37a8f8ba9 44 /* Lead resistance value (in ohms)
Janani Sunil 0:6ca37a8f8ba9 45 * NOTE: There is an RC filter configuration physically in series with the AIN+
Janani Sunil 0:6ca37a8f8ba9 46 * and AIN- terminals, (10 + 10 ohms) that needs to be compensated for during conversion. */
Janani Sunil 0:6ca37a8f8ba9 47 #define LEAD_RESISTANCE 20
Janani Sunil 0:6ca37a8f8ba9 48
Janani Sunil 0:6ca37a8f8ba9 49 /* Scale factor for TMP36 used for CJC */
Janani Sunil 0:6ca37a8f8ba9 50 #define TMP36_SCALE 0.03
Janani Sunil 0:6ca37a8f8ba9 51
Janani Sunil 0:6ca37a8f8ba9 52 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 53 /******************** Variables and User Defined Data Types *******************/
Janani Sunil 0:6ca37a8f8ba9 54 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 55
Janani Sunil 0:6ca37a8f8ba9 56 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 57 /************************** Functions Definitions *****************************/
Janani Sunil 0:6ca37a8f8ba9 58 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 59
Janani Sunil 0:6ca37a8f8ba9 60 /**
Janani Sunil 0:6ca37a8f8ba9 61 * @brief Convert ADC raw value into equivalent RTD temperature
Janani Sunil 0:6ca37a8f8ba9 62 * @param rtd_sample[in] - Raw ADC sample for RTD sensor
Janani Sunil 0:6ca37a8f8ba9 63 * @return RTD temperature
Janani Sunil 0:6ca37a8f8ba9 64 * @note Fixed PT100 RTD sensor is used
Janani Sunil 0:6ca37a8f8ba9 65 */
Janani Sunil 0:6ca37a8f8ba9 66 float get_rtd_temperature(uint32_t rtd_sample)
Janani Sunil 0:6ca37a8f8ba9 67 {
Janani Sunil 0:6ca37a8f8ba9 68 PT100 rtd_sensor;
Janani Sunil 0:6ca37a8f8ba9 69 float rtd_resistance;
Janani Sunil 0:6ca37a8f8ba9 70
Janani Sunil 0:6ca37a8f8ba9 71 rtd_resistance = convert_adc_raw_into_rtd_resistance(rtd_sample, RTD_RREF);
Janani Sunil 0:6ca37a8f8ba9 72 /* The lead resistance value is compensated to achieve accuracy in resistance and temperature
Janani Sunil 0:6ca37a8f8ba9 73 measurement */
Janani Sunil 0:6ca37a8f8ba9 74 rtd_resistance = rtd_resistance - LEAD_RESISTANCE;
Janani Sunil 0:6ca37a8f8ba9 75 return rtd_sensor.convertResistanceToTemperature(rtd_resistance);
Janani Sunil 0:6ca37a8f8ba9 76 }
Janani Sunil 0:6ca37a8f8ba9 77
Janani Sunil 0:6ca37a8f8ba9 78
Janani Sunil 0:6ca37a8f8ba9 79 /**
Janani Sunil 0:6ca37a8f8ba9 80 * @brief Convert ADC raw value into TC temperature
Janani Sunil 0:6ca37a8f8ba9 81 * @param tc_sample[in] - Raw TC sample
Janani Sunil 0:6ca37a8f8ba9 82 * @param tc_channel[in] - Thermocouple channel
Janani Sunil 0:6ca37a8f8ba9 83 * @param cjc_sample[in] - Raw CJC sample
Janani Sunil 0:6ca37a8f8ba9 84 * @param cjc_channel[in - CJC channel
Janani Sunil 0:6ca37a8f8ba9 85 * @param cjc_temp[in, out] - CJC temperature value
Janani Sunil 0:6ca37a8f8ba9 86 * @return TC temperature
Janani Sunil 0:6ca37a8f8ba9 87 * @note T type thermocouple used, on board TMP36 is used for CJC.
Janani Sunil 0:6ca37a8f8ba9 88 */
Janani Sunil 0:6ca37a8f8ba9 89 float get_tc_temperature(uint32_t tc_sample, uint8_t tc_channel,
Janani Sunil 0:6ca37a8f8ba9 90 uint32_t cjc_sample, uint8_t cjc_channel,
Janani Sunil 0:6ca37a8f8ba9 91 float *cjc_temp)
Janani Sunil 0:6ca37a8f8ba9 92 {
Janani Sunil 0:6ca37a8f8ba9 93 Thermocouple_Type_T tcSensor;
Janani Sunil 0:6ca37a8f8ba9 94 float tc_mv;
Janani Sunil 0:6ca37a8f8ba9 95 volatile float cjc_mv;
Janani Sunil 0:6ca37a8f8ba9 96 float tc_temperature;
Janani Sunil 0:6ca37a8f8ba9 97 float cjc_temperature;
Janani Sunil 0:6ca37a8f8ba9 98
Janani Sunil 0:6ca37a8f8ba9 99 /* Thermocouple temperature calculation */
Janani Sunil 0:6ca37a8f8ba9 100 tc_mv = convert_adc_sample_into_voltage(tc_sample, tc_channel) * 1000;
Janani Sunil 0:6ca37a8f8ba9 101 tc_temperature = tcSensor.convert(tc_mv);
Janani Sunil 0:6ca37a8f8ba9 102
Janani Sunil 0:6ca37a8f8ba9 103 /* CJC Temperature calculation */
Janani Sunil 0:6ca37a8f8ba9 104 cjc_mv = convert_adc_sample_into_voltage(cjc_sample, cjc_channel) * 1000;
Janani Sunil 0:6ca37a8f8ba9 105 cjc_temperature = TMP36_SCALE * cjc_mv;
Janani Sunil 0:6ca37a8f8ba9 106
Janani Sunil 0:6ca37a8f8ba9 107 /* Get the CJC temperature */
Janani Sunil 0:6ca37a8f8ba9 108 *cjc_temp = cjc_temperature;
Janani Sunil 0:6ca37a8f8ba9 109
Janani Sunil 0:6ca37a8f8ba9 110 return (tc_temperature + cjc_temperature);
Janani Sunil 0:6ca37a8f8ba9 111 }