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: platform_drivers AD7124_no_OS adi_console_menu tempsensors_prv
app/ad7124_console_app.c@8:3d7b5897b028, 2021-03-24 (annotated)
- Committer:
- mahphalke
- Date:
- Wed Mar 24 19:48:08 2021 +0530
- Revision:
- 8:3d7b5897b028
- Parent:
- 7:ef6fffc246a6
Displaying iout average values
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mahphalke |
0:08ba94bc5a30 | 1 | /***************************************************************************//** |
| mahphalke |
0:08ba94bc5a30 | 2 | * @file ad7124_console_app.c |
| mahphalke |
0:08ba94bc5a30 | 3 | * @brief AD7124 temperature measurement firmware console interface |
| mahphalke |
0:08ba94bc5a30 | 4 | * @details This file is specific to ad7124 console menu application handle. |
| mahphalke |
0:08ba94bc5a30 | 5 | * The functions defined in this file performs the action |
| mahphalke |
0:08ba94bc5a30 | 6 | * based on user selected console menu. |
| mahphalke |
0:08ba94bc5a30 | 7 | ******************************************************************************** |
| mahphalke |
0:08ba94bc5a30 | 8 | * Copyright (c) 2021 Analog Devices, Inc. |
| mahphalke |
0:08ba94bc5a30 | 9 | * All rights reserved. |
| mahphalke |
0:08ba94bc5a30 | 10 | * |
| mahphalke |
0:08ba94bc5a30 | 11 | * This software is proprietary to Analog Devices, Inc. and its licensors. |
| mahphalke |
0:08ba94bc5a30 | 12 | * By using this software you agree to the terms of the associated |
| mahphalke |
0:08ba94bc5a30 | 13 | * Analog Devices Software License Agreement. |
| mahphalke |
0:08ba94bc5a30 | 14 | *******************************************************************************/ |
| mahphalke |
0:08ba94bc5a30 | 15 | |
| mahphalke |
0:08ba94bc5a30 | 16 | /******************************************************************************/ |
| mahphalke |
0:08ba94bc5a30 | 17 | /***************************** Include Files **********************************/ |
| mahphalke |
0:08ba94bc5a30 | 18 | /******************************************************************************/ |
| mahphalke |
0:08ba94bc5a30 | 19 | |
| mahphalke |
0:08ba94bc5a30 | 20 | #include <stdio.h> |
| mahphalke |
0:08ba94bc5a30 | 21 | #include <string.h> |
| mahphalke |
0:08ba94bc5a30 | 22 | #include <stdbool.h> |
| mahphalke |
0:08ba94bc5a30 | 23 | #include <math.h> |
| mahphalke |
0:08ba94bc5a30 | 24 | |
| mahphalke |
0:08ba94bc5a30 | 25 | #include "app_config.h" |
| mahphalke |
0:08ba94bc5a30 | 26 | |
| mahphalke |
0:08ba94bc5a30 | 27 | #include "platform_support.h" |
| mahphalke |
0:08ba94bc5a30 | 28 | #include "platform_drivers.h" |
| mahphalke |
0:08ba94bc5a30 | 29 | |
| mahphalke |
0:08ba94bc5a30 | 30 | #include "ad7124.h" |
| mahphalke |
0:08ba94bc5a30 | 31 | #include "ad7124_regs.h" |
| mahphalke |
0:08ba94bc5a30 | 32 | #include "ad7124_support.h" |
| mahphalke |
0:08ba94bc5a30 | 33 | #include "ad7124_regs_configs.h" |
| mahphalke |
0:08ba94bc5a30 | 34 | |
| mahphalke |
0:08ba94bc5a30 | 35 | #include "ad7124_console_app.h" |
| mahphalke |
0:08ba94bc5a30 | 36 | #include "ad7124_user_config.h" |
| mahphalke |
0:08ba94bc5a30 | 37 | #include "ad7124_temperature_sensor.h" |
| mahphalke |
0:08ba94bc5a30 | 38 | |
| mahphalke |
0:08ba94bc5a30 | 39 | /******************************************************************************/ |
| mahphalke |
0:08ba94bc5a30 | 40 | /********************* Macros and Constants Definitions ***********************/ |
| mahphalke |
0:08ba94bc5a30 | 41 | /******************************************************************************/ |
| mahphalke |
0:08ba94bc5a30 | 42 | |
| mahphalke |
0:08ba94bc5a30 | 43 | /* Maximum number of ADC samples for the conversion */ |
| mahphalke |
0:08ba94bc5a30 | 44 | #define MAX_ADC_SAMPLES 100 |
| mahphalke |
0:08ba94bc5a30 | 45 | |
| mahphalke |
0:08ba94bc5a30 | 46 | /* The max number of sensors connected to any AD7124 device */ |
| mahphalke |
0:08ba94bc5a30 | 47 | #define MAX_RTD_SENSORS 5 |
| mahphalke |
0:08ba94bc5a30 | 48 | #define MAX_THERMOCOUPLE_SENSORS 6 |
| mahphalke |
0:08ba94bc5a30 | 49 | #define MAX_NTC_THERMISTOR_SENSORS 8 |
| mahphalke |
0:08ba94bc5a30 | 50 | |
| mahphalke |
0:08ba94bc5a30 | 51 | /* AD7124 max input count */ |
| mahphalke |
0:08ba94bc5a30 | 52 | #if defined(AD7124_8) |
| mahphalke |
0:08ba94bc5a30 | 53 | #define AD7124_MAX_INPUTS 16 |
| mahphalke |
0:08ba94bc5a30 | 54 | #else |
| mahphalke |
0:08ba94bc5a30 | 55 | #define AD7124_MAX_INPUTS 8 |
| mahphalke |
0:08ba94bc5a30 | 56 | #endif |
| mahphalke |
0:08ba94bc5a30 | 57 | |
| mahphalke |
0:08ba94bc5a30 | 58 | /* Default offset value for AD7124 */ |
| mahphalke |
0:08ba94bc5a30 | 59 | #define AD7124_DEFAULT_OFFSET 0x800000 |
| mahphalke |
0:08ba94bc5a30 | 60 | |
| mahphalke |
0:08ba94bc5a30 | 61 | /* Max configurations (setups) used in the firmware (required for ADC calibration) */ |
| mahphalke |
0:08ba94bc5a30 | 62 | #define AD7124_MAX_CONFIGS_USED 3 // TC + CJC1 + CJC2 |
| mahphalke |
0:08ba94bc5a30 | 63 | |
| mahphalke |
0:08ba94bc5a30 | 64 | /* @brief ADC Conversion wait timeout period. |
| mahphalke |
0:08ba94bc5a30 | 65 | * @Note This value depends upon the core clock frequency. |
| mahphalke |
0:08ba94bc5a30 | 66 | * Below value is derived based on the code testing for SDP-K1 controller |
| mahphalke |
0:08ba94bc5a30 | 67 | * at default frequency and it ensures timeout period is more than 1 sec. |
| mahphalke |
0:08ba94bc5a30 | 68 | **/ |
| mahphalke |
0:08ba94bc5a30 | 69 | #define CONVERSION_TIMEOUT 10000 |
| mahphalke |
0:08ba94bc5a30 | 70 | |
| mahphalke |
0:08ba94bc5a30 | 71 | /******************************************************************************/ |
| mahphalke |
0:08ba94bc5a30 | 72 | /******************** Variables and User Defined Data Types *******************/ |
| mahphalke |
0:08ba94bc5a30 | 73 | /******************************************************************************/ |
| mahphalke |
0:08ba94bc5a30 | 74 | |
| mahphalke |
0:08ba94bc5a30 | 75 | /* |
| mahphalke |
0:08ba94bc5a30 | 76 | * This is the 'live' AD7124 register map that is used by the driver |
| mahphalke |
0:08ba94bc5a30 | 77 | * the other 'default' configs are used to populate this at init time |
| mahphalke |
0:08ba94bc5a30 | 78 | */ |
| mahphalke |
0:08ba94bc5a30 | 79 | static struct ad7124_st_reg ad7124_register_map[AD7124_REG_NO]; |
| mahphalke |
0:08ba94bc5a30 | 80 | |
| mahphalke |
0:08ba94bc5a30 | 81 | /* Pointer to the struct representing the AD7124 device */ |
| mahphalke |
0:08ba94bc5a30 | 82 | static struct ad7124_dev *p_ad7124_dev = NULL; |
| mahphalke |
0:08ba94bc5a30 | 83 | |
| mahphalke |
0:08ba94bc5a30 | 84 | /* Possible sensor configurations (mapped with enum sensor_config_ids) */ |
| mahphalke |
0:08ba94bc5a30 | 85 | static const char *sensor_configs[NUMBER_OF_SENSOR_CONFIGS] = { |
| mahphalke |
5:90166c496b01 | 86 | "RESET", |
| mahphalke |
0:08ba94bc5a30 | 87 | "2-Wire RTD", |
| mahphalke |
0:08ba94bc5a30 | 88 | "3-Wire RTD", |
| mahphalke |
0:08ba94bc5a30 | 89 | "4-Wire RTD", |
| mahphalke |
0:08ba94bc5a30 | 90 | "Thermocouple", |
| mahphalke |
0:08ba94bc5a30 | 91 | "Thermistor", |
| mahphalke |
0:08ba94bc5a30 | 92 | "ADC Calibration" |
| mahphalke |
0:08ba94bc5a30 | 93 | }; |
| mahphalke |
0:08ba94bc5a30 | 94 | |
| mahphalke |
0:08ba94bc5a30 | 95 | /* Maximum number of sensors connected to different AD7124 devices */ |
| mahphalke |
0:08ba94bc5a30 | 96 | static uint8_t max_supported_sensors[NUMBER_OF_SENSOR_CONFIGS] = { |
| mahphalke |
0:08ba94bc5a30 | 97 | #if defined (AD7124_8) |
| mahphalke |
5:90166c496b01 | 98 | 0, // RESET config |
| mahphalke |
0:08ba94bc5a30 | 99 | 5, // 2-wire RTDs |
| mahphalke |
0:08ba94bc5a30 | 100 | 4, // 3-wire RTDs |
| mahphalke |
0:08ba94bc5a30 | 101 | 5, // 4-wire RTDs |
| mahphalke |
0:08ba94bc5a30 | 102 | 6, // Thermocouples |
| mahphalke |
0:08ba94bc5a30 | 103 | 8 // Thermistors |
| mahphalke |
0:08ba94bc5a30 | 104 | #else |
| mahphalke |
5:90166c496b01 | 105 | 0, // RESET config |
| mahphalke |
0:08ba94bc5a30 | 106 | 2, // 2-wire RTDs |
| mahphalke |
0:08ba94bc5a30 | 107 | 2, // 3-wire RTDs |
| mahphalke |
0:08ba94bc5a30 | 108 | 2, // 4-wire RTDs |
| mahphalke |
0:08ba94bc5a30 | 109 | 2, // Thermocouples |
| mahphalke |
0:08ba94bc5a30 | 110 | 4 // Thermistors |
| mahphalke |
0:08ba94bc5a30 | 111 | #endif |
| mahphalke |
0:08ba94bc5a30 | 112 | }; |
| mahphalke |
0:08ba94bc5a30 | 113 | |
| mahphalke |
0:08ba94bc5a30 | 114 | /* ADC channels assigned to sensors for the measurement (each channel per sensor) */ |
| mahphalke |
0:08ba94bc5a30 | 115 | enum sensor_channels { |
| mahphalke |
0:08ba94bc5a30 | 116 | SENSOR_CHANNEL0, |
| mahphalke |
0:08ba94bc5a30 | 117 | SENSOR_CHANNEL1, |
| mahphalke |
0:08ba94bc5a30 | 118 | SENSOR_CHANNEL2, |
| mahphalke |
0:08ba94bc5a30 | 119 | SENSOR_CHANNEL3, |
| mahphalke |
0:08ba94bc5a30 | 120 | SENSOR_CHANNEL4, |
| mahphalke |
0:08ba94bc5a30 | 121 | SENSOR_CHANNEL5, |
| mahphalke |
0:08ba94bc5a30 | 122 | SENSOR_CHANNEL6, |
| mahphalke |
0:08ba94bc5a30 | 123 | SENSOR_CHANNEL7, |
| mahphalke |
0:08ba94bc5a30 | 124 | NUM_OF_SENSOR_CHANNELS |
| mahphalke |
0:08ba94bc5a30 | 125 | }; |
| mahphalke |
0:08ba94bc5a30 | 126 | |
| mahphalke |
5:90166c496b01 | 127 | /* Sensor measurement type */ |
| mahphalke |
5:90166c496b01 | 128 | typedef enum { |
| mahphalke |
5:90166c496b01 | 129 | /* Measurement with averaged ADC samples */ |
| mahphalke |
5:90166c496b01 | 130 | AVERAGED_MEASUREMENT, |
| mahphalke |
5:90166c496b01 | 131 | /* Measurement with single ADC sample */ |
| mahphalke |
5:90166c496b01 | 132 | SINGLE_MEASUREMENT, |
| mahphalke |
5:90166c496b01 | 133 | /* Continuous measurement with single ADC sample */ |
| mahphalke |
5:90166c496b01 | 134 | CONTINUOUS_MEASUREMENT |
| mahphalke |
5:90166c496b01 | 135 | } sensor_measurement_type; |
| mahphalke |
5:90166c496b01 | 136 | |
| mahphalke |
0:08ba94bc5a30 | 137 | /* Curent sensor configuration (pointer to sensor_configs string array) */ |
| mahphalke |
0:08ba94bc5a30 | 138 | static const char *current_sensor_config; |
| mahphalke |
0:08ba94bc5a30 | 139 | |
| mahphalke |
5:90166c496b01 | 140 | /* ADC raw data for n samples */ |
| mahphalke |
5:90166c496b01 | 141 | static int32_t n_sample_data[NUM_OF_SENSOR_CHANNELS][MAX_ADC_SAMPLES]; |
| mahphalke |
5:90166c496b01 | 142 | |
| mahphalke |
6:622270f7d476 | 143 | /* RTD calibraed IOUT values for n samples */ |
| mahphalke |
8:3d7b5897b028 | 144 | //static float rtd_calib_iout0[MAX_RTD_SENSORS][MAX_ADC_SAMPLES]; |
| mahphalke |
8:3d7b5897b028 | 145 | //static float rtd_calib_iout1[MAX_RTD_SENSORS][MAX_ADC_SAMPLES]; |
| mahphalke |
5:90166c496b01 | 146 | |
| mahphalke |
5:90166c496b01 | 147 | /* CJC sensor ADC raw data for n samples */ |
| mahphalke |
5:90166c496b01 | 148 | static int32_t n_cjc_sample_data[MAX_THERMOCOUPLE_SENSORS][MAX_ADC_SAMPLES]; |
| mahphalke |
5:90166c496b01 | 149 | |
| mahphalke |
0:08ba94bc5a30 | 150 | /* Status info (true/false) */ |
| mahphalke |
0:08ba94bc5a30 | 151 | static const char status_info[] = { |
| mahphalke |
0:08ba94bc5a30 | 152 | 'N', |
| mahphalke |
0:08ba94bc5a30 | 153 | 'Y' |
| mahphalke |
0:08ba94bc5a30 | 154 | }; |
| mahphalke |
0:08ba94bc5a30 | 155 | |
| mahphalke |
6:622270f7d476 | 156 | /* For storing decimal value(s) in character form */ |
| mahphalke |
6:622270f7d476 | 157 | static char decimal_eqv_str[50] = ""; |
| mahphalke |
6:622270f7d476 | 158 | static char decimal_eqv_str_arr[50 * NUM_OF_SENSOR_CHANNELS] = ""; |
| mahphalke |
0:08ba94bc5a30 | 159 | |
| mahphalke |
0:08ba94bc5a30 | 160 | /* Sensor enable status */ |
| mahphalke |
0:08ba94bc5a30 | 161 | static bool sensor_enable_status[NUM_OF_SENSOR_CHANNELS] = { |
| mahphalke |
0:08ba94bc5a30 | 162 | true, false, false, false, false, false, false, false |
| mahphalke |
0:08ba94bc5a30 | 163 | }; |
| mahphalke |
0:08ba94bc5a30 | 164 | |
| mahphalke |
0:08ba94bc5a30 | 165 | /* CJC sensor names (for thermocouple measurement) */ |
| mahphalke |
0:08ba94bc5a30 | 166 | static const char *cjc_sensor_names[NUM_OF_CJC_SENSORS] = { |
| mahphalke |
0:08ba94bc5a30 | 167 | "PT100 4-Wire RTD", |
| mahphalke |
0:08ba94bc5a30 | 168 | "Thermistor PTC KY81/110", |
| mahphalke |
5:90166c496b01 | 169 | "PT1000 2-Wire RTD", |
| mahphalke |
0:08ba94bc5a30 | 170 | }; |
| mahphalke |
0:08ba94bc5a30 | 171 | |
| mahphalke |
0:08ba94bc5a30 | 172 | /* Current selected CJC sensor */ |
| mahphalke |
0:08ba94bc5a30 | 173 | static cjc_sensor_type current_cjc_sensor = PT100_4WIRE_RTD; |
| mahphalke |
0:08ba94bc5a30 | 174 | |
| mahphalke |
0:08ba94bc5a30 | 175 | /* Below channels are configured through 'ad7124_regs_config_thermocouple' structure*/ |
| mahphalke |
0:08ba94bc5a30 | 176 | #define CJC_RTD_CHN SENSOR_CHANNEL6 |
| mahphalke |
0:08ba94bc5a30 | 177 | #define CJC_THERMISTOR_CHN SENSOR_CHANNEL7 |
| mahphalke |
0:08ba94bc5a30 | 178 | |
| mahphalke |
0:08ba94bc5a30 | 179 | /* ADC calibration type */ |
| mahphalke |
0:08ba94bc5a30 | 180 | enum adc_calibration_type { |
| mahphalke |
0:08ba94bc5a30 | 181 | INTERNAL_CALIBRATION, |
| mahphalke |
0:08ba94bc5a30 | 182 | SYSTEM_CALIBRATION |
| mahphalke |
0:08ba94bc5a30 | 183 | }; |
| mahphalke |
0:08ba94bc5a30 | 184 | |
| mahphalke |
0:08ba94bc5a30 | 185 | /* 3-wire RTD calibration types */ |
| mahphalke |
0:08ba94bc5a30 | 186 | enum rtd_3wire_calibration_type { |
| mahphalke |
0:08ba94bc5a30 | 187 | MEASURING_EXCITATION_CURRENT, |
| mahphalke |
0:08ba94bc5a30 | 188 | CHOPPING_EXCITATION_CURRENT |
| mahphalke |
0:08ba94bc5a30 | 189 | }; |
| mahphalke |
0:08ba94bc5a30 | 190 | |
| mahphalke |
0:08ba94bc5a30 | 191 | /* Current RTD 3-wire calibration type */ |
| mahphalke |
0:08ba94bc5a30 | 192 | enum rtd_3wire_calibration_type rtd_3wire_calibration_type = |
| mahphalke |
0:08ba94bc5a30 | 193 | MEASURING_EXCITATION_CURRENT; |
| mahphalke |
0:08ba94bc5a30 | 194 | |
| mahphalke |
0:08ba94bc5a30 | 195 | /* Below channel is configured through 'ad7124_regs_config_3wire_rtd' structure*/ |
| mahphalke |
0:08ba94bc5a30 | 196 | #define RTD_3WIRE_REF_MEASUREMENT_CHN SENSOR_CHANNEL4 |
| mahphalke |
0:08ba94bc5a30 | 197 | |
| mahphalke |
0:08ba94bc5a30 | 198 | /* Forward declaration of console menus */ |
| mahphalke |
0:08ba94bc5a30 | 199 | console_menu rtd_2wire_menu; |
| mahphalke |
0:08ba94bc5a30 | 200 | console_menu rtd_3wire_menu; |
| mahphalke |
0:08ba94bc5a30 | 201 | console_menu rtd_3wire_calibration_menu; |
| mahphalke |
0:08ba94bc5a30 | 202 | console_menu rtd_4wire_menu; |
| mahphalke |
0:08ba94bc5a30 | 203 | console_menu ntc_thermistor_menu; |
| mahphalke |
0:08ba94bc5a30 | 204 | console_menu thermocouple_menu; |
| mahphalke |
0:08ba94bc5a30 | 205 | console_menu adc_calibration_menu; |
| mahphalke |
0:08ba94bc5a30 | 206 | |
| mahphalke |
0:08ba94bc5a30 | 207 | /******************************************************************************/ |
| mahphalke |
0:08ba94bc5a30 | 208 | /************************** Functions Declarations ****************************/ |
| mahphalke |
0:08ba94bc5a30 | 209 | /******************************************************************************/ |
| mahphalke |
0:08ba94bc5a30 | 210 | |
| mahphalke |
0:08ba94bc5a30 | 211 | /******************************************************************************/ |
| mahphalke |
0:08ba94bc5a30 | 212 | /************************** Functions Definitions *****************************/ |
| mahphalke |
0:08ba94bc5a30 | 213 | /******************************************************************************/ |
| mahphalke |
0:08ba94bc5a30 | 214 | |
| mahphalke |
0:08ba94bc5a30 | 215 | /*! |
| mahphalke |
0:08ba94bc5a30 | 216 | * @brief Initialize the AD7124 device and user configuration. |
| mahphalke |
0:08ba94bc5a30 | 217 | * @param config_id[in]- Register configuration to be load into device |
| mahphalke |
0:08ba94bc5a30 | 218 | * @return Return 0 in case of SUCCESS, else return negative error code |
| mahphalke |
0:08ba94bc5a30 | 219 | * @details This resets and then writes the default register map value to |
| mahphalke |
0:08ba94bc5a30 | 220 | * the device. A call to init the SPI port is made, but may not |
| mahphalke |
0:08ba94bc5a30 | 221 | * actually do very much, depending on the platform. |
| mahphalke |
0:08ba94bc5a30 | 222 | */ |
| mahphalke |
0:08ba94bc5a30 | 223 | int32_t ad7124_app_initialize(uint8_t config_id) |
| mahphalke |
0:08ba94bc5a30 | 224 | { |
| mahphalke |
0:08ba94bc5a30 | 225 | /* |
| mahphalke |
0:08ba94bc5a30 | 226 | * Copy one of the default/user configs to the live register memory map |
| mahphalke |
0:08ba94bc5a30 | 227 | * Requirement, not checked here, is that all the configs are the same size |
| mahphalke |
0:08ba94bc5a30 | 228 | */ |
| mahphalke |
0:08ba94bc5a30 | 229 | switch (config_id) { |
| mahphalke |
5:90166c496b01 | 230 | case AD7124_CONFIG_RESET: |
| mahphalke |
5:90166c496b01 | 231 | memcpy(ad7124_register_map, ad7124_regs, |
| mahphalke |
5:90166c496b01 | 232 | sizeof(ad7124_register_map)); |
| mahphalke |
5:90166c496b01 | 233 | break; |
| mahphalke |
5:90166c496b01 | 234 | |
| mahphalke |
0:08ba94bc5a30 | 235 | case AD7124_CONFIG_2WIRE_RTD: |
| mahphalke |
0:08ba94bc5a30 | 236 | memcpy(ad7124_register_map, ad7124_regs_config_2wire_rtd, |
| mahphalke |
0:08ba94bc5a30 | 237 | sizeof(ad7124_register_map)); |
| mahphalke |
0:08ba94bc5a30 | 238 | break; |
| mahphalke |
0:08ba94bc5a30 | 239 | |
| mahphalke |
0:08ba94bc5a30 | 240 | case AD7124_CONFIG_3WIRE_RTD: |
| mahphalke |
0:08ba94bc5a30 | 241 | memcpy(ad7124_register_map, ad7124_regs_config_3wire_rtd, |
| mahphalke |
0:08ba94bc5a30 | 242 | sizeof(ad7124_register_map)); |
| mahphalke |
0:08ba94bc5a30 | 243 | break; |
| mahphalke |
0:08ba94bc5a30 | 244 | |
| mahphalke |
0:08ba94bc5a30 | 245 | case AD7124_CONFIG_4WIRE_RTD: |
| mahphalke |
0:08ba94bc5a30 | 246 | memcpy(ad7124_register_map, ad7124_regs_config_4wire_rtd, |
| mahphalke |
0:08ba94bc5a30 | 247 | sizeof(ad7124_register_map)); |
| mahphalke |
0:08ba94bc5a30 | 248 | break; |
| mahphalke |
0:08ba94bc5a30 | 249 | |
| mahphalke |
0:08ba94bc5a30 | 250 | case AD7124_CONFIG_THERMISTOR: |
| mahphalke |
0:08ba94bc5a30 | 251 | memcpy(ad7124_register_map, ad7124_regs_config_thermistor, |
| mahphalke |
0:08ba94bc5a30 | 252 | sizeof(ad7124_register_map)); |
| mahphalke |
0:08ba94bc5a30 | 253 | break; |
| mahphalke |
0:08ba94bc5a30 | 254 | |
| mahphalke |
0:08ba94bc5a30 | 255 | case AD7124_CONFIG_THERMOCOUPLE: |
| mahphalke |
0:08ba94bc5a30 | 256 | memcpy(ad7124_register_map, ad7124_regs_config_thermocouple, |
| mahphalke |
0:08ba94bc5a30 | 257 | sizeof(ad7124_register_map)); |
| mahphalke |
0:08ba94bc5a30 | 258 | break; |
| mahphalke |
0:08ba94bc5a30 | 259 | |
| mahphalke |
0:08ba94bc5a30 | 260 | default: |
| mahphalke |
0:08ba94bc5a30 | 261 | /* Not a defined configID */ |
| mahphalke |
0:08ba94bc5a30 | 262 | return(FAILURE); |
| mahphalke |
0:08ba94bc5a30 | 263 | } |
| mahphalke |
0:08ba94bc5a30 | 264 | |
| mahphalke |
0:08ba94bc5a30 | 265 | /* Get the current sensor configuration */ |
| mahphalke |
0:08ba94bc5a30 | 266 | current_sensor_config = sensor_configs[config_id]; |
| mahphalke |
0:08ba94bc5a30 | 267 | |
| mahphalke |
0:08ba94bc5a30 | 268 | ad7124_init_params.regs = ad7124_register_map; |
| mahphalke |
0:08ba94bc5a30 | 269 | |
| mahphalke |
0:08ba94bc5a30 | 270 | return (ad7124_setup(&p_ad7124_dev, ad7124_init_params)); |
| mahphalke |
0:08ba94bc5a30 | 271 | } |
| mahphalke |
0:08ba94bc5a30 | 272 | |
| mahphalke |
0:08ba94bc5a30 | 273 | |
| mahphalke |
0:08ba94bc5a30 | 274 | /*! |
| mahphalke |
0:08ba94bc5a30 | 275 | * @brief Initialize the part with a specific configuration |
| mahphalke |
0:08ba94bc5a30 | 276 | * @param config_id[in] - Configuration ID |
| mahphalke |
0:08ba94bc5a30 | 277 | * @return Configuration status |
| mahphalke |
0:08ba94bc5a30 | 278 | */ |
| mahphalke |
0:08ba94bc5a30 | 279 | static int32_t init_with_configuration(uint8_t config_id) |
| mahphalke |
0:08ba94bc5a30 | 280 | { |
| mahphalke |
0:08ba94bc5a30 | 281 | /* Free the device resources */ |
| mahphalke |
0:08ba94bc5a30 | 282 | (void)ad7124_remove(p_ad7124_dev); |
| mahphalke |
0:08ba94bc5a30 | 283 | |
| mahphalke |
0:08ba94bc5a30 | 284 | return ad7124_app_initialize(config_id); |
| mahphalke |
0:08ba94bc5a30 | 285 | } |
| mahphalke |
0:08ba94bc5a30 | 286 | |
| mahphalke |
0:08ba94bc5a30 | 287 | |
| mahphalke |
0:08ba94bc5a30 | 288 | /*! |
| mahphalke |
5:90166c496b01 | 289 | * @brief determines if the Escape key was pressed |
| mahphalke |
5:90166c496b01 | 290 | * @return bool- key press status |
| mahphalke |
5:90166c496b01 | 291 | */ |
| mahphalke |
5:90166c496b01 | 292 | static bool was_escape_key_pressed(void) |
| mahphalke |
5:90166c496b01 | 293 | { |
| mahphalke |
5:90166c496b01 | 294 | char rxChar; |
| mahphalke |
5:90166c496b01 | 295 | bool wasPressed = false; |
| mahphalke |
5:90166c496b01 | 296 | |
| mahphalke |
5:90166c496b01 | 297 | /* Check for Escape key pressed */ |
| mahphalke |
5:90166c496b01 | 298 | if ((rxChar = getchar_noblock()) > 0) { |
| mahphalke |
5:90166c496b01 | 299 | if (rxChar == ESCAPE_KEY_CODE) { |
| mahphalke |
5:90166c496b01 | 300 | wasPressed = true; |
| mahphalke |
5:90166c496b01 | 301 | } |
| mahphalke |
5:90166c496b01 | 302 | } |
| mahphalke |
5:90166c496b01 | 303 | |
| mahphalke |
5:90166c496b01 | 304 | return (wasPressed); |
| mahphalke |
5:90166c496b01 | 305 | } |
| mahphalke |
5:90166c496b01 | 306 | |
| mahphalke |
5:90166c496b01 | 307 | |
| mahphalke |
5:90166c496b01 | 308 | /*! |
| mahphalke |
0:08ba94bc5a30 | 309 | * @brief Enable the multiple sensors for measurement |
| mahphalke |
0:08ba94bc5a30 | 310 | * @param chn_number[in]- Channel number assigned for the sensor |
| mahphalke |
0:08ba94bc5a30 | 311 | * @return MENU_CONTINUE |
| mahphalke |
0:08ba94bc5a30 | 312 | * @note Each sensor has been assigned with unique channel number |
| mahphalke |
0:08ba94bc5a30 | 313 | */ |
| mahphalke |
0:08ba94bc5a30 | 314 | int32_t enable_disable_sensor(uint32_t chn_number) |
| mahphalke |
0:08ba94bc5a30 | 315 | { |
| mahphalke |
0:08ba94bc5a30 | 316 | sensor_enable_status[chn_number] = !sensor_enable_status[chn_number]; |
| mahphalke |
0:08ba94bc5a30 | 317 | return MENU_CONTINUE; |
| mahphalke |
0:08ba94bc5a30 | 318 | } |
| mahphalke |
0:08ba94bc5a30 | 319 | |
| mahphalke |
0:08ba94bc5a30 | 320 | |
| mahphalke |
0:08ba94bc5a30 | 321 | /*! |
| mahphalke |
0:08ba94bc5a30 | 322 | * @brief Select the CJC sensor for thermocouple measurement |
| mahphalke |
0:08ba94bc5a30 | 323 | * @param cjc_sensor[in]- CJC sensor to be selected |
| mahphalke |
0:08ba94bc5a30 | 324 | * @return MENU_CONTINUE |
| mahphalke |
0:08ba94bc5a30 | 325 | * @return Only one CJC sensor is active at a time, therefore fixed |
| mahphalke |
0:08ba94bc5a30 | 326 | * channel value is selected for it during measurement |
| mahphalke |
0:08ba94bc5a30 | 327 | */ |
| mahphalke |
0:08ba94bc5a30 | 328 | int32_t select_cjc_sensor(uint32_t cjc_sensor) |
| mahphalke |
0:08ba94bc5a30 | 329 | { |
| mahphalke |
0:08ba94bc5a30 | 330 | current_cjc_sensor = cjc_sensor; |
| mahphalke |
0:08ba94bc5a30 | 331 | |
| mahphalke |
0:08ba94bc5a30 | 332 | /* Change status of all CJC sensor channels to false at start */ |
| mahphalke |
0:08ba94bc5a30 | 333 | sensor_enable_status[CJC_RTD_CHN] = false; |
| mahphalke |
0:08ba94bc5a30 | 334 | sensor_enable_status[CJC_THERMISTOR_CHN] = false; |
| mahphalke |
0:08ba94bc5a30 | 335 | |
| mahphalke |
0:08ba94bc5a30 | 336 | switch (current_cjc_sensor) { |
| mahphalke |
0:08ba94bc5a30 | 337 | case PT100_4WIRE_RTD: |
| mahphalke |
5:90166c496b01 | 338 | case PT1000_2WIRE_RTD: |
| mahphalke |
0:08ba94bc5a30 | 339 | sensor_enable_status[CJC_RTD_CHN] = true; |
| mahphalke |
0:08ba94bc5a30 | 340 | break; |
| mahphalke |
0:08ba94bc5a30 | 341 | |
| mahphalke |
0:08ba94bc5a30 | 342 | case THERMISTOR_PTC_KY81_110: |
| mahphalke |
0:08ba94bc5a30 | 343 | sensor_enable_status[CJC_THERMISTOR_CHN] = true; |
| mahphalke |
0:08ba94bc5a30 | 344 | break; |
| mahphalke |
0:08ba94bc5a30 | 345 | |
| mahphalke |
0:08ba94bc5a30 | 346 | default: |
| mahphalke |
0:08ba94bc5a30 | 347 | return FAILURE; |
| mahphalke |
0:08ba94bc5a30 | 348 | } |
| mahphalke |
0:08ba94bc5a30 | 349 | |
| mahphalke |
0:08ba94bc5a30 | 350 | return MENU_CONTINUE; |
| mahphalke |
0:08ba94bc5a30 | 351 | } |
| mahphalke |
0:08ba94bc5a30 | 352 | |
| mahphalke |
0:08ba94bc5a30 | 353 | |
| mahphalke |
0:08ba94bc5a30 | 354 | /*! |
| mahphalke |
0:08ba94bc5a30 | 355 | * @brief Perform the ADC data conversion for input channel |
| mahphalke |
0:08ba94bc5a30 | 356 | * @param chn[in]- Channel to be sampled |
| mahphalke |
5:90166c496b01 | 357 | * @param data[in]- Array to store converted results |
| mahphalke |
5:90166c496b01 | 358 | * @param measurement_type[in] - Temperature measurement and display type |
| mahphalke |
0:08ba94bc5a30 | 359 | * @return Return 0 in case of SUCCESS, else return negative error code |
| mahphalke |
0:08ba94bc5a30 | 360 | * @note This function gets the averged adc raw value for MAX_ADC_SAMPLES |
| mahphalke |
0:08ba94bc5a30 | 361 | * samples |
| mahphalke |
0:08ba94bc5a30 | 362 | */ |
| mahphalke |
5:90166c496b01 | 363 | static int32_t perform_adc_conversion(uint8_t chn, |
| mahphalke |
5:90166c496b01 | 364 | int32_t (*data)[MAX_ADC_SAMPLES], |
| mahphalke |
5:90166c496b01 | 365 | sensor_measurement_type measurement_type) |
| mahphalke |
0:08ba94bc5a30 | 366 | { |
| mahphalke |
0:08ba94bc5a30 | 367 | int32_t sample_data; |
| mahphalke |
0:08ba94bc5a30 | 368 | int64_t avg_sample_data = 0; |
| mahphalke |
0:08ba94bc5a30 | 369 | |
| mahphalke |
0:08ba94bc5a30 | 370 | /* Enable the current channel */ |
| mahphalke |
0:08ba94bc5a30 | 371 | ad7124_register_map[AD7124_Channel_0 + chn].value |= |
| mahphalke |
0:08ba94bc5a30 | 372 | AD7124_CH_MAP_REG_CH_ENABLE; |
| mahphalke |
0:08ba94bc5a30 | 373 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
0:08ba94bc5a30 | 374 | ad7124_register_map[AD7124_Channel_0 + chn]) != SUCCESS) { |
| mahphalke |
0:08ba94bc5a30 | 375 | return FAILURE; |
| mahphalke |
0:08ba94bc5a30 | 376 | } |
| mahphalke |
0:08ba94bc5a30 | 377 | |
| mahphalke |
0:08ba94bc5a30 | 378 | /* Enter into continuous conversion mode */ |
| mahphalke |
0:08ba94bc5a30 | 379 | ad7124_register_map[AD7124_ADC_Control].value &= (~AD7124_ADC_CTRL_REG_MSK); |
| mahphalke |
0:08ba94bc5a30 | 380 | ad7124_register_map[AD7124_ADC_Control].value |= AD7124_ADC_CTRL_REG_MODE( |
| mahphalke |
0:08ba94bc5a30 | 381 | CONTINUOUS_CONV_MODE); |
| mahphalke |
0:08ba94bc5a30 | 382 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
0:08ba94bc5a30 | 383 | ad7124_register_map[AD7124_ADC_Control]) != SUCCESS) { |
| mahphalke |
0:08ba94bc5a30 | 384 | return FAILURE; |
| mahphalke |
0:08ba94bc5a30 | 385 | } |
| mahphalke |
0:08ba94bc5a30 | 386 | |
| mahphalke |
0:08ba94bc5a30 | 387 | /* Read adc samples */ |
| mahphalke |
0:08ba94bc5a30 | 388 | for (uint16_t sample = 0; sample < MAX_ADC_SAMPLES; sample++) { |
| mahphalke |
0:08ba94bc5a30 | 389 | /* |
| mahphalke |
0:08ba94bc5a30 | 390 | * this polls the status register READY/ bit to determine when conversion is done |
| mahphalke |
0:08ba94bc5a30 | 391 | * this also ensures the STATUS register value is up to date and contains the |
| mahphalke |
0:08ba94bc5a30 | 392 | * channel that was sampled as well. No need to read STATUS separately |
| mahphalke |
0:08ba94bc5a30 | 393 | */ |
| mahphalke |
0:08ba94bc5a30 | 394 | if (ad7124_wait_for_conv_ready(p_ad7124_dev, CONVERSION_TIMEOUT) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 395 | break; |
| mahphalke |
0:08ba94bc5a30 | 396 | } |
| mahphalke |
0:08ba94bc5a30 | 397 | |
| mahphalke |
5:90166c496b01 | 398 | if (measurement_type == AVERAGED_MEASUREMENT) { |
| mahphalke |
5:90166c496b01 | 399 | if (ad7124_read_data(p_ad7124_dev, &sample_data) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 400 | break; |
| mahphalke |
5:90166c496b01 | 401 | } |
| mahphalke |
5:90166c496b01 | 402 | avg_sample_data += sample_data; |
| mahphalke |
5:90166c496b01 | 403 | } else { |
| mahphalke |
5:90166c496b01 | 404 | if (ad7124_read_data(p_ad7124_dev, data[0]+sample) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 405 | break; |
| mahphalke |
5:90166c496b01 | 406 | } |
| mahphalke |
5:90166c496b01 | 407 | } |
| mahphalke |
0:08ba94bc5a30 | 408 | } |
| mahphalke |
0:08ba94bc5a30 | 409 | |
| mahphalke |
0:08ba94bc5a30 | 410 | /* Put ADC into Standby mode */ |
| mahphalke |
0:08ba94bc5a30 | 411 | ad7124_register_map[AD7124_ADC_Control].value &= (~AD7124_ADC_CTRL_REG_MSK); |
| mahphalke |
0:08ba94bc5a30 | 412 | ad7124_register_map[AD7124_ADC_Control].value |= AD7124_ADC_CTRL_REG_MODE( |
| mahphalke |
0:08ba94bc5a30 | 413 | STANDBY_MODE); |
| mahphalke |
0:08ba94bc5a30 | 414 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
0:08ba94bc5a30 | 415 | ad7124_register_map[AD7124_ADC_Control]) != SUCCESS) { |
| mahphalke |
0:08ba94bc5a30 | 416 | return FAILURE; |
| mahphalke |
0:08ba94bc5a30 | 417 | } |
| mahphalke |
0:08ba94bc5a30 | 418 | |
| mahphalke |
5:90166c496b01 | 419 | /* Disable current channel */ |
| mahphalke |
5:90166c496b01 | 420 | ad7124_register_map[AD7124_Channel_0 + chn].value &= |
| mahphalke |
5:90166c496b01 | 421 | ~AD7124_CH_MAP_REG_CH_ENABLE; |
| mahphalke |
5:90166c496b01 | 422 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
5:90166c496b01 | 423 | ad7124_register_map[AD7124_Channel_0 + chn]) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 424 | return FAILURE; |
| mahphalke |
5:90166c496b01 | 425 | } |
| mahphalke |
5:90166c496b01 | 426 | |
| mahphalke |
5:90166c496b01 | 427 | if (measurement_type == AVERAGED_MEASUREMENT) { |
| mahphalke |
5:90166c496b01 | 428 | /* Calculate the averaged adc raw value */ |
| mahphalke |
5:90166c496b01 | 429 | *data[0] = (avg_sample_data / MAX_ADC_SAMPLES); |
| mahphalke |
5:90166c496b01 | 430 | } |
| mahphalke |
5:90166c496b01 | 431 | |
| mahphalke |
5:90166c496b01 | 432 | return SUCCESS; |
| mahphalke |
5:90166c496b01 | 433 | } |
| mahphalke |
5:90166c496b01 | 434 | |
| mahphalke |
5:90166c496b01 | 435 | |
| mahphalke |
5:90166c496b01 | 436 | /*! |
| mahphalke |
5:90166c496b01 | 437 | * @brief Perform the 3-wire RTD additional configurations |
| mahphalke |
5:90166c496b01 | 438 | * @param multiple_rtd_enabled[in,out]- Multiple RTD enable status flag |
| mahphalke |
5:90166c496b01 | 439 | * @return SUCCESS/FAILURE |
| mahphalke |
5:90166c496b01 | 440 | */ |
| mahphalke |
5:90166c496b01 | 441 | static int32_t do_3wire_rtd_configs(bool *multiple_rtd_enabled) |
| mahphalke |
5:90166c496b01 | 442 | { |
| mahphalke |
5:90166c496b01 | 443 | uint8_t sensor_enable_cnt = 0; |
| mahphalke |
5:90166c496b01 | 444 | uint8_t setup; |
| mahphalke |
5:90166c496b01 | 445 | |
| mahphalke |
5:90166c496b01 | 446 | *multiple_rtd_enabled = false; |
| mahphalke |
5:90166c496b01 | 447 | |
| mahphalke |
5:90166c496b01 | 448 | /* Check if multiple RTDs are enabled */ |
| mahphalke |
5:90166c496b01 | 449 | for (uint8_t chn = SENSOR_CHANNEL0; |
| mahphalke |
5:90166c496b01 | 450 | chn < max_supported_sensors[AD7124_CONFIG_3WIRE_RTD]; chn++) { |
| mahphalke |
5:90166c496b01 | 451 | if (sensor_enable_status[chn]) |
| mahphalke |
5:90166c496b01 | 452 | sensor_enable_cnt++; |
| mahphalke |
5:90166c496b01 | 453 | |
| mahphalke |
5:90166c496b01 | 454 | if (sensor_enable_cnt > 1) { |
| mahphalke |
5:90166c496b01 | 455 | *multiple_rtd_enabled = true; |
| mahphalke |
5:90166c496b01 | 456 | break; |
| mahphalke |
5:90166c496b01 | 457 | } |
| mahphalke |
5:90166c496b01 | 458 | } |
| mahphalke |
5:90166c496b01 | 459 | |
| mahphalke |
5:90166c496b01 | 460 | for (uint8_t chn = SENSOR_CHANNEL0; |
| mahphalke |
5:90166c496b01 | 461 | chn < max_supported_sensors[AD7124_CONFIG_3WIRE_RTD]; chn++) { |
| mahphalke |
5:90166c496b01 | 462 | if (sensor_enable_status[chn]) { |
| mahphalke |
5:90166c496b01 | 463 | setup = ad7124_get_channel_setup(p_ad7124_dev, chn); |
| mahphalke |
5:90166c496b01 | 464 | ad7124_register_map[AD7124_Config_0 + setup].value &= (~AD7124_CFG_REG_PGA_MSK); |
| mahphalke |
5:90166c496b01 | 465 | |
| mahphalke |
5:90166c496b01 | 466 | if (*multiple_rtd_enabled) { |
| mahphalke |
5:90166c496b01 | 467 | ad7124_register_map[AD7124_Config_0 + setup].value |= AD7124_CFG_REG_PGA( |
| mahphalke |
5:90166c496b01 | 468 | MULTI_3WIRE_RTD_GAIN); |
| mahphalke |
5:90166c496b01 | 469 | } else { |
| mahphalke |
5:90166c496b01 | 470 | ad7124_register_map[AD7124_Config_0 + setup].value |= AD7124_CFG_REG_PGA( |
| mahphalke |
5:90166c496b01 | 471 | SINGLE_3WIRE_RTD_GAIN); |
| mahphalke |
5:90166c496b01 | 472 | } |
| mahphalke |
5:90166c496b01 | 473 | |
| mahphalke |
5:90166c496b01 | 474 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
5:90166c496b01 | 475 | ad7124_register_map[AD7124_Config_0 + setup]) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 476 | return FAILURE; |
| mahphalke |
5:90166c496b01 | 477 | } |
| mahphalke |
5:90166c496b01 | 478 | } |
| mahphalke |
5:90166c496b01 | 479 | } |
| mahphalke |
0:08ba94bc5a30 | 480 | |
| mahphalke |
0:08ba94bc5a30 | 481 | return SUCCESS; |
| mahphalke |
0:08ba94bc5a30 | 482 | } |
| mahphalke |
0:08ba94bc5a30 | 483 | |
| mahphalke |
0:08ba94bc5a30 | 484 | |
| mahphalke |
0:08ba94bc5a30 | 485 | /*! |
| mahphalke |
0:08ba94bc5a30 | 486 | * @brief Perform the ADC sampling for selected RTD sensor channel |
| mahphalke |
0:08ba94bc5a30 | 487 | * @param rtd_config_id[in]- RTD type (2/3/4-wire) |
| mahphalke |
0:08ba94bc5a30 | 488 | * @param chn[in] - ADC channel assigned to given RTD sensor |
| mahphalke |
0:08ba94bc5a30 | 489 | * @param adc_raw[out] - ADC raw result |
| mahphalke |
5:90166c496b01 | 490 | * @param measurement_type[in] - Temperature measurement and display type |
| mahphalke |
5:90166c496b01 | 491 | * @param multiple_3wire_rtd_enabled[in] - Multiple RTD enable status |
| mahphalke |
0:08ba94bc5a30 | 492 | * @return RTC sensor ADC sampling data |
| mahphalke |
0:08ba94bc5a30 | 493 | */ |
| mahphalke |
5:90166c496b01 | 494 | static bool do_rtd_sensor_adc_sampling(uint32_t rtd_config_id, uint8_t chn, |
| mahphalke |
5:90166c496b01 | 495 | int32_t (*adc_raw)[MAX_ADC_SAMPLES], sensor_measurement_type measurement_type, |
| mahphalke |
5:90166c496b01 | 496 | bool multiple_3wire_rtd_enabled) |
| mahphalke |
0:08ba94bc5a30 | 497 | { |
| mahphalke |
0:08ba94bc5a30 | 498 | bool adc_sampling_status = true; |
| mahphalke |
5:90166c496b01 | 499 | int32_t iout0_exc, iout1_exc; |
| mahphalke |
0:08ba94bc5a30 | 500 | |
| mahphalke |
0:08ba94bc5a30 | 501 | const uint8_t rtd_iout0_source[][MAX_RTD_SENSORS] = { |
| mahphalke |
0:08ba94bc5a30 | 502 | { |
| mahphalke |
0:08ba94bc5a30 | 503 | RTD1_2WIRE_IOUT0, RTD2_2WIRE_IOUT0, RTD3_2WIRE_IOUT0, RTD4_2WIRE_IOUT0, |
| mahphalke |
0:08ba94bc5a30 | 504 | RTD5_2WIRE_IOUT0 |
| mahphalke |
0:08ba94bc5a30 | 505 | }, |
| mahphalke |
0:08ba94bc5a30 | 506 | { |
| mahphalke |
0:08ba94bc5a30 | 507 | RTD1_3WIRE_IOUT0, RTD2_3WIRE_IOUT0, RTD3_3WIRE_IOUT0, RTD4_3WIRE_IOUT0 |
| mahphalke |
0:08ba94bc5a30 | 508 | }, |
| mahphalke |
0:08ba94bc5a30 | 509 | { |
| mahphalke |
0:08ba94bc5a30 | 510 | RTD1_4WIRE_IOUT0, RTD2_4WIRE_IOUT0, RTD3_4WIRE_IOUT0, RTD4_4WIRE_IOUT0, |
| mahphalke |
0:08ba94bc5a30 | 511 | RTD5_4WIRE_IOUT0 |
| mahphalke |
0:08ba94bc5a30 | 512 | } |
| mahphalke |
0:08ba94bc5a30 | 513 | }; |
| mahphalke |
0:08ba94bc5a30 | 514 | |
| mahphalke |
0:08ba94bc5a30 | 515 | const uint8_t rtd_3wire_iout1_source[] = { |
| mahphalke |
0:08ba94bc5a30 | 516 | RTD1_3WIRE_IOUT1, RTD2_3WIRE_IOUT1, RTD3_3WIRE_IOUT1, RTD4_3WIRE_IOUT1, |
| mahphalke |
0:08ba94bc5a30 | 517 | }; |
| mahphalke |
0:08ba94bc5a30 | 518 | |
| mahphalke |
5:90166c496b01 | 519 | /* Select excitation source based on RTD configuration */ |
| mahphalke |
5:90166c496b01 | 520 | if (multiple_3wire_rtd_enabled) { |
| mahphalke |
5:90166c496b01 | 521 | iout0_exc = RTD_IOUT0_250UA_EXC; |
| mahphalke |
5:90166c496b01 | 522 | iout1_exc = RTD_IOUT1_250UA_EXC; |
| mahphalke |
5:90166c496b01 | 523 | } else { |
| mahphalke |
5:90166c496b01 | 524 | iout0_exc = RTD_IOUT0_500UA_EXC; |
| mahphalke |
5:90166c496b01 | 525 | iout1_exc = RTD_IOUT1_500UA_EXC; |
| mahphalke |
5:90166c496b01 | 526 | } |
| mahphalke |
5:90166c496b01 | 527 | |
| mahphalke |
0:08ba94bc5a30 | 528 | do { |
| mahphalke |
0:08ba94bc5a30 | 529 | /* Enable and direct IOUT0 excitation current source for current RTD sensor measurement */ |
| mahphalke |
0:08ba94bc5a30 | 530 | ad7124_register_map[AD7124_IOCon1].value |= (AD7124_IO_CTRL1_REG_IOUT_CH0( |
| mahphalke |
0:08ba94bc5a30 | 531 | rtd_iout0_source[rtd_config_id][chn]) | AD7124_IO_CTRL1_REG_IOUT0( |
| mahphalke |
5:90166c496b01 | 532 | iout0_exc)); |
| mahphalke |
0:08ba94bc5a30 | 533 | |
| mahphalke |
0:08ba94bc5a30 | 534 | if (rtd_config_id == AD7124_CONFIG_3WIRE_RTD) { |
| mahphalke |
0:08ba94bc5a30 | 535 | /* Enable and direct IOUT1 excitation current source for current RTD sensor measurement */ |
| mahphalke |
0:08ba94bc5a30 | 536 | ad7124_register_map[AD7124_IOCon1].value |= (AD7124_IO_CTRL1_REG_IOUT_CH1( |
| mahphalke |
0:08ba94bc5a30 | 537 | rtd_3wire_iout1_source[chn]) | AD7124_IO_CTRL1_REG_IOUT1( |
| mahphalke |
5:90166c496b01 | 538 | iout1_exc)); |
| mahphalke |
0:08ba94bc5a30 | 539 | } |
| mahphalke |
0:08ba94bc5a30 | 540 | |
| mahphalke |
0:08ba94bc5a30 | 541 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
0:08ba94bc5a30 | 542 | ad7124_register_map[AD7124_IOCon1]) != SUCCESS) { |
| mahphalke |
0:08ba94bc5a30 | 543 | adc_sampling_status = false; |
| mahphalke |
0:08ba94bc5a30 | 544 | break; |
| mahphalke |
0:08ba94bc5a30 | 545 | } |
| mahphalke |
0:08ba94bc5a30 | 546 | |
| mahphalke |
5:90166c496b01 | 547 | if (perform_adc_conversion(chn, adc_raw, measurement_type) != SUCCESS) { |
| mahphalke |
0:08ba94bc5a30 | 548 | adc_sampling_status = false; |
| mahphalke |
0:08ba94bc5a30 | 549 | break; |
| mahphalke |
0:08ba94bc5a30 | 550 | } |
| mahphalke |
0:08ba94bc5a30 | 551 | |
| mahphalke |
0:08ba94bc5a30 | 552 | /* Turn off the excitation currents */ |
| mahphalke |
0:08ba94bc5a30 | 553 | ad7124_register_map[AD7124_IOCon1].value &= ((~AD7124_IO_CTRL1_REG_IOUT0_MSK) |
| mahphalke |
0:08ba94bc5a30 | 554 | & (~AD7124_IO_CTRL1_REG_IOUT_CH0_MSK)); |
| mahphalke |
0:08ba94bc5a30 | 555 | |
| mahphalke |
0:08ba94bc5a30 | 556 | if (rtd_config_id == AD7124_CONFIG_3WIRE_RTD) { |
| mahphalke |
0:08ba94bc5a30 | 557 | ad7124_register_map[AD7124_IOCon1].value &= ((~AD7124_IO_CTRL1_REG_IOUT1_MSK) |
| mahphalke |
0:08ba94bc5a30 | 558 | & (~AD7124_IO_CTRL1_REG_IOUT_CH1_MSK)); |
| mahphalke |
0:08ba94bc5a30 | 559 | } |
| mahphalke |
0:08ba94bc5a30 | 560 | |
| mahphalke |
0:08ba94bc5a30 | 561 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
0:08ba94bc5a30 | 562 | ad7124_register_map[AD7124_IOCon1]) != SUCCESS) { |
| mahphalke |
0:08ba94bc5a30 | 563 | adc_sampling_status = false; |
| mahphalke |
0:08ba94bc5a30 | 564 | break; |
| mahphalke |
0:08ba94bc5a30 | 565 | } |
| mahphalke |
0:08ba94bc5a30 | 566 | } while (0); |
| mahphalke |
0:08ba94bc5a30 | 567 | |
| mahphalke |
0:08ba94bc5a30 | 568 | return adc_sampling_status; |
| mahphalke |
0:08ba94bc5a30 | 569 | } |
| mahphalke |
0:08ba94bc5a30 | 570 | |
| mahphalke |
0:08ba94bc5a30 | 571 | |
| mahphalke |
0:08ba94bc5a30 | 572 | /*! |
| mahphalke |
0:08ba94bc5a30 | 573 | * @brief Perform the multiple RTD sensors measurement |
| mahphalke |
0:08ba94bc5a30 | 574 | * @param rtd_config_id[in]- RTD type (2/3/4-wire) |
| mahphalke |
5:90166c496b01 | 575 | * @param measurement_type[in] - Temperature measurement and display type |
| mahphalke |
0:08ba94bc5a30 | 576 | * @return MENU_CONTINUE |
| mahphalke |
0:08ba94bc5a30 | 577 | */ |
| mahphalke |
5:90166c496b01 | 578 | static int32_t perform_rtd_measurement(uint32_t rtd_config_id, |
| mahphalke |
5:90166c496b01 | 579 | sensor_measurement_type measurement_type) |
| mahphalke |
0:08ba94bc5a30 | 580 | { |
| mahphalke |
0:08ba94bc5a30 | 581 | bool adc_error = false; |
| mahphalke |
5:90166c496b01 | 582 | bool multiple_3wire_rtd_enabled = false; |
| mahphalke |
5:90166c496b01 | 583 | uint8_t rtd_gain; |
| mahphalke |
5:90166c496b01 | 584 | uint16_t sample_cnt; |
| mahphalke |
5:90166c496b01 | 585 | bool continue_measurement = false; |
| mahphalke |
0:08ba94bc5a30 | 586 | float temperature; |
| mahphalke |
0:08ba94bc5a30 | 587 | |
| mahphalke |
5:90166c496b01 | 588 | if (measurement_type == CONTINUOUS_MEASUREMENT) { |
| mahphalke |
5:90166c496b01 | 589 | printf(EOL"Press ESC key once to stop measurement..." EOL); |
| mahphalke |
5:90166c496b01 | 590 | mdelay(1000); |
| mahphalke |
5:90166c496b01 | 591 | continue_measurement = true; |
| mahphalke |
5:90166c496b01 | 592 | } |
| mahphalke |
5:90166c496b01 | 593 | |
| mahphalke |
5:90166c496b01 | 594 | /* Print display header */ |
| mahphalke |
0:08ba94bc5a30 | 595 | printf(EOL EOL EOL); |
| mahphalke |
5:90166c496b01 | 596 | for (uint8_t chn = SENSOR_CHANNEL0; |
| mahphalke |
5:90166c496b01 | 597 | chn < max_supported_sensors[rtd_config_id]; chn++) { |
| mahphalke |
5:90166c496b01 | 598 | if (sensor_enable_status[chn]) { |
| mahphalke |
6:622270f7d476 | 599 | printf("\tRTD%d ", chn+1); |
| mahphalke |
5:90166c496b01 | 600 | } |
| mahphalke |
5:90166c496b01 | 601 | } |
| mahphalke |
6:622270f7d476 | 602 | printf(EOL "\t-----------------------------------------------" EOL EOL); |
| mahphalke |
5:90166c496b01 | 603 | |
| mahphalke |
5:90166c496b01 | 604 | /* Perform additional configs for 3-wire RTD measurement */ |
| mahphalke |
5:90166c496b01 | 605 | if (rtd_config_id == AD7124_CONFIG_3WIRE_RTD) { |
| mahphalke |
5:90166c496b01 | 606 | if (do_3wire_rtd_configs(&multiple_3wire_rtd_enabled) != SUCCESS) |
| mahphalke |
5:90166c496b01 | 607 | adc_error = true; |
| mahphalke |
5:90166c496b01 | 608 | } |
| mahphalke |
0:08ba94bc5a30 | 609 | |
| mahphalke |
5:90166c496b01 | 610 | do { |
| mahphalke |
5:90166c496b01 | 611 | /* Sample and Read all enabled NTC channels in sequence */ |
| mahphalke |
5:90166c496b01 | 612 | for (uint8_t chn = SENSOR_CHANNEL0; |
| mahphalke |
5:90166c496b01 | 613 | (chn < max_supported_sensors[rtd_config_id]) & !adc_error; chn++) { |
| mahphalke |
5:90166c496b01 | 614 | if (sensor_enable_status[chn]) { |
| mahphalke |
5:90166c496b01 | 615 | if (!do_rtd_sensor_adc_sampling(rtd_config_id, chn, &n_sample_data[chn], |
| mahphalke |
5:90166c496b01 | 616 | measurement_type, multiple_3wire_rtd_enabled)) { |
| mahphalke |
5:90166c496b01 | 617 | adc_error = true; |
| mahphalke |
5:90166c496b01 | 618 | break; |
| mahphalke |
5:90166c496b01 | 619 | } |
| mahphalke |
5:90166c496b01 | 620 | } |
| mahphalke |
5:90166c496b01 | 621 | } |
| mahphalke |
5:90166c496b01 | 622 | |
| mahphalke |
5:90166c496b01 | 623 | if (adc_error) { |
| mahphalke |
5:90166c496b01 | 624 | printf(EOL EOL "\tError Performing Measurement" EOL); |
| mahphalke |
5:90166c496b01 | 625 | break; |
| mahphalke |
5:90166c496b01 | 626 | } else { |
| mahphalke |
5:90166c496b01 | 627 | if (multiple_3wire_rtd_enabled) { |
| mahphalke |
5:90166c496b01 | 628 | /* Store the Iout ratio as 1 (assumption is Iout0=Iout1) and no |
| mahphalke |
5:90166c496b01 | 629 | * Iout calibration is performed */ |
| mahphalke |
5:90166c496b01 | 630 | store_rtd_calibrated_iout_ratio(1, true); |
| mahphalke |
5:90166c496b01 | 631 | rtd_gain = MULTI_3WIRE_RTD_GAIN; |
| mahphalke |
5:90166c496b01 | 632 | } else { |
| mahphalke |
5:90166c496b01 | 633 | rtd_gain = RTD_2WIRE_GAIN_VALUE; |
| mahphalke |
0:08ba94bc5a30 | 634 | } |
| mahphalke |
0:08ba94bc5a30 | 635 | |
| mahphalke |
5:90166c496b01 | 636 | /* Calculate temperature and display result */ |
| mahphalke |
5:90166c496b01 | 637 | if (measurement_type == AVERAGED_MEASUREMENT) { |
| mahphalke |
5:90166c496b01 | 638 | for (uint8_t chn = SENSOR_CHANNEL0; chn < max_supported_sensors[rtd_config_id]; |
| mahphalke |
5:90166c496b01 | 639 | chn++) { |
| mahphalke |
5:90166c496b01 | 640 | if (sensor_enable_status[chn]) { |
| mahphalke |
5:90166c496b01 | 641 | temperature = get_rtd_temperature(n_sample_data[chn][0], rtd_gain); |
| mahphalke |
6:622270f7d476 | 642 | sprintf(decimal_eqv_str, "%.4f ", temperature); |
| mahphalke |
6:622270f7d476 | 643 | strcat(decimal_eqv_str_arr, decimal_eqv_str); |
| mahphalke |
5:90166c496b01 | 644 | } |
| mahphalke |
5:90166c496b01 | 645 | } |
| mahphalke |
6:622270f7d476 | 646 | printf("\t%s" EOL EOL, decimal_eqv_str_arr); |
| mahphalke |
6:622270f7d476 | 647 | decimal_eqv_str_arr[0] = '\0'; |
| mahphalke |
5:90166c496b01 | 648 | } else { |
| mahphalke |
5:90166c496b01 | 649 | for (sample_cnt = 0; sample_cnt < MAX_ADC_SAMPLES; sample_cnt++) { |
| mahphalke |
5:90166c496b01 | 650 | for (uint8_t chn = SENSOR_CHANNEL0; chn < max_supported_sensors[rtd_config_id]; |
| mahphalke |
5:90166c496b01 | 651 | chn++) { |
| mahphalke |
5:90166c496b01 | 652 | if (sensor_enable_status[chn]) { |
| mahphalke |
5:90166c496b01 | 653 | temperature = get_rtd_temperature(n_sample_data[chn][sample_cnt], rtd_gain); |
| mahphalke |
6:622270f7d476 | 654 | sprintf(decimal_eqv_str, "%.4f ", temperature); |
| mahphalke |
6:622270f7d476 | 655 | strcat(decimal_eqv_str_arr, decimal_eqv_str); |
| mahphalke |
5:90166c496b01 | 656 | } |
| mahphalke |
5:90166c496b01 | 657 | } |
| mahphalke |
6:622270f7d476 | 658 | printf("\t%s" EOL EOL, decimal_eqv_str_arr); |
| mahphalke |
6:622270f7d476 | 659 | decimal_eqv_str_arr[0] = '\0'; |
| mahphalke |
5:90166c496b01 | 660 | } |
| mahphalke |
0:08ba94bc5a30 | 661 | } |
| mahphalke |
0:08ba94bc5a30 | 662 | } |
| mahphalke |
5:90166c496b01 | 663 | } while (continue_measurement && !was_escape_key_pressed()); |
| mahphalke |
5:90166c496b01 | 664 | |
| mahphalke |
5:90166c496b01 | 665 | if (multiple_3wire_rtd_enabled) { |
| mahphalke |
5:90166c496b01 | 666 | /* Reset the calibration constant value after measurement */ |
| mahphalke |
5:90166c496b01 | 667 | store_rtd_calibrated_iout_ratio(1, false); |
| mahphalke |
0:08ba94bc5a30 | 668 | } |
| mahphalke |
0:08ba94bc5a30 | 669 | |
| mahphalke |
0:08ba94bc5a30 | 670 | /* Put ADC into standby mode */ |
| mahphalke |
0:08ba94bc5a30 | 671 | ad7124_register_map[AD7124_ADC_Control].value &= (~AD7124_ADC_CTRL_REG_MSK); |
| mahphalke |
0:08ba94bc5a30 | 672 | ad7124_register_map[AD7124_ADC_Control].value |= AD7124_ADC_CTRL_REG_MODE( |
| mahphalke |
0:08ba94bc5a30 | 673 | STANDBY_MODE); |
| mahphalke |
0:08ba94bc5a30 | 674 | ad7124_write_register(p_ad7124_dev, ad7124_register_map[AD7124_ADC_Control]); |
| mahphalke |
0:08ba94bc5a30 | 675 | |
| mahphalke |
0:08ba94bc5a30 | 676 | adi_press_any_key_to_continue(); |
| mahphalke |
0:08ba94bc5a30 | 677 | return MENU_CONTINUE; |
| mahphalke |
0:08ba94bc5a30 | 678 | } |
| mahphalke |
0:08ba94bc5a30 | 679 | |
| mahphalke |
0:08ba94bc5a30 | 680 | |
| mahphalke |
0:08ba94bc5a30 | 681 | /*! |
| mahphalke |
5:90166c496b01 | 682 | * @brief Perform the 2-wire RTD measurement |
| mahphalke |
5:90166c496b01 | 683 | * @param measurement_type[in] - Temperature measurement and display type |
| mahphalke |
5:90166c496b01 | 684 | * @return MENU_CONTINUE |
| mahphalke |
5:90166c496b01 | 685 | */ |
| mahphalke |
5:90166c496b01 | 686 | static int32_t perform_2wire_rtd_measurement(uint32_t measurement_type) |
| mahphalke |
5:90166c496b01 | 687 | { |
| mahphalke |
5:90166c496b01 | 688 | return perform_rtd_measurement(AD7124_CONFIG_2WIRE_RTD, measurement_type); |
| mahphalke |
5:90166c496b01 | 689 | } |
| mahphalke |
5:90166c496b01 | 690 | |
| mahphalke |
5:90166c496b01 | 691 | |
| mahphalke |
5:90166c496b01 | 692 | /*! |
| mahphalke |
5:90166c496b01 | 693 | * @brief Perform the 3-wire RTD measurement |
| mahphalke |
5:90166c496b01 | 694 | * @param measurement_type[in] - Temperature measurement and display type |
| mahphalke |
5:90166c496b01 | 695 | * @return MENU_CONTINUE |
| mahphalke |
5:90166c496b01 | 696 | */ |
| mahphalke |
5:90166c496b01 | 697 | static int32_t perform_3wire_rtd_measurement(uint32_t measurement_type) |
| mahphalke |
5:90166c496b01 | 698 | { |
| mahphalke |
5:90166c496b01 | 699 | return perform_rtd_measurement(AD7124_CONFIG_3WIRE_RTD, measurement_type); |
| mahphalke |
5:90166c496b01 | 700 | } |
| mahphalke |
5:90166c496b01 | 701 | |
| mahphalke |
5:90166c496b01 | 702 | |
| mahphalke |
5:90166c496b01 | 703 | /*! |
| mahphalke |
5:90166c496b01 | 704 | * @brief Perform the 4-wire RTD measurement |
| mahphalke |
5:90166c496b01 | 705 | * @param measurement_type[in] - Temperature measurement and display type |
| mahphalke |
5:90166c496b01 | 706 | * @return MENU_CONTINUE |
| mahphalke |
5:90166c496b01 | 707 | */ |
| mahphalke |
5:90166c496b01 | 708 | static int32_t perform_4wire_rtd_measurement(uint32_t measurement_type) |
| mahphalke |
5:90166c496b01 | 709 | { |
| mahphalke |
5:90166c496b01 | 710 | return perform_rtd_measurement(AD7124_CONFIG_4WIRE_RTD, measurement_type); |
| mahphalke |
5:90166c496b01 | 711 | } |
| mahphalke |
5:90166c496b01 | 712 | |
| mahphalke |
5:90166c496b01 | 713 | |
| mahphalke |
5:90166c496b01 | 714 | /*! |
| mahphalke |
0:08ba94bc5a30 | 715 | * @brief Change the 3-wire RTD calibration type to user selected type |
| mahphalke |
0:08ba94bc5a30 | 716 | * @param calibration_type[in]- 3-wire RTD calibration type |
| mahphalke |
0:08ba94bc5a30 | 717 | * @return MENU_CONTINUE |
| mahphalke |
0:08ba94bc5a30 | 718 | */ |
| mahphalke |
0:08ba94bc5a30 | 719 | static int32_t change_3wire_rtd_calibration_type(uint32_t calibration_type) |
| mahphalke |
0:08ba94bc5a30 | 720 | { |
| mahphalke |
0:08ba94bc5a30 | 721 | rtd_3wire_calibration_type = calibration_type; |
| mahphalke |
0:08ba94bc5a30 | 722 | return MENU_CONTINUE; |
| mahphalke |
0:08ba94bc5a30 | 723 | } |
| mahphalke |
0:08ba94bc5a30 | 724 | |
| mahphalke |
0:08ba94bc5a30 | 725 | |
| mahphalke |
0:08ba94bc5a30 | 726 | /*! |
| mahphalke |
0:08ba94bc5a30 | 727 | * @brief Perform the 3-wire RTD calibration and measurement |
| mahphalke |
5:90166c496b01 | 728 | * @param measurement_type[in] - Temperature measurement and display type |
| mahphalke |
0:08ba94bc5a30 | 729 | * @return MENU_CONTINUE |
| mahphalke |
0:08ba94bc5a30 | 730 | */ |
| mahphalke |
5:90166c496b01 | 731 | static int32_t calibrate_and_measure_3wire_rtd(uint32_t measurement_type) |
| mahphalke |
0:08ba94bc5a30 | 732 | { |
| mahphalke |
5:90166c496b01 | 733 | int32_t sample_data[2][MAX_ADC_SAMPLES]; |
| mahphalke |
8:3d7b5897b028 | 734 | float rtd_calib_iout0_avg[MAX_RTD_SENSORS]; |
| mahphalke |
8:3d7b5897b028 | 735 | float rtd_calib_iout1_avg[MAX_RTD_SENSORS]; |
| mahphalke |
0:08ba94bc5a30 | 736 | bool adc_error = false; |
| mahphalke |
0:08ba94bc5a30 | 737 | float temperature; |
| mahphalke |
0:08ba94bc5a30 | 738 | float voltage; |
| mahphalke |
5:90166c496b01 | 739 | bool multiple_3wire_rtd_enabled = false; |
| mahphalke |
5:90166c496b01 | 740 | uint16_t sample_cnt; |
| mahphalke |
5:90166c496b01 | 741 | bool continue_measurement = false; |
| mahphalke |
0:08ba94bc5a30 | 742 | |
| mahphalke |
0:08ba94bc5a30 | 743 | const uint8_t rtd_3wire_iout0_source[] = { |
| mahphalke |
0:08ba94bc5a30 | 744 | RTD1_3WIRE_IOUT0, RTD2_3WIRE_IOUT0, RTD3_3WIRE_IOUT0, RTD4_3WIRE_IOUT0 |
| mahphalke |
0:08ba94bc5a30 | 745 | }; |
| mahphalke |
0:08ba94bc5a30 | 746 | |
| mahphalke |
0:08ba94bc5a30 | 747 | const uint8_t rtd_3wire_iout1_source[] = { |
| mahphalke |
0:08ba94bc5a30 | 748 | RTD1_3WIRE_IOUT1, RTD2_3WIRE_IOUT1, RTD3_3WIRE_IOUT1, RTD4_3WIRE_IOUT1 |
| mahphalke |
0:08ba94bc5a30 | 749 | }; |
| mahphalke |
0:08ba94bc5a30 | 750 | |
| mahphalke |
5:90166c496b01 | 751 | do { |
| mahphalke |
5:90166c496b01 | 752 | /* Perform additional configurations for 3-wire RTD */ |
| mahphalke |
5:90166c496b01 | 753 | if (do_3wire_rtd_configs(&multiple_3wire_rtd_enabled) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 754 | printf(EOL EOL "\tError Performing Measurement" EOL); |
| mahphalke |
5:90166c496b01 | 755 | adc_error = true; |
| mahphalke |
5:90166c496b01 | 756 | break; |
| mahphalke |
5:90166c496b01 | 757 | } |
| mahphalke |
0:08ba94bc5a30 | 758 | |
| mahphalke |
5:90166c496b01 | 759 | if (!multiple_3wire_rtd_enabled) { |
| mahphalke |
5:90166c496b01 | 760 | printf(EOL EOL |
| mahphalke |
5:90166c496b01 | 761 | "\tError in calibration!! Calibration is recommended only when multiple RTDs are connected" |
| mahphalke |
5:90166c496b01 | 762 | EOL); |
| mahphalke |
0:08ba94bc5a30 | 763 | |
| mahphalke |
5:90166c496b01 | 764 | adc_error = true; |
| mahphalke |
5:90166c496b01 | 765 | break; |
| mahphalke |
5:90166c496b01 | 766 | } |
| mahphalke |
5:90166c496b01 | 767 | } while (0); |
| mahphalke |
0:08ba94bc5a30 | 768 | |
| mahphalke |
5:90166c496b01 | 769 | if (adc_error) { |
| mahphalke |
5:90166c496b01 | 770 | adi_press_any_key_to_continue(); |
| mahphalke |
5:90166c496b01 | 771 | return MENU_CONTINUE; |
| mahphalke |
5:90166c496b01 | 772 | } |
| mahphalke |
0:08ba94bc5a30 | 773 | |
| mahphalke |
5:90166c496b01 | 774 | if (measurement_type == CONTINUOUS_MEASUREMENT) { |
| mahphalke |
5:90166c496b01 | 775 | printf(EOL"Press ESC key once to stop measurement..." EOL); |
| mahphalke |
5:90166c496b01 | 776 | mdelay(1000); |
| mahphalke |
5:90166c496b01 | 777 | continue_measurement = true; |
| mahphalke |
5:90166c496b01 | 778 | } |
| mahphalke |
0:08ba94bc5a30 | 779 | |
| mahphalke |
5:90166c496b01 | 780 | /* Print display header */ |
| mahphalke |
5:90166c496b01 | 781 | printf(EOL EOL EOL); |
| mahphalke |
5:90166c496b01 | 782 | for (uint8_t chn = SENSOR_CHANNEL0; |
| mahphalke |
5:90166c496b01 | 783 | chn < max_supported_sensors[AD7124_CONFIG_3WIRE_RTD]; chn++) { |
| mahphalke |
5:90166c496b01 | 784 | if (sensor_enable_status[chn]) { |
| mahphalke |
6:622270f7d476 | 785 | printf("\tRTD%d ", chn + 1); |
| mahphalke |
0:08ba94bc5a30 | 786 | } |
| mahphalke |
0:08ba94bc5a30 | 787 | } |
| mahphalke |
6:622270f7d476 | 788 | printf(EOL "\t-----------------------------------------------" EOL EOL); |
| mahphalke |
0:08ba94bc5a30 | 789 | |
| mahphalke |
5:90166c496b01 | 790 | do { |
| mahphalke |
5:90166c496b01 | 791 | /* Calibrate, Sample and Read all enabled RTD channels in sequence */ |
| mahphalke |
5:90166c496b01 | 792 | for (uint8_t chn = SENSOR_CHANNEL0; |
| mahphalke |
5:90166c496b01 | 793 | (chn < max_supported_sensors[AD7124_CONFIG_3WIRE_RTD]) && (!adc_error); |
| mahphalke |
5:90166c496b01 | 794 | chn++) { |
| mahphalke |
5:90166c496b01 | 795 | if (sensor_enable_status[chn]) { |
| mahphalke |
5:90166c496b01 | 796 | if (rtd_3wire_calibration_type == MEASURING_EXCITATION_CURRENT) { |
| mahphalke |
5:90166c496b01 | 797 | /* Part 1: Perform the calibration on current RTD sensor */ |
| mahphalke |
5:90166c496b01 | 798 | |
| mahphalke |
5:90166c496b01 | 799 | /* Enable and direct IOUT0 excitation current source */ |
| mahphalke |
5:90166c496b01 | 800 | ad7124_register_map[AD7124_IOCon1].value |= (AD7124_IO_CTRL1_REG_IOUT_CH0( |
| mahphalke |
5:90166c496b01 | 801 | rtd_3wire_iout0_source[chn]) | AD7124_IO_CTRL1_REG_IOUT0( |
| mahphalke |
5:90166c496b01 | 802 | RTD_IOUT0_250UA_EXC)); |
| mahphalke |
5:90166c496b01 | 803 | |
| mahphalke |
5:90166c496b01 | 804 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
5:90166c496b01 | 805 | ad7124_register_map[AD7124_IOCon1]) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 806 | adc_error = true; |
| mahphalke |
5:90166c496b01 | 807 | break; |
| mahphalke |
5:90166c496b01 | 808 | } |
| mahphalke |
5:90166c496b01 | 809 | |
| mahphalke |
5:90166c496b01 | 810 | /* Read adc averaged sample result for Iout0 excitation */ |
| mahphalke |
5:90166c496b01 | 811 | if (perform_adc_conversion(RTD_3WIRE_REF_MEASUREMENT_CHN, |
| mahphalke |
5:90166c496b01 | 812 | &n_sample_data[RTD_3WIRE_REF_MEASUREMENT_CHN], |
| mahphalke |
5:90166c496b01 | 813 | measurement_type) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 814 | adc_error = true; |
| mahphalke |
5:90166c496b01 | 815 | break; |
| mahphalke |
5:90166c496b01 | 816 | } |
| mahphalke |
5:90166c496b01 | 817 | |
| mahphalke |
5:90166c496b01 | 818 | if (measurement_type == AVERAGED_MEASUREMENT) { |
| mahphalke |
5:90166c496b01 | 819 | /* Get the equivalent ADC voltage */ |
| mahphalke |
5:90166c496b01 | 820 | voltage = ad7124_convert_sample_to_voltage(p_ad7124_dev, |
| mahphalke |
5:90166c496b01 | 821 | RTD_3WIRE_REF_MEASUREMENT_CHN, n_sample_data[RTD_3WIRE_REF_MEASUREMENT_CHN][0]); |
| mahphalke |
5:90166c496b01 | 822 | |
| mahphalke |
5:90166c496b01 | 823 | /* Calculate equivalent Iout0 current flowing through Rref resistance */ |
| mahphalke |
8:3d7b5897b028 | 824 | //rtd_calib_iout0[chn][0] = voltage / get_rtd_rref(); |
| mahphalke |
8:3d7b5897b028 | 825 | rtd_calib_iout0_avg[chn] = voltage / get_rtd_rref(); |
| mahphalke |
5:90166c496b01 | 826 | } else { |
| mahphalke |
5:90166c496b01 | 827 | for (sample_cnt = 0; sample_cnt < MAX_ADC_SAMPLES; sample_cnt++) { |
| mahphalke |
5:90166c496b01 | 828 | /* Get the equivalent ADC voltage */ |
| mahphalke |
5:90166c496b01 | 829 | voltage = ad7124_convert_sample_to_voltage(p_ad7124_dev, |
| mahphalke |
5:90166c496b01 | 830 | RTD_3WIRE_REF_MEASUREMENT_CHN, |
| mahphalke |
5:90166c496b01 | 831 | n_sample_data[RTD_3WIRE_REF_MEASUREMENT_CHN][sample_cnt]); |
| mahphalke |
5:90166c496b01 | 832 | |
| mahphalke |
5:90166c496b01 | 833 | /* Calculate equivalent Iout0 current flowing through Rref resistance */ |
| mahphalke |
8:3d7b5897b028 | 834 | //rtd_calib_iout0[chn][sample_cnt] = voltage / get_rtd_rref(); |
| mahphalke |
8:3d7b5897b028 | 835 | rtd_calib_iout0_avg[chn] += voltage / get_rtd_rref(); |
| mahphalke |
5:90166c496b01 | 836 | } |
| mahphalke |
8:3d7b5897b028 | 837 | |
| mahphalke |
8:3d7b5897b028 | 838 | rtd_calib_iout0_avg[chn] /= MAX_ADC_SAMPLES; |
| mahphalke |
5:90166c496b01 | 839 | } |
| mahphalke |
5:90166c496b01 | 840 | |
| mahphalke |
5:90166c496b01 | 841 | /* Turn off the Iout0 excitation current */ |
| mahphalke |
5:90166c496b01 | 842 | ad7124_register_map[AD7124_IOCon1].value &= ((~AD7124_IO_CTRL1_REG_IOUT0_MSK) |
| mahphalke |
5:90166c496b01 | 843 | & (~AD7124_IO_CTRL1_REG_IOUT_CH0_MSK)); |
| mahphalke |
5:90166c496b01 | 844 | |
| mahphalke |
5:90166c496b01 | 845 | /* Enable and direct IOUT1 excitation current source */ |
| mahphalke |
5:90166c496b01 | 846 | ad7124_register_map[AD7124_IOCon1].value |= (AD7124_IO_CTRL1_REG_IOUT_CH1( |
| mahphalke |
5:90166c496b01 | 847 | rtd_3wire_iout1_source[chn]) | AD7124_IO_CTRL1_REG_IOUT1( |
| mahphalke |
5:90166c496b01 | 848 | RTD_IOUT1_250UA_EXC)); |
| mahphalke |
5:90166c496b01 | 849 | |
| mahphalke |
5:90166c496b01 | 850 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
5:90166c496b01 | 851 | ad7124_register_map[AD7124_IOCon1]) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 852 | adc_error = true; |
| mahphalke |
5:90166c496b01 | 853 | break; |
| mahphalke |
5:90166c496b01 | 854 | } |
| mahphalke |
5:90166c496b01 | 855 | |
| mahphalke |
5:90166c496b01 | 856 | /* Read adc averaged sample result for Iout1 excitation */ |
| mahphalke |
5:90166c496b01 | 857 | if (perform_adc_conversion(RTD_3WIRE_REF_MEASUREMENT_CHN, |
| mahphalke |
5:90166c496b01 | 858 | &n_sample_data[RTD_3WIRE_REF_MEASUREMENT_CHN], |
| mahphalke |
5:90166c496b01 | 859 | measurement_type) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 860 | adc_error = true; |
| mahphalke |
5:90166c496b01 | 861 | break; |
| mahphalke |
5:90166c496b01 | 862 | } |
| mahphalke |
5:90166c496b01 | 863 | |
| mahphalke |
5:90166c496b01 | 864 | if (measurement_type == AVERAGED_MEASUREMENT) { |
| mahphalke |
5:90166c496b01 | 865 | /* Get the equivalent ADC voltage */ |
| mahphalke |
5:90166c496b01 | 866 | voltage = ad7124_convert_sample_to_voltage(p_ad7124_dev, |
| mahphalke |
5:90166c496b01 | 867 | RTD_3WIRE_REF_MEASUREMENT_CHN, |
| mahphalke |
5:90166c496b01 | 868 | n_sample_data[RTD_3WIRE_REF_MEASUREMENT_CHN][0]); |
| mahphalke |
5:90166c496b01 | 869 | |
| mahphalke |
5:90166c496b01 | 870 | /* Calculate equivalent Iout1 current flowing through Rref resistance */ |
| mahphalke |
8:3d7b5897b028 | 871 | //rtd_calib_iout1[chn][0] = voltage / get_rtd_rref(); |
| mahphalke |
8:3d7b5897b028 | 872 | rtd_calib_iout1_avg[chn] = voltage / get_rtd_rref(); |
| mahphalke |
5:90166c496b01 | 873 | } else { |
| mahphalke |
5:90166c496b01 | 874 | for (sample_cnt = 0; sample_cnt < MAX_ADC_SAMPLES; sample_cnt++) { |
| mahphalke |
5:90166c496b01 | 875 | /* Get the equivalent ADC voltage */ |
| mahphalke |
5:90166c496b01 | 876 | voltage = ad7124_convert_sample_to_voltage(p_ad7124_dev, |
| mahphalke |
5:90166c496b01 | 877 | RTD_3WIRE_REF_MEASUREMENT_CHN, |
| mahphalke |
5:90166c496b01 | 878 | n_sample_data[RTD_3WIRE_REF_MEASUREMENT_CHN][sample_cnt]); |
| mahphalke |
5:90166c496b01 | 879 | |
| mahphalke |
5:90166c496b01 | 880 | /* Calculate equivalent Iout1 current flowing through Rref resistance */ |
| mahphalke |
8:3d7b5897b028 | 881 | //rtd_calib_iout1[chn][sample_cnt] = voltage / get_rtd_rref(); |
| mahphalke |
8:3d7b5897b028 | 882 | rtd_calib_iout1_avg[chn] += voltage / get_rtd_rref(); |
| mahphalke |
5:90166c496b01 | 883 | } |
| mahphalke |
8:3d7b5897b028 | 884 | |
| mahphalke |
8:3d7b5897b028 | 885 | rtd_calib_iout1_avg[chn] /= MAX_ADC_SAMPLES; |
| mahphalke |
5:90166c496b01 | 886 | } |
| mahphalke |
8:3d7b5897b028 | 887 | |
| mahphalke |
8:3d7b5897b028 | 888 | // for testing |
| mahphalke |
8:3d7b5897b028 | 889 | printf("Iout_avg (RTD%d): %f" EOL, chn +1, rtd_calib_iout1_avg[chn] / |
| mahphalke |
8:3d7b5897b028 | 890 | rtd_calib_iout0_avg[chn]); |
| mahphalke |
5:90166c496b01 | 891 | |
| mahphalke |
5:90166c496b01 | 892 | /* Turn off the Iout1 excitation current */ |
| mahphalke |
5:90166c496b01 | 893 | ad7124_register_map[AD7124_IOCon1].value &= ((~AD7124_IO_CTRL1_REG_IOUT1_MSK) |
| mahphalke |
5:90166c496b01 | 894 | & (~AD7124_IO_CTRL1_REG_IOUT_CH1_MSK)); |
| mahphalke |
5:90166c496b01 | 895 | |
| mahphalke |
5:90166c496b01 | 896 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
5:90166c496b01 | 897 | ad7124_register_map[AD7124_IOCon1]) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 898 | adc_error = true; |
| mahphalke |
5:90166c496b01 | 899 | break; |
| mahphalke |
5:90166c496b01 | 900 | } |
| mahphalke |
5:90166c496b01 | 901 | |
| mahphalke |
5:90166c496b01 | 902 | /* Part 2: Perform the ADC sampling on calibrated RTD sensor channel */ |
| mahphalke |
5:90166c496b01 | 903 | if (!do_rtd_sensor_adc_sampling(AD7124_CONFIG_3WIRE_RTD, |
| mahphalke |
5:90166c496b01 | 904 | chn, &n_sample_data[chn], measurement_type, multiple_3wire_rtd_enabled)) { |
| mahphalke |
5:90166c496b01 | 905 | adc_error = true; |
| mahphalke |
5:90166c496b01 | 906 | break; |
| mahphalke |
5:90166c496b01 | 907 | } |
| mahphalke |
5:90166c496b01 | 908 | } else { |
| mahphalke |
5:90166c496b01 | 909 | /* Calibration by Iout excitation chopping. |
| mahphalke |
5:90166c496b01 | 910 | * Part1: Direct the Iout excitation currents */ |
| mahphalke |
5:90166c496b01 | 911 | |
| mahphalke |
5:90166c496b01 | 912 | /* Enable and direct IOUT0 excitation current source */ |
| mahphalke |
5:90166c496b01 | 913 | ad7124_register_map[AD7124_IOCon1].value |= (AD7124_IO_CTRL1_REG_IOUT_CH0( |
| mahphalke |
5:90166c496b01 | 914 | rtd_3wire_iout0_source[chn]) | AD7124_IO_CTRL1_REG_IOUT0( |
| mahphalke |
5:90166c496b01 | 915 | RTD_IOUT0_250UA_EXC)); |
| mahphalke |
0:08ba94bc5a30 | 916 | |
| mahphalke |
5:90166c496b01 | 917 | /* Enable and direct IOUT1 excitation current source */ |
| mahphalke |
5:90166c496b01 | 918 | ad7124_register_map[AD7124_IOCon1].value |= (AD7124_IO_CTRL1_REG_IOUT_CH1( |
| mahphalke |
5:90166c496b01 | 919 | rtd_3wire_iout1_source[chn]) | AD7124_IO_CTRL1_REG_IOUT1( |
| mahphalke |
5:90166c496b01 | 920 | RTD_IOUT1_250UA_EXC)); |
| mahphalke |
5:90166c496b01 | 921 | |
| mahphalke |
5:90166c496b01 | 922 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
5:90166c496b01 | 923 | ad7124_register_map[AD7124_IOCon1]) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 924 | adc_error = true; |
| mahphalke |
5:90166c496b01 | 925 | break; |
| mahphalke |
5:90166c496b01 | 926 | } |
| mahphalke |
5:90166c496b01 | 927 | |
| mahphalke |
5:90166c496b01 | 928 | /* Read adc averaged sample result for selected RTD sensor channel */ |
| mahphalke |
5:90166c496b01 | 929 | if (perform_adc_conversion(chn, &sample_data[0], |
| mahphalke |
5:90166c496b01 | 930 | measurement_type) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 931 | adc_error = true; |
| mahphalke |
5:90166c496b01 | 932 | break; |
| mahphalke |
5:90166c496b01 | 933 | } |
| mahphalke |
5:90166c496b01 | 934 | |
| mahphalke |
5:90166c496b01 | 935 | /* Reset Iout registers for loading new configs */ |
| mahphalke |
5:90166c496b01 | 936 | ad7124_register_map[AD7124_IOCon1].value &= ((~AD7124_IO_CTRL1_REG_IOUT0_MSK) |
| mahphalke |
5:90166c496b01 | 937 | & (~AD7124_IO_CTRL1_REG_IOUT_CH0_MSK) & (~AD7124_IO_CTRL1_REG_IOUT1_MSK) |
| mahphalke |
5:90166c496b01 | 938 | & (~AD7124_IO_CTRL1_REG_IOUT_CH1_MSK)); |
| mahphalke |
5:90166c496b01 | 939 | |
| mahphalke |
5:90166c496b01 | 940 | /* Part2: Swap the Iout excitation sources and direct currents */ |
| mahphalke |
5:90166c496b01 | 941 | |
| mahphalke |
5:90166c496b01 | 942 | /* Enable and direct IOUT0 excitation current source */ |
| mahphalke |
5:90166c496b01 | 943 | ad7124_register_map[AD7124_IOCon1].value |= (AD7124_IO_CTRL1_REG_IOUT_CH0( |
| mahphalke |
5:90166c496b01 | 944 | rtd_3wire_iout1_source[chn]) | AD7124_IO_CTRL1_REG_IOUT0( |
| mahphalke |
5:90166c496b01 | 945 | RTD_IOUT0_250UA_EXC)); |
| mahphalke |
5:90166c496b01 | 946 | |
| mahphalke |
5:90166c496b01 | 947 | /* Enable and direct IOUT1 excitation current source */ |
| mahphalke |
5:90166c496b01 | 948 | ad7124_register_map[AD7124_IOCon1].value |= (AD7124_IO_CTRL1_REG_IOUT_CH1( |
| mahphalke |
5:90166c496b01 | 949 | rtd_3wire_iout0_source[chn]) | AD7124_IO_CTRL1_REG_IOUT1( |
| mahphalke |
5:90166c496b01 | 950 | RTD_IOUT1_250UA_EXC)); |
| mahphalke |
5:90166c496b01 | 951 | |
| mahphalke |
5:90166c496b01 | 952 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
5:90166c496b01 | 953 | ad7124_register_map[AD7124_IOCon1]) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 954 | adc_error = true; |
| mahphalke |
5:90166c496b01 | 955 | break; |
| mahphalke |
5:90166c496b01 | 956 | } |
| mahphalke |
5:90166c496b01 | 957 | |
| mahphalke |
5:90166c496b01 | 958 | /* Read adc averaged sample result for selected RTD sensor channel */ |
| mahphalke |
5:90166c496b01 | 959 | if (perform_adc_conversion(chn, &sample_data[1], |
| mahphalke |
5:90166c496b01 | 960 | measurement_type) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 961 | adc_error = true; |
| mahphalke |
5:90166c496b01 | 962 | break; |
| mahphalke |
5:90166c496b01 | 963 | } |
| mahphalke |
5:90166c496b01 | 964 | |
| mahphalke |
5:90166c496b01 | 965 | /* Turn off the excitation currents */ |
| mahphalke |
5:90166c496b01 | 966 | ad7124_register_map[AD7124_IOCon1].value &= ((~AD7124_IO_CTRL1_REG_IOUT0_MSK) |
| mahphalke |
5:90166c496b01 | 967 | & (~AD7124_IO_CTRL1_REG_IOUT_CH0_MSK) & (~AD7124_IO_CTRL1_REG_IOUT1_MSK) |
| mahphalke |
5:90166c496b01 | 968 | & (~AD7124_IO_CTRL1_REG_IOUT_CH1_MSK)); |
| mahphalke |
5:90166c496b01 | 969 | |
| mahphalke |
5:90166c496b01 | 970 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
5:90166c496b01 | 971 | ad7124_register_map[AD7124_IOCon1]) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 972 | adc_error = true; |
| mahphalke |
5:90166c496b01 | 973 | break; |
| mahphalke |
5:90166c496b01 | 974 | } |
| mahphalke |
0:08ba94bc5a30 | 975 | |
| mahphalke |
5:90166c496b01 | 976 | /* Get ADC averaged result */ |
| mahphalke |
5:90166c496b01 | 977 | if (measurement_type == AVERAGED_MEASUREMENT) { |
| mahphalke |
5:90166c496b01 | 978 | n_sample_data[chn][0] = (sample_data[0][0] + sample_data[1][0]) / 2; |
| mahphalke |
5:90166c496b01 | 979 | } else { |
| mahphalke |
5:90166c496b01 | 980 | for (sample_cnt = 0; sample_cnt < MAX_ADC_SAMPLES; sample_cnt++) { |
| mahphalke |
5:90166c496b01 | 981 | n_sample_data[chn][sample_cnt] = (sample_data[0][sample_cnt] + |
| mahphalke |
5:90166c496b01 | 982 | sample_data[1][sample_cnt]) / 2; |
| mahphalke |
5:90166c496b01 | 983 | } |
| mahphalke |
5:90166c496b01 | 984 | } |
| mahphalke |
5:90166c496b01 | 985 | } |
| mahphalke |
5:90166c496b01 | 986 | } |
| mahphalke |
5:90166c496b01 | 987 | } |
| mahphalke |
5:90166c496b01 | 988 | |
| mahphalke |
5:90166c496b01 | 989 | if (adc_error) { |
| mahphalke |
5:90166c496b01 | 990 | printf(EOL EOL "\tError Performing Measurement" EOL); |
| mahphalke |
5:90166c496b01 | 991 | break; |
| mahphalke |
5:90166c496b01 | 992 | } else { |
| mahphalke |
5:90166c496b01 | 993 | /* Calculate temperature and display result */ |
| mahphalke |
5:90166c496b01 | 994 | if (measurement_type == AVERAGED_MEASUREMENT) { |
| mahphalke |
5:90166c496b01 | 995 | for (uint8_t chn = SENSOR_CHANNEL0; |
| mahphalke |
5:90166c496b01 | 996 | chn < max_supported_sensors[AD7124_CONFIG_3WIRE_RTD]; |
| mahphalke |
5:90166c496b01 | 997 | chn++) { |
| mahphalke |
5:90166c496b01 | 998 | if (sensor_enable_status[chn]) { |
| mahphalke |
5:90166c496b01 | 999 | if (rtd_3wire_calibration_type == MEASURING_EXCITATION_CURRENT) { |
| mahphalke |
8:3d7b5897b028 | 1000 | //store_rtd_calibrated_iout_ratio((rtd_calib_iout1[chn][0] / |
| mahphalke |
8:3d7b5897b028 | 1001 | // rtd_calib_iout0[chn][0]), true); |
| mahphalke |
8:3d7b5897b028 | 1002 | |
| mahphalke |
8:3d7b5897b028 | 1003 | store_rtd_calibrated_iout_ratio((rtd_calib_iout1_avg[chn] / |
| mahphalke |
8:3d7b5897b028 | 1004 | rtd_calib_iout0_avg[chn]), true); |
| mahphalke |
5:90166c496b01 | 1005 | } |
| mahphalke |
5:90166c496b01 | 1006 | |
| mahphalke |
5:90166c496b01 | 1007 | temperature = get_rtd_temperature(n_sample_data[chn][0], MULTI_3WIRE_RTD_GAIN); |
| mahphalke |
6:622270f7d476 | 1008 | sprintf(decimal_eqv_str, "%.4f ", temperature); |
| mahphalke |
6:622270f7d476 | 1009 | strcat(decimal_eqv_str_arr, decimal_eqv_str); |
| mahphalke |
7:ef6fffc246a6 | 1010 | |
| mahphalke |
7:ef6fffc246a6 | 1011 | // for testing |
| mahphalke |
8:3d7b5897b028 | 1012 | //sprintf(decimal_eqv_str, "%.4f ", rtd_calib_iout1[chn][0] / |
| mahphalke |
8:3d7b5897b028 | 1013 | // rtd_calib_iout0[chn][0]); |
| mahphalke |
8:3d7b5897b028 | 1014 | //strcat(decimal_eqv_str_arr, decimal_eqv_str); |
| mahphalke |
5:90166c496b01 | 1015 | } |
| mahphalke |
5:90166c496b01 | 1016 | } |
| mahphalke |
6:622270f7d476 | 1017 | printf("\t%s" EOL EOL, decimal_eqv_str_arr); |
| mahphalke |
6:622270f7d476 | 1018 | decimal_eqv_str_arr[0] = '\0'; |
| mahphalke |
5:90166c496b01 | 1019 | } else { |
| mahphalke |
5:90166c496b01 | 1020 | for (sample_cnt = 0; sample_cnt < MAX_ADC_SAMPLES; sample_cnt++) { |
| mahphalke |
5:90166c496b01 | 1021 | for (uint8_t chn = SENSOR_CHANNEL0; |
| mahphalke |
5:90166c496b01 | 1022 | chn < max_supported_sensors[AD7124_CONFIG_3WIRE_RTD]; |
| mahphalke |
5:90166c496b01 | 1023 | chn++) { |
| mahphalke |
5:90166c496b01 | 1024 | if (sensor_enable_status[chn]) { |
| mahphalke |
5:90166c496b01 | 1025 | if (rtd_3wire_calibration_type == MEASURING_EXCITATION_CURRENT) { |
| mahphalke |
8:3d7b5897b028 | 1026 | //store_rtd_calibrated_iout_ratio((rtd_calib_iout1[chn][sample_cnt] / |
| mahphalke |
8:3d7b5897b028 | 1027 | // rtd_calib_iout0[chn][sample_cnt]), true); |
| mahphalke |
8:3d7b5897b028 | 1028 | |
| mahphalke |
8:3d7b5897b028 | 1029 | store_rtd_calibrated_iout_ratio((rtd_calib_iout1_avg[chn] / |
| mahphalke |
8:3d7b5897b028 | 1030 | rtd_calib_iout0_avg[chn]), true); |
| mahphalke |
5:90166c496b01 | 1031 | } |
| mahphalke |
5:90166c496b01 | 1032 | |
| mahphalke |
5:90166c496b01 | 1033 | temperature = get_rtd_temperature(n_sample_data[chn][sample_cnt], |
| mahphalke |
5:90166c496b01 | 1034 | MULTI_3WIRE_RTD_GAIN); |
| mahphalke |
6:622270f7d476 | 1035 | sprintf(decimal_eqv_str, "%.4f ", temperature); |
| mahphalke |
6:622270f7d476 | 1036 | strcat(decimal_eqv_str_arr, decimal_eqv_str); |
| mahphalke |
7:ef6fffc246a6 | 1037 | |
| mahphalke |
7:ef6fffc246a6 | 1038 | // for testing |
| mahphalke |
8:3d7b5897b028 | 1039 | //sprintf(decimal_eqv_str, "%.4f ", rtd_calib_iout1[chn][sample_cnt] / |
| mahphalke |
8:3d7b5897b028 | 1040 | // rtd_calib_iout0[chn][sample_cnt]); |
| mahphalke |
8:3d7b5897b028 | 1041 | //strcat(decimal_eqv_str_arr, decimal_eqv_str); |
| mahphalke |
5:90166c496b01 | 1042 | } |
| mahphalke |
5:90166c496b01 | 1043 | } |
| mahphalke |
6:622270f7d476 | 1044 | printf("\t%s" EOL EOL, decimal_eqv_str_arr); |
| mahphalke |
6:622270f7d476 | 1045 | decimal_eqv_str_arr[0] = '\0'; |
| mahphalke |
5:90166c496b01 | 1046 | } |
| mahphalke |
5:90166c496b01 | 1047 | } |
| mahphalke |
5:90166c496b01 | 1048 | } |
| mahphalke |
5:90166c496b01 | 1049 | } while (continue_measurement && !was_escape_key_pressed()); |
| mahphalke |
5:90166c496b01 | 1050 | |
| mahphalke |
5:90166c496b01 | 1051 | /* Reset the calibration constant value after measurement */ |
| mahphalke |
5:90166c496b01 | 1052 | store_rtd_calibrated_iout_ratio(1, false); |
| mahphalke |
0:08ba94bc5a30 | 1053 | |
| mahphalke |
0:08ba94bc5a30 | 1054 | /* Put ADC into standby mode */ |
| mahphalke |
0:08ba94bc5a30 | 1055 | ad7124_register_map[AD7124_ADC_Control].value &= (~AD7124_ADC_CTRL_REG_MSK); |
| mahphalke |
0:08ba94bc5a30 | 1056 | ad7124_register_map[AD7124_ADC_Control].value |= AD7124_ADC_CTRL_REG_MODE( |
| mahphalke |
0:08ba94bc5a30 | 1057 | STANDBY_MODE); |
| mahphalke |
0:08ba94bc5a30 | 1058 | ad7124_write_register(p_ad7124_dev, ad7124_register_map[AD7124_ADC_Control]); |
| mahphalke |
0:08ba94bc5a30 | 1059 | |
| mahphalke |
0:08ba94bc5a30 | 1060 | adi_press_any_key_to_continue(); |
| mahphalke |
0:08ba94bc5a30 | 1061 | return MENU_CONTINUE; |
| mahphalke |
0:08ba94bc5a30 | 1062 | } |
| mahphalke |
0:08ba94bc5a30 | 1063 | |
| mahphalke |
0:08ba94bc5a30 | 1064 | |
| mahphalke |
0:08ba94bc5a30 | 1065 | /*! |
| mahphalke |
0:08ba94bc5a30 | 1066 | * @brief Perform the multiple NTC thermistor sensors measurement |
| mahphalke |
5:90166c496b01 | 1067 | * @param measurement_type[in]- Temperature measurement and display type |
| mahphalke |
0:08ba94bc5a30 | 1068 | * @return MENU_CONTINUE |
| mahphalke |
0:08ba94bc5a30 | 1069 | */ |
| mahphalke |
5:90166c496b01 | 1070 | int32_t perform_ntc_thermistor_measurement(uint32_t measurement_type) |
| mahphalke |
0:08ba94bc5a30 | 1071 | { |
| mahphalke |
0:08ba94bc5a30 | 1072 | bool adc_error = false; |
| mahphalke |
5:90166c496b01 | 1073 | uint16_t sample_cnt; |
| mahphalke |
5:90166c496b01 | 1074 | bool continue_measurement = false; |
| mahphalke |
0:08ba94bc5a30 | 1075 | float temperature; |
| mahphalke |
0:08ba94bc5a30 | 1076 | |
| mahphalke |
5:90166c496b01 | 1077 | if (measurement_type == CONTINUOUS_MEASUREMENT) { |
| mahphalke |
5:90166c496b01 | 1078 | printf(EOL"Press ESC key once to stop measurement..." EOL); |
| mahphalke |
5:90166c496b01 | 1079 | mdelay(1000); |
| mahphalke |
5:90166c496b01 | 1080 | continue_measurement = true; |
| mahphalke |
0:08ba94bc5a30 | 1081 | } |
| mahphalke |
0:08ba94bc5a30 | 1082 | |
| mahphalke |
5:90166c496b01 | 1083 | /* Print display header */ |
| mahphalke |
5:90166c496b01 | 1084 | printf(EOL EOL EOL); |
| mahphalke |
5:90166c496b01 | 1085 | for (uint8_t chn = SENSOR_CHANNEL0; |
| mahphalke |
5:90166c496b01 | 1086 | chn < max_supported_sensors[AD7124_CONFIG_THERMISTOR]; chn++) { |
| mahphalke |
5:90166c496b01 | 1087 | if (sensor_enable_status[chn]) { |
| mahphalke |
6:622270f7d476 | 1088 | printf("\tNTC%d ", chn + 1); |
| mahphalke |
5:90166c496b01 | 1089 | } |
| mahphalke |
5:90166c496b01 | 1090 | } |
| mahphalke |
6:622270f7d476 | 1091 | printf(EOL "\t-----------------------------------------------" EOL EOL); |
| mahphalke |
0:08ba94bc5a30 | 1092 | |
| mahphalke |
5:90166c496b01 | 1093 | do { |
| mahphalke |
5:90166c496b01 | 1094 | /* Sample and Read all enabled NTC channels in sequence */ |
| mahphalke |
5:90166c496b01 | 1095 | for (uint8_t chn = SENSOR_CHANNEL0; |
| mahphalke |
5:90166c496b01 | 1096 | chn < max_supported_sensors[AD7124_CONFIG_THERMISTOR]; |
| mahphalke |
0:08ba94bc5a30 | 1097 | chn++) { |
| mahphalke |
0:08ba94bc5a30 | 1098 | if (sensor_enable_status[chn]) { |
| mahphalke |
5:90166c496b01 | 1099 | if (perform_adc_conversion(chn, &n_sample_data[chn], |
| mahphalke |
5:90166c496b01 | 1100 | measurement_type) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 1101 | adc_error = true; |
| mahphalke |
5:90166c496b01 | 1102 | break; |
| mahphalke |
5:90166c496b01 | 1103 | } |
| mahphalke |
0:08ba94bc5a30 | 1104 | } |
| mahphalke |
0:08ba94bc5a30 | 1105 | } |
| mahphalke |
5:90166c496b01 | 1106 | |
| mahphalke |
5:90166c496b01 | 1107 | if (adc_error) { |
| mahphalke |
5:90166c496b01 | 1108 | printf(EOL EOL "\tError Performing Measurement" EOL); |
| mahphalke |
5:90166c496b01 | 1109 | break; |
| mahphalke |
5:90166c496b01 | 1110 | } else { |
| mahphalke |
5:90166c496b01 | 1111 | /* Calculate temperature and display result */ |
| mahphalke |
5:90166c496b01 | 1112 | if (measurement_type == AVERAGED_MEASUREMENT) { |
| mahphalke |
5:90166c496b01 | 1113 | for (uint8_t chn = SENSOR_CHANNEL0; |
| mahphalke |
5:90166c496b01 | 1114 | chn < max_supported_sensors[AD7124_CONFIG_THERMISTOR]; |
| mahphalke |
5:90166c496b01 | 1115 | chn++) { |
| mahphalke |
5:90166c496b01 | 1116 | if (sensor_enable_status[chn]) { |
| mahphalke |
5:90166c496b01 | 1117 | temperature = get_ntc_thermistor_temperature(n_sample_data[chn][0]); |
| mahphalke |
6:622270f7d476 | 1118 | sprintf(decimal_eqv_str, "%.4f ", temperature); |
| mahphalke |
6:622270f7d476 | 1119 | strcat(decimal_eqv_str_arr, decimal_eqv_str); |
| mahphalke |
5:90166c496b01 | 1120 | } |
| mahphalke |
5:90166c496b01 | 1121 | } |
| mahphalke |
6:622270f7d476 | 1122 | printf("\t%s" EOL EOL, decimal_eqv_str_arr); |
| mahphalke |
6:622270f7d476 | 1123 | decimal_eqv_str_arr[0] = '\0'; |
| mahphalke |
5:90166c496b01 | 1124 | } else { |
| mahphalke |
5:90166c496b01 | 1125 | for (sample_cnt = 0; sample_cnt < MAX_ADC_SAMPLES; sample_cnt++) { |
| mahphalke |
5:90166c496b01 | 1126 | for (uint8_t chn = SENSOR_CHANNEL0; |
| mahphalke |
5:90166c496b01 | 1127 | chn < max_supported_sensors[AD7124_CONFIG_THERMISTOR]; |
| mahphalke |
5:90166c496b01 | 1128 | chn++) { |
| mahphalke |
5:90166c496b01 | 1129 | if (sensor_enable_status[chn]) { |
| mahphalke |
5:90166c496b01 | 1130 | temperature = get_ntc_thermistor_temperature(n_sample_data[chn][sample_cnt]); |
| mahphalke |
6:622270f7d476 | 1131 | sprintf(decimal_eqv_str, "%.4f ", temperature); |
| mahphalke |
6:622270f7d476 | 1132 | strcat(decimal_eqv_str_arr, decimal_eqv_str); |
| mahphalke |
5:90166c496b01 | 1133 | } |
| mahphalke |
5:90166c496b01 | 1134 | } |
| mahphalke |
6:622270f7d476 | 1135 | printf("\t%s" EOL EOL, decimal_eqv_str_arr); |
| mahphalke |
6:622270f7d476 | 1136 | decimal_eqv_str_arr[0] = '\0'; |
| mahphalke |
5:90166c496b01 | 1137 | } |
| mahphalke |
5:90166c496b01 | 1138 | } |
| mahphalke |
5:90166c496b01 | 1139 | } |
| mahphalke |
5:90166c496b01 | 1140 | } while (continue_measurement && !was_escape_key_pressed()); |
| mahphalke |
0:08ba94bc5a30 | 1141 | |
| mahphalke |
0:08ba94bc5a30 | 1142 | /* Put ADC into standby mode */ |
| mahphalke |
0:08ba94bc5a30 | 1143 | ad7124_register_map[AD7124_ADC_Control].value &= (~AD7124_ADC_CTRL_REG_MSK); |
| mahphalke |
0:08ba94bc5a30 | 1144 | ad7124_register_map[AD7124_ADC_Control].value |= AD7124_ADC_CTRL_REG_MODE( |
| mahphalke |
0:08ba94bc5a30 | 1145 | STANDBY_MODE); |
| mahphalke |
0:08ba94bc5a30 | 1146 | ad7124_write_register(p_ad7124_dev, ad7124_register_map[AD7124_ADC_Control]); |
| mahphalke |
0:08ba94bc5a30 | 1147 | |
| mahphalke |
0:08ba94bc5a30 | 1148 | adi_press_any_key_to_continue(); |
| mahphalke |
0:08ba94bc5a30 | 1149 | return MENU_CONTINUE; |
| mahphalke |
0:08ba94bc5a30 | 1150 | } |
| mahphalke |
0:08ba94bc5a30 | 1151 | |
| mahphalke |
0:08ba94bc5a30 | 1152 | |
| mahphalke |
0:08ba94bc5a30 | 1153 | /*! |
| mahphalke |
0:08ba94bc5a30 | 1154 | * @brief Perform the cold junction compensation (CJC) measurement |
| mahphalke |
5:90166c496b01 | 1155 | * @param *data[out]- Pointer to array to read data into |
| mahphalke |
5:90166c496b01 | 1156 | * @param measurement_type[in]- Temperature measurement and display type |
| mahphalke |
0:08ba94bc5a30 | 1157 | * @return SUCCESS/FAILURE |
| mahphalke |
0:08ba94bc5a30 | 1158 | * @note Both CJCs uses similar excitation and ratiometric measurement |
| mahphalke |
0:08ba94bc5a30 | 1159 | * logic |
| mahphalke |
0:08ba94bc5a30 | 1160 | */ |
| mahphalke |
5:90166c496b01 | 1161 | int32_t perform_cjc_measurement(int32_t (*data)[MAX_ADC_SAMPLES], |
| mahphalke |
5:90166c496b01 | 1162 | sensor_measurement_type measurement_type) |
| mahphalke |
0:08ba94bc5a30 | 1163 | { |
| mahphalke |
0:08ba94bc5a30 | 1164 | int32_t iout0_input, iout_exc; |
| mahphalke |
0:08ba94bc5a30 | 1165 | int32_t input_chn; |
| mahphalke |
5:90166c496b01 | 1166 | int32_t gain; |
| mahphalke |
5:90166c496b01 | 1167 | uint8_t setup; |
| mahphalke |
0:08ba94bc5a30 | 1168 | |
| mahphalke |
0:08ba94bc5a30 | 1169 | switch (current_cjc_sensor) { |
| mahphalke |
0:08ba94bc5a30 | 1170 | case PT100_4WIRE_RTD: |
| mahphalke |
5:90166c496b01 | 1171 | iout0_input = CJC_RTD_IOUT0; |
| mahphalke |
5:90166c496b01 | 1172 | iout_exc = CJC_RTD_IOUT0_EXC; |
| mahphalke |
0:08ba94bc5a30 | 1173 | input_chn = CJC_RTD_CHN; |
| mahphalke |
5:90166c496b01 | 1174 | gain = RTD_4WIRE_GAIN_VALUE; |
| mahphalke |
5:90166c496b01 | 1175 | break; |
| mahphalke |
5:90166c496b01 | 1176 | |
| mahphalke |
5:90166c496b01 | 1177 | case PT1000_2WIRE_RTD: |
| mahphalke |
5:90166c496b01 | 1178 | iout0_input = CJC_RTD_IOUT0; |
| mahphalke |
5:90166c496b01 | 1179 | iout_exc = CJC_RTD_IOUT0_EXC; |
| mahphalke |
5:90166c496b01 | 1180 | input_chn = CJC_RTD_CHN; |
| mahphalke |
5:90166c496b01 | 1181 | gain = RTD_PT1000_GAIN_VALUE; |
| mahphalke |
0:08ba94bc5a30 | 1182 | break; |
| mahphalke |
0:08ba94bc5a30 | 1183 | |
| mahphalke |
0:08ba94bc5a30 | 1184 | case THERMISTOR_PTC_KY81_110: |
| mahphalke |
0:08ba94bc5a30 | 1185 | iout0_input = CJC_PTC_THERMISTOR_IOUT0; |
| mahphalke |
0:08ba94bc5a30 | 1186 | iout_exc = CJC_PTC_THERMISTOR_IOUT0_EXC; |
| mahphalke |
0:08ba94bc5a30 | 1187 | input_chn = CJC_THERMISTOR_CHN; |
| mahphalke |
5:90166c496b01 | 1188 | gain = THERMISTOR_GAIN_VALUE; |
| mahphalke |
0:08ba94bc5a30 | 1189 | break; |
| mahphalke |
0:08ba94bc5a30 | 1190 | |
| mahphalke |
0:08ba94bc5a30 | 1191 | default: |
| mahphalke |
0:08ba94bc5a30 | 1192 | return FAILURE; |
| mahphalke |
0:08ba94bc5a30 | 1193 | } |
| mahphalke |
0:08ba94bc5a30 | 1194 | |
| mahphalke |
5:90166c496b01 | 1195 | setup = ad7124_get_channel_setup(p_ad7124_dev, input_chn); |
| mahphalke |
5:90166c496b01 | 1196 | |
| mahphalke |
5:90166c496b01 | 1197 | /* Set the gain corresponding to selected CJC sensor */ |
| mahphalke |
5:90166c496b01 | 1198 | ad7124_register_map[AD7124_Config_0 + setup].value &= (~AD7124_CFG_REG_PGA_MSK); |
| mahphalke |
5:90166c496b01 | 1199 | ad7124_register_map[AD7124_Config_0 + setup].value |= AD7124_CFG_REG_PGA(gain); |
| mahphalke |
5:90166c496b01 | 1200 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
5:90166c496b01 | 1201 | ad7124_register_map[AD7124_Config_0 + setup]) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 1202 | return FAILURE; |
| mahphalke |
5:90166c496b01 | 1203 | } |
| mahphalke |
5:90166c496b01 | 1204 | |
| mahphalke |
0:08ba94bc5a30 | 1205 | /* Enable and direct IOUT0 excitation current source for CJ sensor measurement */ |
| mahphalke |
0:08ba94bc5a30 | 1206 | ad7124_register_map[AD7124_IOCon1].value |= (AD7124_IO_CTRL1_REG_IOUT_CH0( |
| mahphalke |
0:08ba94bc5a30 | 1207 | iout0_input) | AD7124_IO_CTRL1_REG_IOUT0(iout_exc)); |
| mahphalke |
0:08ba94bc5a30 | 1208 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
0:08ba94bc5a30 | 1209 | ad7124_register_map[AD7124_IOCon1]) != SUCCESS) { |
| mahphalke |
0:08ba94bc5a30 | 1210 | return FAILURE; |
| mahphalke |
0:08ba94bc5a30 | 1211 | } |
| mahphalke |
0:08ba94bc5a30 | 1212 | |
| mahphalke |
5:90166c496b01 | 1213 | if (perform_adc_conversion(input_chn, data, measurement_type) == FAILURE) { |
| mahphalke |
0:08ba94bc5a30 | 1214 | return FAILURE; |
| mahphalke |
0:08ba94bc5a30 | 1215 | } |
| mahphalke |
0:08ba94bc5a30 | 1216 | |
| mahphalke |
0:08ba94bc5a30 | 1217 | /* Turn off the excitation current */ |
| mahphalke |
0:08ba94bc5a30 | 1218 | ad7124_register_map[AD7124_IOCon1].value &= ((~AD7124_IO_CTRL1_REG_IOUT0_MSK) |
| mahphalke |
0:08ba94bc5a30 | 1219 | & (~AD7124_IO_CTRL1_REG_IOUT_CH0_MSK)); |
| mahphalke |
0:08ba94bc5a30 | 1220 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
0:08ba94bc5a30 | 1221 | ad7124_register_map[AD7124_IOCon1]) != SUCCESS) { |
| mahphalke |
0:08ba94bc5a30 | 1222 | return FAILURE; |
| mahphalke |
0:08ba94bc5a30 | 1223 | } |
| mahphalke |
0:08ba94bc5a30 | 1224 | |
| mahphalke |
0:08ba94bc5a30 | 1225 | return SUCCESS; |
| mahphalke |
0:08ba94bc5a30 | 1226 | } |
| mahphalke |
0:08ba94bc5a30 | 1227 | |
| mahphalke |
0:08ba94bc5a30 | 1228 | |
| mahphalke |
0:08ba94bc5a30 | 1229 | /*! |
| mahphalke |
0:08ba94bc5a30 | 1230 | * @brief Perform the multiple thermocouple sensors measurement |
| mahphalke |
5:90166c496b01 | 1231 | * @param measurement_type[in]- Temperature measurement and display type |
| mahphalke |
0:08ba94bc5a30 | 1232 | * @return MENU_CONTINUE |
| mahphalke |
0:08ba94bc5a30 | 1233 | */ |
| mahphalke |
5:90166c496b01 | 1234 | int32_t perform_thermocouple_measurement(uint32_t measurement_type) |
| mahphalke |
0:08ba94bc5a30 | 1235 | { |
| mahphalke |
0:08ba94bc5a30 | 1236 | bool adc_error = false; |
| mahphalke |
5:90166c496b01 | 1237 | uint8_t setup; |
| mahphalke |
5:90166c496b01 | 1238 | uint16_t sample_cnt; |
| mahphalke |
5:90166c496b01 | 1239 | bool continue_measurement = false; |
| mahphalke |
5:90166c496b01 | 1240 | float tc_temperature; |
| mahphalke |
5:90166c496b01 | 1241 | float cjc_temperature; |
| mahphalke |
0:08ba94bc5a30 | 1242 | |
| mahphalke |
0:08ba94bc5a30 | 1243 | #if defined(AD7124_8) |
| mahphalke |
0:08ba94bc5a30 | 1244 | const int32_t tc_vbias_input[] = { |
| mahphalke |
0:08ba94bc5a30 | 1245 | AD7124_8_IO_CTRL2_REG_GPIO_VBIAS2, AD7124_8_IO_CTRL2_REG_GPIO_VBIAS6, |
| mahphalke |
0:08ba94bc5a30 | 1246 | AD7124_8_IO_CTRL2_REG_GPIO_VBIAS8, AD7124_8_IO_CTRL2_REG_GPIO_VBIAS10, |
| mahphalke |
0:08ba94bc5a30 | 1247 | AD7124_8_IO_CTRL2_REG_GPIO_VBIAS12, AD7124_8_IO_CTRL2_REG_GPIO_VBIAS14 |
| mahphalke |
0:08ba94bc5a30 | 1248 | }; |
| mahphalke |
0:08ba94bc5a30 | 1249 | #else |
| mahphalke |
0:08ba94bc5a30 | 1250 | const int32_t tc_vbias_input[] = { |
| mahphalke |
0:08ba94bc5a30 | 1251 | AD7124_IO_CTRL2_REG_GPIO_VBIAS2, AD7124_IO_CTRL2_REG_GPIO_VBIAS6 |
| mahphalke |
0:08ba94bc5a30 | 1252 | }; |
| mahphalke |
0:08ba94bc5a30 | 1253 | #endif |
| mahphalke |
0:08ba94bc5a30 | 1254 | |
| mahphalke |
5:90166c496b01 | 1255 | if (measurement_type == CONTINUOUS_MEASUREMENT) { |
| mahphalke |
5:90166c496b01 | 1256 | printf(EOL"Press ESC key once to stop measurement..." EOL); |
| mahphalke |
5:90166c496b01 | 1257 | mdelay(1000); |
| mahphalke |
5:90166c496b01 | 1258 | continue_measurement = true; |
| mahphalke |
5:90166c496b01 | 1259 | } |
| mahphalke |
0:08ba94bc5a30 | 1260 | |
| mahphalke |
5:90166c496b01 | 1261 | /* Print display header */ |
| mahphalke |
5:90166c496b01 | 1262 | printf(EOL EOL EOL); |
| mahphalke |
5:90166c496b01 | 1263 | for (uint8_t chn = SENSOR_CHANNEL0; |
| mahphalke |
5:90166c496b01 | 1264 | chn < max_supported_sensors[AD7124_CONFIG_THERMOCOUPLE]; chn++) { |
| mahphalke |
0:08ba94bc5a30 | 1265 | if (sensor_enable_status[chn]) { |
| mahphalke |
6:622270f7d476 | 1266 | sprintf(decimal_eqv_str, "TC%d CJC ", chn+1); |
| mahphalke |
6:622270f7d476 | 1267 | strcat(decimal_eqv_str_arr, decimal_eqv_str); |
| mahphalke |
5:90166c496b01 | 1268 | } |
| mahphalke |
5:90166c496b01 | 1269 | } |
| mahphalke |
6:622270f7d476 | 1270 | printf("\t%s" EOL EOL, decimal_eqv_str_arr); |
| mahphalke |
6:622270f7d476 | 1271 | decimal_eqv_str_arr[0] = '\0'; |
| mahphalke |
5:90166c496b01 | 1272 | printf("\t----------------------------------------------------------------------------------------------" |
| mahphalke |
5:90166c496b01 | 1273 | EOL EOL); |
| mahphalke |
0:08ba94bc5a30 | 1274 | |
| mahphalke |
5:90166c496b01 | 1275 | do { |
| mahphalke |
5:90166c496b01 | 1276 | /* Sample and Read all enabled TC channels in sequence */ |
| mahphalke |
5:90166c496b01 | 1277 | for (uint8_t chn = SENSOR_CHANNEL0; |
| mahphalke |
5:90166c496b01 | 1278 | chn < max_supported_sensors[AD7124_CONFIG_THERMOCOUPLE]; |
| mahphalke |
5:90166c496b01 | 1279 | chn++) { |
| mahphalke |
5:90166c496b01 | 1280 | if (sensor_enable_status[chn]) { |
| mahphalke |
5:90166c496b01 | 1281 | /* Turn on the bias voltage for current thermocouple input (AINP) */ |
| mahphalke |
5:90166c496b01 | 1282 | ad7124_register_map[AD7124_IOCon2].value |= tc_vbias_input[chn]; |
| mahphalke |
5:90166c496b01 | 1283 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
5:90166c496b01 | 1284 | ad7124_register_map[AD7124_IOCon2]) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 1285 | adc_error = true; |
| mahphalke |
5:90166c496b01 | 1286 | break; |
| mahphalke |
5:90166c496b01 | 1287 | } |
| mahphalke |
0:08ba94bc5a30 | 1288 | |
| mahphalke |
5:90166c496b01 | 1289 | if (perform_adc_conversion(chn, &n_sample_data[chn], |
| mahphalke |
5:90166c496b01 | 1290 | measurement_type) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 1291 | adc_error = true; |
| mahphalke |
5:90166c496b01 | 1292 | break; |
| mahphalke |
5:90166c496b01 | 1293 | } |
| mahphalke |
0:08ba94bc5a30 | 1294 | |
| mahphalke |
5:90166c496b01 | 1295 | /* Turn off the bias voltage for all analog inputs */ |
| mahphalke |
5:90166c496b01 | 1296 | ad7124_register_map[AD7124_IOCon2].value = 0x0; |
| mahphalke |
5:90166c496b01 | 1297 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
5:90166c496b01 | 1298 | ad7124_register_map[AD7124_IOCon2]) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 1299 | adc_error = true; |
| mahphalke |
5:90166c496b01 | 1300 | break; |
| mahphalke |
5:90166c496b01 | 1301 | } |
| mahphalke |
5:90166c496b01 | 1302 | |
| mahphalke |
5:90166c496b01 | 1303 | /* Perform measurement for the cold junction compensation sensor */ |
| mahphalke |
5:90166c496b01 | 1304 | if (perform_cjc_measurement(&n_cjc_sample_data[chn], |
| mahphalke |
5:90166c496b01 | 1305 | measurement_type) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 1306 | adc_error = true; |
| mahphalke |
5:90166c496b01 | 1307 | break; |
| mahphalke |
5:90166c496b01 | 1308 | } |
| mahphalke |
5:90166c496b01 | 1309 | |
| mahphalke |
5:90166c496b01 | 1310 | setup = ad7124_get_channel_setup(p_ad7124_dev, chn); |
| mahphalke |
5:90166c496b01 | 1311 | |
| mahphalke |
5:90166c496b01 | 1312 | /* Change gain back to thermocouple sensor gain */ |
| mahphalke |
5:90166c496b01 | 1313 | ad7124_register_map[AD7124_Config_0 + setup].value &= (~AD7124_CFG_REG_PGA_MSK); |
| mahphalke |
5:90166c496b01 | 1314 | ad7124_register_map[AD7124_Config_0 + setup].value |= AD7124_CFG_REG_PGA( |
| mahphalke |
5:90166c496b01 | 1315 | THERMOCOUPLE_GAIN_VALUE); |
| mahphalke |
5:90166c496b01 | 1316 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
5:90166c496b01 | 1317 | ad7124_register_map[AD7124_Config_0 + setup]) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 1318 | adc_error = true; |
| mahphalke |
5:90166c496b01 | 1319 | break; |
| mahphalke |
5:90166c496b01 | 1320 | } |
| mahphalke |
0:08ba94bc5a30 | 1321 | } |
| mahphalke |
0:08ba94bc5a30 | 1322 | } |
| mahphalke |
0:08ba94bc5a30 | 1323 | |
| mahphalke |
5:90166c496b01 | 1324 | if (adc_error) { |
| mahphalke |
5:90166c496b01 | 1325 | printf(EOL EOL "\tError Performing Measurement" EOL); |
| mahphalke |
0:08ba94bc5a30 | 1326 | break; |
| mahphalke |
5:90166c496b01 | 1327 | } else { |
| mahphalke |
5:90166c496b01 | 1328 | /* Calculate temperature and display result */ |
| mahphalke |
5:90166c496b01 | 1329 | if (measurement_type == AVERAGED_MEASUREMENT) { |
| mahphalke |
5:90166c496b01 | 1330 | for (uint8_t chn = SENSOR_CHANNEL0; |
| mahphalke |
5:90166c496b01 | 1331 | chn < max_supported_sensors[AD7124_CONFIG_THERMOCOUPLE]; |
| mahphalke |
5:90166c496b01 | 1332 | chn++) { |
| mahphalke |
5:90166c496b01 | 1333 | if (sensor_enable_status[chn]) { |
| mahphalke |
5:90166c496b01 | 1334 | tc_temperature = get_tc_temperature(n_sample_data[chn][0], |
| mahphalke |
5:90166c496b01 | 1335 | n_cjc_sample_data[chn][0], current_cjc_sensor, |
| mahphalke |
5:90166c496b01 | 1336 | &cjc_temperature); |
| mahphalke |
6:622270f7d476 | 1337 | sprintf(decimal_eqv_str, "%.4f %.4f ", tc_temperature, cjc_temperature); |
| mahphalke |
6:622270f7d476 | 1338 | strcat(decimal_eqv_str_arr, decimal_eqv_str); |
| mahphalke |
5:90166c496b01 | 1339 | } |
| mahphalke |
5:90166c496b01 | 1340 | } |
| mahphalke |
6:622270f7d476 | 1341 | printf("\t%s" EOL EOL, decimal_eqv_str_arr); |
| mahphalke |
6:622270f7d476 | 1342 | decimal_eqv_str_arr[0] = '\0'; |
| mahphalke |
5:90166c496b01 | 1343 | } else { |
| mahphalke |
5:90166c496b01 | 1344 | for (sample_cnt = 0; sample_cnt < MAX_ADC_SAMPLES; sample_cnt++) { |
| mahphalke |
5:90166c496b01 | 1345 | for (uint8_t chn = SENSOR_CHANNEL0; |
| mahphalke |
5:90166c496b01 | 1346 | chn < max_supported_sensors[AD7124_CONFIG_THERMOCOUPLE]; |
| mahphalke |
5:90166c496b01 | 1347 | chn++) { |
| mahphalke |
5:90166c496b01 | 1348 | if (sensor_enable_status[chn]) { |
| mahphalke |
5:90166c496b01 | 1349 | tc_temperature = get_tc_temperature(n_sample_data[chn][sample_cnt], |
| mahphalke |
5:90166c496b01 | 1350 | n_cjc_sample_data[chn][sample_cnt], current_cjc_sensor, |
| mahphalke |
5:90166c496b01 | 1351 | &cjc_temperature); |
| mahphalke |
6:622270f7d476 | 1352 | sprintf(decimal_eqv_str, "%.4f %.4f ", tc_temperature, cjc_temperature); |
| mahphalke |
6:622270f7d476 | 1353 | strcat(decimal_eqv_str_arr, decimal_eqv_str); |
| mahphalke |
5:90166c496b01 | 1354 | } |
| mahphalke |
5:90166c496b01 | 1355 | } |
| mahphalke |
6:622270f7d476 | 1356 | printf("\t%s" EOL EOL, decimal_eqv_str_arr); |
| mahphalke |
6:622270f7d476 | 1357 | decimal_eqv_str_arr[0] = '\0'; |
| mahphalke |
5:90166c496b01 | 1358 | } |
| mahphalke |
0:08ba94bc5a30 | 1359 | } |
| mahphalke |
0:08ba94bc5a30 | 1360 | } |
| mahphalke |
5:90166c496b01 | 1361 | } while (continue_measurement && !was_escape_key_pressed()); |
| mahphalke |
0:08ba94bc5a30 | 1362 | |
| mahphalke |
0:08ba94bc5a30 | 1363 | /* Put ADC into standby mode */ |
| mahphalke |
0:08ba94bc5a30 | 1364 | ad7124_register_map[AD7124_ADC_Control].value &= (~AD7124_ADC_CTRL_REG_MSK); |
| mahphalke |
0:08ba94bc5a30 | 1365 | ad7124_register_map[AD7124_ADC_Control].value |= AD7124_ADC_CTRL_REG_MODE( |
| mahphalke |
0:08ba94bc5a30 | 1366 | STANDBY_MODE); |
| mahphalke |
0:08ba94bc5a30 | 1367 | ad7124_write_register(p_ad7124_dev, ad7124_register_map[AD7124_ADC_Control]); |
| mahphalke |
0:08ba94bc5a30 | 1368 | |
| mahphalke |
0:08ba94bc5a30 | 1369 | adi_press_any_key_to_continue(); |
| mahphalke |
0:08ba94bc5a30 | 1370 | return MENU_CONTINUE; |
| mahphalke |
0:08ba94bc5a30 | 1371 | } |
| mahphalke |
0:08ba94bc5a30 | 1372 | |
| mahphalke |
0:08ba94bc5a30 | 1373 | |
| mahphalke |
0:08ba94bc5a30 | 1374 | /*! |
| mahphalke |
0:08ba94bc5a30 | 1375 | * @brief Perform the ADC calibration device configuration |
| mahphalke |
0:08ba94bc5a30 | 1376 | * @return adc_error_status |
| mahphalke |
0:08ba94bc5a30 | 1377 | */ |
| mahphalke |
0:08ba94bc5a30 | 1378 | static bool do_adc_calibration_configs(void) |
| mahphalke |
0:08ba94bc5a30 | 1379 | { |
| mahphalke |
0:08ba94bc5a30 | 1380 | bool adc_error_status = false; |
| mahphalke |
0:08ba94bc5a30 | 1381 | |
| mahphalke |
0:08ba94bc5a30 | 1382 | do { |
| mahphalke |
0:08ba94bc5a30 | 1383 | /* Put ADC into standby mode */ |
| mahphalke |
0:08ba94bc5a30 | 1384 | ad7124_register_map[AD7124_ADC_Control].value &= (~AD7124_ADC_CTRL_REG_MSK); |
| mahphalke |
0:08ba94bc5a30 | 1385 | ad7124_register_map[AD7124_ADC_Control].value |= AD7124_ADC_CTRL_REG_MODE( |
| mahphalke |
0:08ba94bc5a30 | 1386 | STANDBY_MODE); |
| mahphalke |
0:08ba94bc5a30 | 1387 | |
| mahphalke |
0:08ba94bc5a30 | 1388 | /* Enable internal Vref */ |
| mahphalke |
0:08ba94bc5a30 | 1389 | ad7124_register_map[AD7124_ADC_Control].value |= AD7124_ADC_CTRL_REG_REF_EN; |
| mahphalke |
0:08ba94bc5a30 | 1390 | |
| mahphalke |
0:08ba94bc5a30 | 1391 | /* Select low power ADC mode */ |
| mahphalke |
0:08ba94bc5a30 | 1392 | ad7124_register_map[AD7124_ADC_Control].value &= |
| mahphalke |
0:08ba94bc5a30 | 1393 | (~AD7124_ADC_CTRL_REG_POWER_MODE_MSK); |
| mahphalke |
0:08ba94bc5a30 | 1394 | ad7124_register_map[AD7124_ADC_Control].value |= AD7124_ADC_CTRL_REG_POWER_MODE( |
| mahphalke |
0:08ba94bc5a30 | 1395 | ADC_CALIBRATION_PWR_MODE); |
| mahphalke |
0:08ba94bc5a30 | 1396 | |
| mahphalke |
0:08ba94bc5a30 | 1397 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
0:08ba94bc5a30 | 1398 | ad7124_register_map[AD7124_ADC_Control]) != SUCCESS) { |
| mahphalke |
0:08ba94bc5a30 | 1399 | adc_error_status = true; |
| mahphalke |
0:08ba94bc5a30 | 1400 | break; |
| mahphalke |
0:08ba94bc5a30 | 1401 | } |
| mahphalke |
0:08ba94bc5a30 | 1402 | |
| mahphalke |
0:08ba94bc5a30 | 1403 | for (uint8_t cfg = 0; cfg < AD7124_MAX_CONFIGS_USED; cfg++) { |
| mahphalke |
0:08ba94bc5a30 | 1404 | /* Change ADC gain */ |
| mahphalke |
0:08ba94bc5a30 | 1405 | ad7124_register_map[AD7124_Config_0 + cfg].value &= (~AD7124_CFG_REG_PGA_MSK); |
| mahphalke |
0:08ba94bc5a30 | 1406 | ad7124_register_map[AD7124_Config_0 + cfg].value |= AD7124_CFG_REG_PGA( |
| mahphalke |
0:08ba94bc5a30 | 1407 | ADC_CALIBRATION_GAIN); |
| mahphalke |
0:08ba94bc5a30 | 1408 | |
| mahphalke |
0:08ba94bc5a30 | 1409 | /* Enable internal Vref source */ |
| mahphalke |
0:08ba94bc5a30 | 1410 | ad7124_register_map[AD7124_Config_0 + cfg].value &= |
| mahphalke |
0:08ba94bc5a30 | 1411 | (~AD7124_CFG_REG_REF_SEL_MSK); |
| mahphalke |
0:08ba94bc5a30 | 1412 | ad7124_register_map[AD7124_Config_0 + cfg].value |= AD7124_CFG_REG_REF_SEL( |
| mahphalke |
0:08ba94bc5a30 | 1413 | ADC_CALIBRATION_REF_SRC); |
| mahphalke |
0:08ba94bc5a30 | 1414 | |
| mahphalke |
0:08ba94bc5a30 | 1415 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
0:08ba94bc5a30 | 1416 | ad7124_register_map[AD7124_Config_0 + cfg]) != SUCCESS) { |
| mahphalke |
0:08ba94bc5a30 | 1417 | adc_error_status = true; |
| mahphalke |
0:08ba94bc5a30 | 1418 | break; |
| mahphalke |
0:08ba94bc5a30 | 1419 | } |
| mahphalke |
0:08ba94bc5a30 | 1420 | } |
| mahphalke |
0:08ba94bc5a30 | 1421 | } while (0); |
| mahphalke |
0:08ba94bc5a30 | 1422 | |
| mahphalke |
0:08ba94bc5a30 | 1423 | return adc_error_status; |
| mahphalke |
0:08ba94bc5a30 | 1424 | } |
| mahphalke |
0:08ba94bc5a30 | 1425 | |
| mahphalke |
0:08ba94bc5a30 | 1426 | |
| mahphalke |
0:08ba94bc5a30 | 1427 | /*! |
| mahphalke |
0:08ba94bc5a30 | 1428 | * @brief Perform the ADC calibration on selected channel |
| mahphalke |
0:08ba94bc5a30 | 1429 | * @param calibration_mode[in] - ADC calibration mode |
| mahphalke |
0:08ba94bc5a30 | 1430 | * @param chn[in] - ADC channel to be calibrated |
| mahphalke |
0:08ba94bc5a30 | 1431 | * @param setup[in] - Setup mapped to selected ADC channel |
| mahphalke |
0:08ba94bc5a30 | 1432 | * @param pos_analog_input[in] - Positive analog input mapped to selected ADC channel |
| mahphalke |
0:08ba94bc5a30 | 1433 | * @param neg_analog_input[in] - Negative analog input mapped to selected ADC channel |
| mahphalke |
0:08ba94bc5a30 | 1434 | * @return adc_error_status |
| mahphalke |
0:08ba94bc5a30 | 1435 | */ |
| mahphalke |
0:08ba94bc5a30 | 1436 | static bool do_adc_calibration(uint32_t calibration_mode, uint8_t chn, |
| mahphalke |
0:08ba94bc5a30 | 1437 | uint8_t setup, |
| mahphalke |
0:08ba94bc5a30 | 1438 | uint8_t pos_analog_input, uint8_t neg_analog_input) |
| mahphalke |
0:08ba94bc5a30 | 1439 | { |
| mahphalke |
0:08ba94bc5a30 | 1440 | bool adc_error_status = false; |
| mahphalke |
0:08ba94bc5a30 | 1441 | |
| mahphalke |
0:08ba94bc5a30 | 1442 | do { |
| mahphalke |
0:08ba94bc5a30 | 1443 | if ((calibration_mode == INTERNAL_FULL_SCALE_CALIBRATE_MODE) |
| mahphalke |
0:08ba94bc5a30 | 1444 | || (calibration_mode == INTERNAL_ZERO_SCALE_CALIBRATE_MODE)) { |
| mahphalke |
0:08ba94bc5a30 | 1445 | if (calibration_mode == INTERNAL_FULL_SCALE_CALIBRATE_MODE) { |
| mahphalke |
0:08ba94bc5a30 | 1446 | printf("\tRunning full-scale internal calibration..." EOL); |
| mahphalke |
0:08ba94bc5a30 | 1447 | |
| mahphalke |
0:08ba94bc5a30 | 1448 | /* Write default offset register value before starting full-scale internal calibration */ |
| mahphalke |
0:08ba94bc5a30 | 1449 | ad7124_register_map[AD7124_Offset_0 + setup].value = |
| mahphalke |
0:08ba94bc5a30 | 1450 | AD7124_DEFAULT_OFFSET; |
| mahphalke |
0:08ba94bc5a30 | 1451 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
0:08ba94bc5a30 | 1452 | ad7124_register_map[AD7124_Offset_0 + setup]) != SUCCESS) { |
| mahphalke |
0:08ba94bc5a30 | 1453 | adc_error_status = true; |
| mahphalke |
0:08ba94bc5a30 | 1454 | break; |
| mahphalke |
0:08ba94bc5a30 | 1455 | } |
| mahphalke |
0:08ba94bc5a30 | 1456 | } else { |
| mahphalke |
0:08ba94bc5a30 | 1457 | printf("\tRunning zero-scale internal calibration..." EOL); |
| mahphalke |
0:08ba94bc5a30 | 1458 | } |
| mahphalke |
0:08ba94bc5a30 | 1459 | |
| mahphalke |
0:08ba94bc5a30 | 1460 | ad7124_register_map[AD7124_ADC_Control].value = |
| mahphalke |
0:08ba94bc5a30 | 1461 | ((ad7124_register_map[AD7124_ADC_Control].value & ~AD7124_ADC_CTRL_REG_MSK) | \ |
| mahphalke |
0:08ba94bc5a30 | 1462 | AD7124_ADC_CTRL_REG_MODE(calibration_mode)); |
| mahphalke |
0:08ba94bc5a30 | 1463 | } else { |
| mahphalke |
0:08ba94bc5a30 | 1464 | if (calibration_mode == SYSTEM_FULL_SCALE_CALIBRATE_MODE) { |
| mahphalke |
0:08ba94bc5a30 | 1465 | printf(EOL |
| mahphalke |
0:08ba94bc5a30 | 1466 | "\tApply full-scale voltage between AINP%d and AINM%d and press any key..." |
| mahphalke |
0:08ba94bc5a30 | 1467 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1468 | pos_analog_input, |
| mahphalke |
0:08ba94bc5a30 | 1469 | neg_analog_input); |
| mahphalke |
0:08ba94bc5a30 | 1470 | } else { |
| mahphalke |
0:08ba94bc5a30 | 1471 | printf(EOL |
| mahphalke |
0:08ba94bc5a30 | 1472 | "\tApply zero-scale voltage between AINP%d and AINM%d and press any key..." |
| mahphalke |
0:08ba94bc5a30 | 1473 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1474 | pos_analog_input, |
| mahphalke |
0:08ba94bc5a30 | 1475 | neg_analog_input); |
| mahphalke |
0:08ba94bc5a30 | 1476 | } |
| mahphalke |
0:08ba94bc5a30 | 1477 | |
| mahphalke |
0:08ba94bc5a30 | 1478 | /* Wait for user input */ |
| mahphalke |
0:08ba94bc5a30 | 1479 | getchar(); |
| mahphalke |
0:08ba94bc5a30 | 1480 | |
| mahphalke |
0:08ba94bc5a30 | 1481 | ad7124_register_map[AD7124_ADC_Control].value = |
| mahphalke |
0:08ba94bc5a30 | 1482 | ((ad7124_register_map[AD7124_ADC_Control].value & ~AD7124_ADC_CTRL_REG_MSK) | \ |
| mahphalke |
0:08ba94bc5a30 | 1483 | AD7124_ADC_CTRL_REG_MODE(calibration_mode)); |
| mahphalke |
0:08ba94bc5a30 | 1484 | } |
| mahphalke |
0:08ba94bc5a30 | 1485 | |
| mahphalke |
0:08ba94bc5a30 | 1486 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
0:08ba94bc5a30 | 1487 | ad7124_register_map[AD7124_ADC_Control]) != SUCCESS) { |
| mahphalke |
0:08ba94bc5a30 | 1488 | adc_error_status = true; |
| mahphalke |
0:08ba94bc5a30 | 1489 | break; |
| mahphalke |
0:08ba94bc5a30 | 1490 | } |
| mahphalke |
0:08ba94bc5a30 | 1491 | |
| mahphalke |
0:08ba94bc5a30 | 1492 | /* Wait for calibration (conversion) to finish */ |
| mahphalke |
0:08ba94bc5a30 | 1493 | if (ad7124_wait_for_conv_ready(p_ad7124_dev, |
| mahphalke |
0:08ba94bc5a30 | 1494 | p_ad7124_dev->spi_rdy_poll_cnt) != SUCCESS) { |
| mahphalke |
0:08ba94bc5a30 | 1495 | adc_error_status = true; |
| mahphalke |
0:08ba94bc5a30 | 1496 | break; |
| mahphalke |
0:08ba94bc5a30 | 1497 | } |
| mahphalke |
0:08ba94bc5a30 | 1498 | } while (0); |
| mahphalke |
0:08ba94bc5a30 | 1499 | |
| mahphalke |
0:08ba94bc5a30 | 1500 | return adc_error_status; |
| mahphalke |
0:08ba94bc5a30 | 1501 | } |
| mahphalke |
0:08ba94bc5a30 | 1502 | |
| mahphalke |
0:08ba94bc5a30 | 1503 | |
| mahphalke |
0:08ba94bc5a30 | 1504 | /*! |
| mahphalke |
0:08ba94bc5a30 | 1505 | * @brief Perform the AD7124 internal/system calibration |
| mahphalke |
0:08ba94bc5a30 | 1506 | * @param calibration_type[in]- ADC calibration type (internal/system) |
| mahphalke |
0:08ba94bc5a30 | 1507 | * @return MENU_CONTINUE |
| mahphalke |
0:08ba94bc5a30 | 1508 | * @note This function performs both 'Internal/System Full-Scale' and |
| mahphalke |
0:08ba94bc5a30 | 1509 | * 'Internal/System Zero-Scale' calibration on all enabled ADC channels |
| mahphalke |
0:08ba94bc5a30 | 1510 | * sequentially. |
| mahphalke |
0:08ba94bc5a30 | 1511 | */ |
| mahphalke |
0:08ba94bc5a30 | 1512 | int32_t perform_adc_calibration(uint32_t calibration_type) |
| mahphalke |
0:08ba94bc5a30 | 1513 | { |
| mahphalke |
0:08ba94bc5a30 | 1514 | bool cal_error = false; |
| mahphalke |
0:08ba94bc5a30 | 1515 | bool adc_error = false; |
| mahphalke |
0:08ba94bc5a30 | 1516 | uint8_t chn_cnt; |
| mahphalke |
0:08ba94bc5a30 | 1517 | uint8_t pos_analog_input, neg_analog_input; |
| mahphalke |
0:08ba94bc5a30 | 1518 | uint8_t setup; |
| mahphalke |
0:08ba94bc5a30 | 1519 | |
| mahphalke |
0:08ba94bc5a30 | 1520 | current_sensor_config = sensor_configs[AD7124_CONFIG_ADC_CALIBRATION]; |
| mahphalke |
0:08ba94bc5a30 | 1521 | |
| mahphalke |
0:08ba94bc5a30 | 1522 | /* Load ADC configurations and perform the calibration */ |
| mahphalke |
0:08ba94bc5a30 | 1523 | if (!do_adc_calibration_configs()) { |
| mahphalke |
0:08ba94bc5a30 | 1524 | /* Calibrate all the user enabled ADC channels sequentially */ |
| mahphalke |
0:08ba94bc5a30 | 1525 | for (chn_cnt = 0; chn_cnt < NUM_OF_SENSOR_CHANNELS; chn_cnt++) { |
| mahphalke |
0:08ba94bc5a30 | 1526 | if (sensor_enable_status[chn_cnt]) { |
| mahphalke |
0:08ba94bc5a30 | 1527 | /* Read the channel map register */ |
| mahphalke |
0:08ba94bc5a30 | 1528 | if (ad7124_read_register(p_ad7124_dev, |
| mahphalke |
0:08ba94bc5a30 | 1529 | &ad7124_register_map[AD7124_Channel_0 + chn_cnt]) != SUCCESS) { |
| mahphalke |
0:08ba94bc5a30 | 1530 | adc_error = true; |
| mahphalke |
0:08ba94bc5a30 | 1531 | break; |
| mahphalke |
0:08ba94bc5a30 | 1532 | } |
| mahphalke |
0:08ba94bc5a30 | 1533 | |
| mahphalke |
0:08ba94bc5a30 | 1534 | /* Get the analog inputs mapped to corresponding channel */ |
| mahphalke |
0:08ba94bc5a30 | 1535 | pos_analog_input = AD7124_CH_MAP_REG_AINP_RD( |
| mahphalke |
0:08ba94bc5a30 | 1536 | ad7124_register_map[AD7124_Channel_0 + chn_cnt].value); |
| mahphalke |
0:08ba94bc5a30 | 1537 | neg_analog_input = AD7124_CH_MAP_REG_AINM_RD( |
| mahphalke |
0:08ba94bc5a30 | 1538 | ad7124_register_map[AD7124_Channel_0 + chn_cnt].value); |
| mahphalke |
0:08ba94bc5a30 | 1539 | |
| mahphalke |
0:08ba94bc5a30 | 1540 | /* Make sure analog input number mapped to channel is correct */ |
| mahphalke |
0:08ba94bc5a30 | 1541 | if (pos_analog_input > AD7124_MAX_INPUTS |
| mahphalke |
0:08ba94bc5a30 | 1542 | || neg_analog_input > AD7124_MAX_INPUTS) { |
| mahphalke |
0:08ba94bc5a30 | 1543 | continue; |
| mahphalke |
0:08ba94bc5a30 | 1544 | } |
| mahphalke |
0:08ba94bc5a30 | 1545 | |
| mahphalke |
0:08ba94bc5a30 | 1546 | /* Get setup/configuration mapped to corresponding channel */ |
| mahphalke |
0:08ba94bc5a30 | 1547 | setup = AD7124_CH_MAP_REG_SETUP_RD( |
| mahphalke |
0:08ba94bc5a30 | 1548 | ad7124_register_map[AD7124_Channel_0 + chn_cnt].value); |
| mahphalke |
0:08ba94bc5a30 | 1549 | |
| mahphalke |
0:08ba94bc5a30 | 1550 | printf(EOL "Calibrating Channel %d => " EOL, chn_cnt); |
| mahphalke |
0:08ba94bc5a30 | 1551 | |
| mahphalke |
0:08ba94bc5a30 | 1552 | /* Enable channel for calibration */ |
| mahphalke |
0:08ba94bc5a30 | 1553 | ad7124_register_map[AD7124_Channel_0 + chn_cnt].value |= |
| mahphalke |
0:08ba94bc5a30 | 1554 | AD7124_CH_MAP_REG_CH_ENABLE; |
| mahphalke |
0:08ba94bc5a30 | 1555 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
0:08ba94bc5a30 | 1556 | ad7124_register_map[AD7124_Channel_0 + chn_cnt]) != SUCCESS) { |
| mahphalke |
0:08ba94bc5a30 | 1557 | adc_error = true; |
| mahphalke |
0:08ba94bc5a30 | 1558 | break; |
| mahphalke |
0:08ba94bc5a30 | 1559 | } |
| mahphalke |
0:08ba94bc5a30 | 1560 | |
| mahphalke |
0:08ba94bc5a30 | 1561 | if (calibration_type == INTERNAL_CALIBRATION) { |
| mahphalke |
0:08ba94bc5a30 | 1562 | /* Perform the full-scale internal calibration */ |
| mahphalke |
0:08ba94bc5a30 | 1563 | do_adc_calibration(INTERNAL_FULL_SCALE_CALIBRATE_MODE, |
| mahphalke |
0:08ba94bc5a30 | 1564 | chn_cnt, setup, |
| mahphalke |
0:08ba94bc5a30 | 1565 | pos_analog_input, neg_analog_input); |
| mahphalke |
0:08ba94bc5a30 | 1566 | |
| mahphalke |
0:08ba94bc5a30 | 1567 | /* Perform the zero-scale internal calibration */ |
| mahphalke |
0:08ba94bc5a30 | 1568 | do_adc_calibration(INTERNAL_ZERO_SCALE_CALIBRATE_MODE, |
| mahphalke |
0:08ba94bc5a30 | 1569 | chn_cnt, setup, |
| mahphalke |
0:08ba94bc5a30 | 1570 | pos_analog_input, neg_analog_input); |
| mahphalke |
0:08ba94bc5a30 | 1571 | } else { |
| mahphalke |
0:08ba94bc5a30 | 1572 | /* Perform the full-scale system calibration */ |
| mahphalke |
0:08ba94bc5a30 | 1573 | do_adc_calibration(SYSTEM_FULL_SCALE_CALIBRATE_MODE, |
| mahphalke |
0:08ba94bc5a30 | 1574 | chn_cnt, setup, |
| mahphalke |
0:08ba94bc5a30 | 1575 | pos_analog_input, neg_analog_input); |
| mahphalke |
0:08ba94bc5a30 | 1576 | |
| mahphalke |
0:08ba94bc5a30 | 1577 | /* Perform the zero-scale system calibration */ |
| mahphalke |
0:08ba94bc5a30 | 1578 | do_adc_calibration(SYSTEM_ZERO_SCALE_CALIBRATE_MODE, |
| mahphalke |
0:08ba94bc5a30 | 1579 | chn_cnt, setup, |
| mahphalke |
0:08ba94bc5a30 | 1580 | pos_analog_input, neg_analog_input); |
| mahphalke |
0:08ba94bc5a30 | 1581 | } |
| mahphalke |
0:08ba94bc5a30 | 1582 | |
| mahphalke |
0:08ba94bc5a30 | 1583 | /* Read the calibration error status */ |
| mahphalke |
0:08ba94bc5a30 | 1584 | if (ad7124_read_register(p_ad7124_dev, |
| mahphalke |
0:08ba94bc5a30 | 1585 | &ad7124_register_map[AD7124_Error]) != SUCCESS) { |
| mahphalke |
0:08ba94bc5a30 | 1586 | adc_error = true; |
| mahphalke |
0:08ba94bc5a30 | 1587 | break; |
| mahphalke |
0:08ba94bc5a30 | 1588 | } else { |
| mahphalke |
0:08ba94bc5a30 | 1589 | cal_error = AD7124_ERR_REG_ADC_CAL_ERR_RD( |
| mahphalke |
0:08ba94bc5a30 | 1590 | ad7124_register_map[AD7124_Error].value); |
| mahphalke |
0:08ba94bc5a30 | 1591 | |
| mahphalke |
0:08ba94bc5a30 | 1592 | if (!cal_error) { |
| mahphalke |
0:08ba94bc5a30 | 1593 | printf(EOL "\tCalibration done..." EOL); |
| mahphalke |
0:08ba94bc5a30 | 1594 | } else { |
| mahphalke |
0:08ba94bc5a30 | 1595 | printf(EOL "\tError in calibration!!" EOL); |
| mahphalke |
0:08ba94bc5a30 | 1596 | } |
| mahphalke |
0:08ba94bc5a30 | 1597 | |
| mahphalke |
0:08ba94bc5a30 | 1598 | /* Get and print the Offset and Gain coefficient values (setup 0) */ |
| mahphalke |
0:08ba94bc5a30 | 1599 | ad7124_read_register(p_ad7124_dev, |
| mahphalke |
0:08ba94bc5a30 | 1600 | &ad7124_register_map[AD7124_Offset_0 + setup]); |
| mahphalke |
0:08ba94bc5a30 | 1601 | ad7124_read_register(p_ad7124_dev, |
| mahphalke |
0:08ba94bc5a30 | 1602 | &ad7124_register_map[AD7124_Gain_0 + setup]); |
| mahphalke |
0:08ba94bc5a30 | 1603 | |
| mahphalke |
0:08ba94bc5a30 | 1604 | printf("\tOffset %d: 0x%lx" EOL, setup, |
| mahphalke |
0:08ba94bc5a30 | 1605 | ad7124_register_map[AD7124_Offset_0 + setup].value); |
| mahphalke |
0:08ba94bc5a30 | 1606 | printf("\tGain %d: 0x%lx" EOL EOL, setup, |
| mahphalke |
0:08ba94bc5a30 | 1607 | ad7124_register_map[AD7124_Gain_0 + setup].value); |
| mahphalke |
0:08ba94bc5a30 | 1608 | } |
| mahphalke |
0:08ba94bc5a30 | 1609 | |
| mahphalke |
0:08ba94bc5a30 | 1610 | /* Disable current channel */ |
| mahphalke |
0:08ba94bc5a30 | 1611 | ad7124_register_map[AD7124_Channel_0 + chn_cnt].value &= |
| mahphalke |
0:08ba94bc5a30 | 1612 | (~AD7124_CH_MAP_REG_CH_ENABLE); |
| mahphalke |
0:08ba94bc5a30 | 1613 | if (ad7124_write_register(p_ad7124_dev, |
| mahphalke |
0:08ba94bc5a30 | 1614 | ad7124_register_map[AD7124_Channel_0 + chn_cnt]) != SUCCESS) { |
| mahphalke |
0:08ba94bc5a30 | 1615 | adc_error = true; |
| mahphalke |
0:08ba94bc5a30 | 1616 | break; |
| mahphalke |
0:08ba94bc5a30 | 1617 | } |
| mahphalke |
0:08ba94bc5a30 | 1618 | } |
| mahphalke |
0:08ba94bc5a30 | 1619 | } |
| mahphalke |
0:08ba94bc5a30 | 1620 | } |
| mahphalke |
0:08ba94bc5a30 | 1621 | |
| mahphalke |
0:08ba94bc5a30 | 1622 | if (adc_error) { |
| mahphalke |
0:08ba94bc5a30 | 1623 | printf(EOL "\tError in calibration!!" EOL); |
| mahphalke |
0:08ba94bc5a30 | 1624 | } else { |
| mahphalke |
0:08ba94bc5a30 | 1625 | printf(EOL "\tCalibration successful..." EOL); |
| mahphalke |
0:08ba94bc5a30 | 1626 | } |
| mahphalke |
0:08ba94bc5a30 | 1627 | |
| mahphalke |
0:08ba94bc5a30 | 1628 | /* Disable calibration error monitoring */ |
| mahphalke |
0:08ba94bc5a30 | 1629 | ad7124_register_map[AD7124_Error_En].value &= |
| mahphalke |
0:08ba94bc5a30 | 1630 | (~AD7124_ERREN_REG_ADC_CAL_ERR_EN); |
| mahphalke |
0:08ba94bc5a30 | 1631 | ad7124_write_register(p_ad7124_dev, ad7124_register_map[AD7124_Error_En]); |
| mahphalke |
0:08ba94bc5a30 | 1632 | |
| mahphalke |
0:08ba94bc5a30 | 1633 | adi_press_any_key_to_continue(); |
| mahphalke |
0:08ba94bc5a30 | 1634 | adi_clear_console(); |
| mahphalke |
0:08ba94bc5a30 | 1635 | |
| mahphalke |
0:08ba94bc5a30 | 1636 | return MENU_CONTINUE; |
| mahphalke |
0:08ba94bc5a30 | 1637 | } |
| mahphalke |
0:08ba94bc5a30 | 1638 | |
| mahphalke |
0:08ba94bc5a30 | 1639 | |
| mahphalke |
0:08ba94bc5a30 | 1640 | /*! |
| mahphalke |
0:08ba94bc5a30 | 1641 | * @brief Display header information for 2-wire RTD measurement menu |
| mahphalke |
0:08ba94bc5a30 | 1642 | * @return none |
| mahphalke |
0:08ba94bc5a30 | 1643 | */ |
| mahphalke |
0:08ba94bc5a30 | 1644 | void rtd_2wire_menu_header(void) |
| mahphalke |
0:08ba94bc5a30 | 1645 | { |
| mahphalke |
0:08ba94bc5a30 | 1646 | if (strcmp(current_sensor_config, sensor_configs[AD7124_CONFIG_2WIRE_RTD])) { |
| mahphalke |
0:08ba94bc5a30 | 1647 | /* Disable unused sensor channels */ |
| mahphalke |
0:08ba94bc5a30 | 1648 | for (uint8_t chn = max_supported_sensors[AD7124_CONFIG_2WIRE_RTD]; |
| mahphalke |
0:08ba94bc5a30 | 1649 | chn < NUM_OF_SENSOR_CHANNELS; chn++) { |
| mahphalke |
0:08ba94bc5a30 | 1650 | sensor_enable_status[chn] = false; |
| mahphalke |
0:08ba94bc5a30 | 1651 | } |
| mahphalke |
0:08ba94bc5a30 | 1652 | |
| mahphalke |
0:08ba94bc5a30 | 1653 | /* Load the 2-wire RTD device configuration */ |
| mahphalke |
0:08ba94bc5a30 | 1654 | init_with_configuration(AD7124_CONFIG_2WIRE_RTD); |
| mahphalke |
0:08ba94bc5a30 | 1655 | } |
| mahphalke |
0:08ba94bc5a30 | 1656 | |
| mahphalke |
0:08ba94bc5a30 | 1657 | printf("\t Sensor Channel IOUT0 AIN+ AIN- Enable" EOL); |
| mahphalke |
0:08ba94bc5a30 | 1658 | printf("\t -----------------------------------------------" EOL); |
| mahphalke |
0:08ba94bc5a30 | 1659 | printf("\t RTD1 %d AIN%d AIN%d AIN%d %c" |
| mahphalke |
0:08ba94bc5a30 | 1660 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1661 | SENSOR_CHANNEL0, RTD1_2WIRE_IOUT0, RTD1_2WIRE_AINP, RTD1_2WIRE_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1662 | status_info[sensor_enable_status[SENSOR_CHANNEL0]]); |
| mahphalke |
0:08ba94bc5a30 | 1663 | printf("\t RTD2 %d AIN%d AIN%d AIN%d %c" |
| mahphalke |
0:08ba94bc5a30 | 1664 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1665 | SENSOR_CHANNEL1, RTD2_2WIRE_IOUT0, RTD2_2WIRE_AINP, RTD2_2WIRE_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1666 | status_info[sensor_enable_status[SENSOR_CHANNEL1]]); |
| mahphalke |
0:08ba94bc5a30 | 1667 | #if defined(AD7124_8) |
| mahphalke |
0:08ba94bc5a30 | 1668 | printf("\t RTD3 %d AIN%d AIN%d AIN%d %c" EOL, |
| mahphalke |
0:08ba94bc5a30 | 1669 | SENSOR_CHANNEL2, RTD3_2WIRE_IOUT0, RTD3_2WIRE_AINP, RTD3_2WIRE_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1670 | status_info[sensor_enable_status[SENSOR_CHANNEL2]]); |
| mahphalke |
0:08ba94bc5a30 | 1671 | printf("\t RTD4 %d AIN%d AIN%d AIN%d %c" EOL, |
| mahphalke |
0:08ba94bc5a30 | 1672 | SENSOR_CHANNEL3, RTD4_2WIRE_IOUT0, RTD4_2WIRE_AINP, RTD4_2WIRE_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1673 | status_info[sensor_enable_status[SENSOR_CHANNEL3]]); |
| mahphalke |
0:08ba94bc5a30 | 1674 | printf("\t RTD5 %d AIN%d AIN%d AIN%d %c" EOL, |
| mahphalke |
0:08ba94bc5a30 | 1675 | SENSOR_CHANNEL4, RTD5_2WIRE_IOUT0, RTD5_2WIRE_AINP, RTD5_2WIRE_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1676 | status_info[sensor_enable_status[SENSOR_CHANNEL4]]); |
| mahphalke |
0:08ba94bc5a30 | 1677 | #endif |
| mahphalke |
0:08ba94bc5a30 | 1678 | } |
| mahphalke |
0:08ba94bc5a30 | 1679 | |
| mahphalke |
0:08ba94bc5a30 | 1680 | |
| mahphalke |
0:08ba94bc5a30 | 1681 | /*! |
| mahphalke |
0:08ba94bc5a30 | 1682 | * @brief Display header information for 3-wire RTD measurement menu |
| mahphalke |
0:08ba94bc5a30 | 1683 | * @return none |
| mahphalke |
0:08ba94bc5a30 | 1684 | */ |
| mahphalke |
0:08ba94bc5a30 | 1685 | void rtd_3wire_menu_header(void) |
| mahphalke |
0:08ba94bc5a30 | 1686 | { |
| mahphalke |
0:08ba94bc5a30 | 1687 | if (strcmp(current_sensor_config, sensor_configs[AD7124_CONFIG_3WIRE_RTD])) { |
| mahphalke |
0:08ba94bc5a30 | 1688 | /* Disable unused sensor channels */ |
| mahphalke |
0:08ba94bc5a30 | 1689 | for (uint8_t chn = max_supported_sensors[AD7124_CONFIG_3WIRE_RTD]; |
| mahphalke |
0:08ba94bc5a30 | 1690 | chn < NUM_OF_SENSOR_CHANNELS; chn++) { |
| mahphalke |
0:08ba94bc5a30 | 1691 | sensor_enable_status[chn] = false; |
| mahphalke |
0:08ba94bc5a30 | 1692 | } |
| mahphalke |
0:08ba94bc5a30 | 1693 | |
| mahphalke |
0:08ba94bc5a30 | 1694 | /* Load the 3-wire RTD device configuration */ |
| mahphalke |
0:08ba94bc5a30 | 1695 | init_with_configuration(AD7124_CONFIG_3WIRE_RTD); |
| mahphalke |
0:08ba94bc5a30 | 1696 | } |
| mahphalke |
0:08ba94bc5a30 | 1697 | |
| mahphalke |
0:08ba94bc5a30 | 1698 | printf("\t Sensor Channel IOUT0 IOUT1 AIN+ AIN- Enable" EOL); |
| mahphalke |
0:08ba94bc5a30 | 1699 | printf("\t ------------------------------------------------------" EOL); |
| mahphalke |
0:08ba94bc5a30 | 1700 | printf("\t RTD1 %d AIN%d AIN%d AIN%d AIN%d %c" |
| mahphalke |
0:08ba94bc5a30 | 1701 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1702 | SENSOR_CHANNEL0, RTD1_3WIRE_IOUT0, RTD1_3WIRE_IOUT1, RTD1_3WIRE_AINP, |
| mahphalke |
0:08ba94bc5a30 | 1703 | RTD1_3WIRE_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1704 | status_info[sensor_enable_status[SENSOR_CHANNEL0]]); |
| mahphalke |
0:08ba94bc5a30 | 1705 | printf("\t RTD2 %d AIN%d AIN%d AIN%d AIN%d %c" |
| mahphalke |
0:08ba94bc5a30 | 1706 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1707 | SENSOR_CHANNEL1, RTD2_3WIRE_IOUT0, RTD2_3WIRE_IOUT1, RTD2_3WIRE_AINP, |
| mahphalke |
0:08ba94bc5a30 | 1708 | RTD2_3WIRE_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1709 | status_info[sensor_enable_status[SENSOR_CHANNEL1]]); |
| mahphalke |
0:08ba94bc5a30 | 1710 | #if defined(AD7124_8) |
| mahphalke |
0:08ba94bc5a30 | 1711 | printf("\t RTD3 %d AIN%d AIN%d AIN%d AIN%d %c" |
| mahphalke |
0:08ba94bc5a30 | 1712 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1713 | SENSOR_CHANNEL2, RTD3_3WIRE_IOUT0, RTD3_3WIRE_IOUT1, RTD3_3WIRE_AINP, |
| mahphalke |
0:08ba94bc5a30 | 1714 | RTD3_3WIRE_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1715 | status_info[sensor_enable_status[SENSOR_CHANNEL2]]); |
| mahphalke |
0:08ba94bc5a30 | 1716 | printf("\t RTD4 %d AIN%d AIN%d AIN%d AIN%d %c" |
| mahphalke |
0:08ba94bc5a30 | 1717 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1718 | SENSOR_CHANNEL3, RTD4_3WIRE_IOUT0, RTD4_3WIRE_IOUT1, RTD4_3WIRE_AINP, |
| mahphalke |
0:08ba94bc5a30 | 1719 | RTD4_3WIRE_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1720 | status_info[sensor_enable_status[SENSOR_CHANNEL3]]); |
| mahphalke |
0:08ba94bc5a30 | 1721 | #endif |
| mahphalke |
5:90166c496b01 | 1722 | |
| mahphalke |
5:90166c496b01 | 1723 | printf("\t -------------------------------------------------------------------" |
| mahphalke |
5:90166c496b01 | 1724 | EOL); |
| mahphalke |
5:90166c496b01 | 1725 | printf("\tNote: For single RTD measurement, connect Rref at the higher side" |
| mahphalke |
5:90166c496b01 | 1726 | EOL); |
| mahphalke |
5:90166c496b01 | 1727 | printf("\t For multiple RTD measurement, connect Rref at the lower side" |
| mahphalke |
5:90166c496b01 | 1728 | EOL); |
| mahphalke |
0:08ba94bc5a30 | 1729 | } |
| mahphalke |
0:08ba94bc5a30 | 1730 | |
| mahphalke |
0:08ba94bc5a30 | 1731 | |
| mahphalke |
0:08ba94bc5a30 | 1732 | /*! |
| mahphalke |
0:08ba94bc5a30 | 1733 | * @brief Display header information for 3-wire RTD calibration menu |
| mahphalke |
0:08ba94bc5a30 | 1734 | * @return none |
| mahphalke |
0:08ba94bc5a30 | 1735 | */ |
| mahphalke |
0:08ba94bc5a30 | 1736 | void rtd_3wire_calibration_menu_header(void) |
| mahphalke |
0:08ba94bc5a30 | 1737 | { |
| mahphalke |
0:08ba94bc5a30 | 1738 | if (rtd_3wire_calibration_type == MEASURING_EXCITATION_CURRENT) { |
| mahphalke |
0:08ba94bc5a30 | 1739 | if (strcmp(current_sensor_config, sensor_configs[AD7124_CONFIG_3WIRE_RTD])) { |
| mahphalke |
0:08ba94bc5a30 | 1740 | /* Disable unused sensor channels */ |
| mahphalke |
0:08ba94bc5a30 | 1741 | for (uint8_t chn = max_supported_sensors[AD7124_CONFIG_3WIRE_RTD]; |
| mahphalke |
0:08ba94bc5a30 | 1742 | chn < NUM_OF_SENSOR_CHANNELS; chn++) { |
| mahphalke |
0:08ba94bc5a30 | 1743 | sensor_enable_status[chn] = false; |
| mahphalke |
0:08ba94bc5a30 | 1744 | } |
| mahphalke |
0:08ba94bc5a30 | 1745 | |
| mahphalke |
0:08ba94bc5a30 | 1746 | /* Load the 3-wire RTD device configuration */ |
| mahphalke |
0:08ba94bc5a30 | 1747 | init_with_configuration(AD7124_CONFIG_3WIRE_RTD); |
| mahphalke |
0:08ba94bc5a30 | 1748 | } |
| mahphalke |
0:08ba94bc5a30 | 1749 | |
| mahphalke |
0:08ba94bc5a30 | 1750 | /* For 'Iout measurement type calibration', the additional 2 analog inputs |
| mahphalke |
0:08ba94bc5a30 | 1751 | * are needed for Ref measurement, which reduces number of allowed sensors |
| mahphalke |
0:08ba94bc5a30 | 1752 | * interfaces by 1 */ |
| mahphalke |
0:08ba94bc5a30 | 1753 | #if defined(AD7124_8) |
| mahphalke |
0:08ba94bc5a30 | 1754 | /* Chn 0, 1 and 2 are active. Chn3 is disabled */ |
| mahphalke |
0:08ba94bc5a30 | 1755 | sensor_enable_status[SENSOR_CHANNEL3] = false; |
| mahphalke |
0:08ba94bc5a30 | 1756 | #else |
| mahphalke |
0:08ba94bc5a30 | 1757 | /* Chn0 is active. Chn1 is disabled */ |
| mahphalke |
0:08ba94bc5a30 | 1758 | sensor_enable_status[SENSOR_CHANNEL1] = false; |
| mahphalke |
0:08ba94bc5a30 | 1759 | #endif |
| mahphalke |
0:08ba94bc5a30 | 1760 | |
| mahphalke |
0:08ba94bc5a30 | 1761 | printf("\t Calibration Type: Measuring Excitation Current" EOL); |
| mahphalke |
0:08ba94bc5a30 | 1762 | printf("\t -------------------------------------------------------------------" |
| mahphalke |
0:08ba94bc5a30 | 1763 | EOL); |
| mahphalke |
0:08ba94bc5a30 | 1764 | printf("\t Sensor Channel RTD RTD IOUT0 IOUT1 Ref Ref Enable" |
| mahphalke |
0:08ba94bc5a30 | 1765 | EOL); |
| mahphalke |
0:08ba94bc5a30 | 1766 | printf("\t AIN+ AIN- AIN+ AIN- " |
| mahphalke |
0:08ba94bc5a30 | 1767 | EOL); |
| mahphalke |
0:08ba94bc5a30 | 1768 | printf("\t -------------------------------------------------------------------" |
| mahphalke |
0:08ba94bc5a30 | 1769 | EOL); |
| mahphalke |
0:08ba94bc5a30 | 1770 | |
| mahphalke |
0:08ba94bc5a30 | 1771 | printf("\t RTD1 %d AIN%d AIN%d AIN%d AIN%d AIN%d AIN%d %c" |
| mahphalke |
0:08ba94bc5a30 | 1772 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1773 | SENSOR_CHANNEL0, |
| mahphalke |
0:08ba94bc5a30 | 1774 | RTD1_3WIRE_AINP, RTD1_3WIRE_AINM, RTD1_3WIRE_IOUT0, |
| mahphalke |
0:08ba94bc5a30 | 1775 | RTD1_3WIRE_IOUT1, RTD_3WIRE_EXC_MEASURE_AINP, RTD_3WIRE_EXC_MEASURE_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1776 | status_info[sensor_enable_status[SENSOR_CHANNEL0]]); |
| mahphalke |
0:08ba94bc5a30 | 1777 | |
| mahphalke |
0:08ba94bc5a30 | 1778 | #if defined(AD7124_8) |
| mahphalke |
0:08ba94bc5a30 | 1779 | printf("\t RTD2 %d AIN%d AIN%d AIN%d AIN%d AIN%d AIN%d %c" |
| mahphalke |
0:08ba94bc5a30 | 1780 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1781 | SENSOR_CHANNEL1, |
| mahphalke |
0:08ba94bc5a30 | 1782 | RTD2_3WIRE_AINP, RTD2_3WIRE_AINM, RTD2_3WIRE_IOUT0, |
| mahphalke |
0:08ba94bc5a30 | 1783 | RTD2_3WIRE_IOUT1, RTD_3WIRE_EXC_MEASURE_AINP, RTD_3WIRE_EXC_MEASURE_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1784 | status_info[sensor_enable_status[SENSOR_CHANNEL1]]); |
| mahphalke |
0:08ba94bc5a30 | 1785 | |
| mahphalke |
0:08ba94bc5a30 | 1786 | printf("\t RTD3 %d AIN%d AIN%d AIN%d AIN%d AIN%d AIN%d %c" |
| mahphalke |
0:08ba94bc5a30 | 1787 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1788 | SENSOR_CHANNEL2, |
| mahphalke |
0:08ba94bc5a30 | 1789 | RTD3_3WIRE_AINP, RTD3_3WIRE_AINM, RTD3_3WIRE_IOUT0, |
| mahphalke |
0:08ba94bc5a30 | 1790 | RTD3_3WIRE_IOUT1, RTD_3WIRE_EXC_MEASURE_AINP, RTD_3WIRE_EXC_MEASURE_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1791 | status_info[sensor_enable_status[SENSOR_CHANNEL2]]); |
| mahphalke |
0:08ba94bc5a30 | 1792 | #endif |
| mahphalke |
0:08ba94bc5a30 | 1793 | } else { |
| mahphalke |
0:08ba94bc5a30 | 1794 | printf("\t Calibration Type: Chopping Excitation Current " EOL); |
| mahphalke |
0:08ba94bc5a30 | 1795 | printf("\t ------------------------------------------------------" EOL); |
| mahphalke |
0:08ba94bc5a30 | 1796 | rtd_3wire_menu_header(); |
| mahphalke |
0:08ba94bc5a30 | 1797 | } |
| mahphalke |
0:08ba94bc5a30 | 1798 | } |
| mahphalke |
0:08ba94bc5a30 | 1799 | |
| mahphalke |
0:08ba94bc5a30 | 1800 | |
| mahphalke |
0:08ba94bc5a30 | 1801 | /*! |
| mahphalke |
0:08ba94bc5a30 | 1802 | * @brief Display header information for 4-wire RTD measurement menu |
| mahphalke |
0:08ba94bc5a30 | 1803 | * @return none |
| mahphalke |
0:08ba94bc5a30 | 1804 | */ |
| mahphalke |
0:08ba94bc5a30 | 1805 | void rtd_4wire_menu_header(void) |
| mahphalke |
0:08ba94bc5a30 | 1806 | { |
| mahphalke |
0:08ba94bc5a30 | 1807 | if (strcmp(current_sensor_config, sensor_configs[AD7124_CONFIG_4WIRE_RTD])) { |
| mahphalke |
0:08ba94bc5a30 | 1808 | /* Disable unused sensor channels */ |
| mahphalke |
0:08ba94bc5a30 | 1809 | for (uint8_t chn = max_supported_sensors[AD7124_CONFIG_4WIRE_RTD]; |
| mahphalke |
0:08ba94bc5a30 | 1810 | chn < NUM_OF_SENSOR_CHANNELS; chn++) { |
| mahphalke |
0:08ba94bc5a30 | 1811 | sensor_enable_status[chn] = false; |
| mahphalke |
0:08ba94bc5a30 | 1812 | } |
| mahphalke |
0:08ba94bc5a30 | 1813 | |
| mahphalke |
0:08ba94bc5a30 | 1814 | /* Load the 4-wire RTD device configuration */ |
| mahphalke |
0:08ba94bc5a30 | 1815 | init_with_configuration(AD7124_CONFIG_4WIRE_RTD); |
| mahphalke |
0:08ba94bc5a30 | 1816 | } |
| mahphalke |
0:08ba94bc5a30 | 1817 | |
| mahphalke |
0:08ba94bc5a30 | 1818 | printf("\t Sensor Channel IOUT0 AIN+ AIN- Enable" EOL); |
| mahphalke |
0:08ba94bc5a30 | 1819 | printf("\t -----------------------------------------------" EOL); |
| mahphalke |
0:08ba94bc5a30 | 1820 | printf("\t RTD1 %d AIN%d AIN%d AIN%d %c" |
| mahphalke |
0:08ba94bc5a30 | 1821 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1822 | SENSOR_CHANNEL0, RTD1_4WIRE_IOUT0, RTD1_4WIRE_AINP, RTD1_4WIRE_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1823 | status_info[sensor_enable_status[SENSOR_CHANNEL0]]); |
| mahphalke |
0:08ba94bc5a30 | 1824 | printf("\t RTD2 %d AIN%d AIN%d AIN%d %c" |
| mahphalke |
0:08ba94bc5a30 | 1825 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1826 | SENSOR_CHANNEL1, RTD2_4WIRE_IOUT0, RTD2_4WIRE_AINP, RTD2_4WIRE_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1827 | status_info[sensor_enable_status[SENSOR_CHANNEL1]]); |
| mahphalke |
0:08ba94bc5a30 | 1828 | #if defined(AD7124_8) |
| mahphalke |
0:08ba94bc5a30 | 1829 | printf("\t RTD3 %d AIN%d AIN%d AIN%d %c" EOL, |
| mahphalke |
0:08ba94bc5a30 | 1830 | SENSOR_CHANNEL2, RTD3_4WIRE_IOUT0, RTD3_4WIRE_AINP, RTD3_4WIRE_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1831 | status_info[sensor_enable_status[SENSOR_CHANNEL2]]); |
| mahphalke |
0:08ba94bc5a30 | 1832 | printf("\t RTD4 %d AIN%d AIN%d AIN%d %c" EOL, |
| mahphalke |
0:08ba94bc5a30 | 1833 | SENSOR_CHANNEL3, RTD4_4WIRE_IOUT0, RTD4_4WIRE_AINP, RTD4_4WIRE_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1834 | status_info[sensor_enable_status[SENSOR_CHANNEL3]]); |
| mahphalke |
0:08ba94bc5a30 | 1835 | printf("\t RTD5 %d AIN%d AIN%d AIN%d %c" EOL, |
| mahphalke |
0:08ba94bc5a30 | 1836 | SENSOR_CHANNEL4, RTD5_4WIRE_IOUT0, RTD5_4WIRE_AINP, RTD5_4WIRE_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1837 | status_info[sensor_enable_status[SENSOR_CHANNEL4]]); |
| mahphalke |
0:08ba94bc5a30 | 1838 | #endif |
| mahphalke |
0:08ba94bc5a30 | 1839 | } |
| mahphalke |
0:08ba94bc5a30 | 1840 | |
| mahphalke |
0:08ba94bc5a30 | 1841 | |
| mahphalke |
0:08ba94bc5a30 | 1842 | /*! |
| mahphalke |
0:08ba94bc5a30 | 1843 | * @brief Display header information for NTC thermistor measurement menu |
| mahphalke |
0:08ba94bc5a30 | 1844 | * @return none |
| mahphalke |
0:08ba94bc5a30 | 1845 | */ |
| mahphalke |
0:08ba94bc5a30 | 1846 | void ntc_thermistor_menu_header(void) |
| mahphalke |
0:08ba94bc5a30 | 1847 | { |
| mahphalke |
0:08ba94bc5a30 | 1848 | if (strcmp(current_sensor_config, sensor_configs[AD7124_CONFIG_THERMISTOR])) { |
| mahphalke |
0:08ba94bc5a30 | 1849 | /* Disable unused sensor channels */ |
| mahphalke |
0:08ba94bc5a30 | 1850 | for (uint8_t chn = max_supported_sensors[AD7124_CONFIG_THERMISTOR]; |
| mahphalke |
0:08ba94bc5a30 | 1851 | chn < NUM_OF_SENSOR_CHANNELS; chn++) { |
| mahphalke |
0:08ba94bc5a30 | 1852 | sensor_enable_status[chn] = false; |
| mahphalke |
0:08ba94bc5a30 | 1853 | } |
| mahphalke |
0:08ba94bc5a30 | 1854 | |
| mahphalke |
0:08ba94bc5a30 | 1855 | /* Load the Thermistor device configuration */ |
| mahphalke |
0:08ba94bc5a30 | 1856 | init_with_configuration(AD7124_CONFIG_THERMISTOR); |
| mahphalke |
0:08ba94bc5a30 | 1857 | } |
| mahphalke |
0:08ba94bc5a30 | 1858 | |
| mahphalke |
0:08ba94bc5a30 | 1859 | printf("\t Sensor Channel AIN+ AIN- Enable" EOL); |
| mahphalke |
0:08ba94bc5a30 | 1860 | printf("\t ---------------------------------------" EOL); |
| mahphalke |
0:08ba94bc5a30 | 1861 | printf("\t NTC1 %d AIN%d AIN%d %c" |
| mahphalke |
0:08ba94bc5a30 | 1862 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1863 | SENSOR_CHANNEL0, NTC1_THERMISTOR_AINP, NTC1_THERMISTOR_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1864 | status_info[sensor_enable_status[SENSOR_CHANNEL0]]); |
| mahphalke |
0:08ba94bc5a30 | 1865 | printf("\t NTC2 %d AIN%d AIN%d %c" |
| mahphalke |
0:08ba94bc5a30 | 1866 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1867 | SENSOR_CHANNEL1, NTC2_THERMISTOR_AINP, NTC2_THERMISTOR_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1868 | status_info[sensor_enable_status[SENSOR_CHANNEL1]]); |
| mahphalke |
0:08ba94bc5a30 | 1869 | printf("\t NTC3 %d AIN%d AIN%d %c" |
| mahphalke |
0:08ba94bc5a30 | 1870 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1871 | SENSOR_CHANNEL2, NTC3_THERMISTOR_AINP, NTC3_THERMISTOR_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1872 | status_info[sensor_enable_status[SENSOR_CHANNEL2]]); |
| mahphalke |
0:08ba94bc5a30 | 1873 | printf("\t NTC4 %d AIN%d AIN%d %c" |
| mahphalke |
0:08ba94bc5a30 | 1874 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1875 | SENSOR_CHANNEL3, NTC4_THERMISTOR_AINP, NTC4_THERMISTOR_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1876 | status_info[sensor_enable_status[SENSOR_CHANNEL3]]); |
| mahphalke |
0:08ba94bc5a30 | 1877 | #if defined(AD7124_8) |
| mahphalke |
0:08ba94bc5a30 | 1878 | printf("\t NTC5 %d AIN%d AIN%d %c" EOL, |
| mahphalke |
0:08ba94bc5a30 | 1879 | SENSOR_CHANNEL4, NTC5_THERMISTOR_AINP, NTC5_THERMISTOR_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1880 | status_info[sensor_enable_status[SENSOR_CHANNEL4]]); |
| mahphalke |
0:08ba94bc5a30 | 1881 | printf("\t NTC6 %d AIN%d AIN%d %c" EOL, |
| mahphalke |
0:08ba94bc5a30 | 1882 | SENSOR_CHANNEL5, NTC6_THERMISTOR_AINP, NTC6_THERMISTOR_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1883 | status_info[sensor_enable_status[SENSOR_CHANNEL5]]); |
| mahphalke |
0:08ba94bc5a30 | 1884 | printf("\t NTC7 %d AIN%d AIN%d %c" EOL, |
| mahphalke |
0:08ba94bc5a30 | 1885 | SENSOR_CHANNEL6, NTC7_THERMISTOR_AINP, NTC7_THERMISTOR_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1886 | status_info[sensor_enable_status[SENSOR_CHANNEL6]]); |
| mahphalke |
0:08ba94bc5a30 | 1887 | printf("\t NTC8 %d AIN%d AIN%d %c" EOL, |
| mahphalke |
0:08ba94bc5a30 | 1888 | SENSOR_CHANNEL7, NTC8_THERMISTOR_AINP, NTC8_THERMISTOR_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1889 | status_info[sensor_enable_status[SENSOR_CHANNEL7]]); |
| mahphalke |
0:08ba94bc5a30 | 1890 | #endif |
| mahphalke |
0:08ba94bc5a30 | 1891 | } |
| mahphalke |
0:08ba94bc5a30 | 1892 | |
| mahphalke |
0:08ba94bc5a30 | 1893 | |
| mahphalke |
0:08ba94bc5a30 | 1894 | /*! |
| mahphalke |
0:08ba94bc5a30 | 1895 | * @brief Display header information for NTC thermistor measurement menu |
| mahphalke |
0:08ba94bc5a30 | 1896 | * @return none |
| mahphalke |
0:08ba94bc5a30 | 1897 | */ |
| mahphalke |
0:08ba94bc5a30 | 1898 | void thermocouple_menu_header(void) |
| mahphalke |
0:08ba94bc5a30 | 1899 | { |
| mahphalke |
0:08ba94bc5a30 | 1900 | if (strcmp(current_sensor_config, sensor_configs[AD7124_CONFIG_THERMOCOUPLE])) { |
| mahphalke |
0:08ba94bc5a30 | 1901 | /* Disable unused sensor channels */ |
| mahphalke |
0:08ba94bc5a30 | 1902 | for (uint8_t chn = max_supported_sensors[AD7124_CONFIG_THERMOCOUPLE]; |
| mahphalke |
0:08ba94bc5a30 | 1903 | chn < NUM_OF_SENSOR_CHANNELS; chn++) { |
| mahphalke |
0:08ba94bc5a30 | 1904 | sensor_enable_status[chn] = false; |
| mahphalke |
0:08ba94bc5a30 | 1905 | } |
| mahphalke |
0:08ba94bc5a30 | 1906 | |
| mahphalke |
0:08ba94bc5a30 | 1907 | /* Select CJC sensor */ |
| mahphalke |
0:08ba94bc5a30 | 1908 | select_cjc_sensor(current_cjc_sensor); |
| mahphalke |
0:08ba94bc5a30 | 1909 | |
| mahphalke |
0:08ba94bc5a30 | 1910 | /* Load the Thermocouple device configuration */ |
| mahphalke |
0:08ba94bc5a30 | 1911 | init_with_configuration(AD7124_CONFIG_THERMOCOUPLE); |
| mahphalke |
0:08ba94bc5a30 | 1912 | } |
| mahphalke |
0:08ba94bc5a30 | 1913 | |
| mahphalke |
0:08ba94bc5a30 | 1914 | printf("\t Sensor Channel IOUT0 AIN+ AIN- Enable" EOL); |
| mahphalke |
0:08ba94bc5a30 | 1915 | printf("\t ----------------------------------------------" EOL); |
| mahphalke |
0:08ba94bc5a30 | 1916 | printf("\t TC1 %d - AIN%d AIN%d %c" |
| mahphalke |
0:08ba94bc5a30 | 1917 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1918 | SENSOR_CHANNEL0, THERMOCOUPLE1_AINP, THERMOCOUPLE1_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1919 | status_info[sensor_enable_status[SENSOR_CHANNEL0]]); |
| mahphalke |
0:08ba94bc5a30 | 1920 | printf("\t TC2 %d - AIN%d AIN%d %c" |
| mahphalke |
0:08ba94bc5a30 | 1921 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1922 | SENSOR_CHANNEL1, THERMOCOUPLE2_AINP, THERMOCOUPLE2_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1923 | status_info[sensor_enable_status[SENSOR_CHANNEL1]]); |
| mahphalke |
0:08ba94bc5a30 | 1924 | #if defined(AD7124_8) |
| mahphalke |
0:08ba94bc5a30 | 1925 | printf("\t TC3 %d - AIN%d AIN%d %c" |
| mahphalke |
0:08ba94bc5a30 | 1926 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1927 | SENSOR_CHANNEL2, THERMOCOUPLE3_AINP, THERMOCOUPLE3_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1928 | status_info[sensor_enable_status[SENSOR_CHANNEL2]]); |
| mahphalke |
0:08ba94bc5a30 | 1929 | printf("\t TC4 %d - AIN%d AIN%d %c" |
| mahphalke |
0:08ba94bc5a30 | 1930 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1931 | SENSOR_CHANNEL3, THERMOCOUPLE4_AINP, THERMOCOUPLE4_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1932 | status_info[sensor_enable_status[SENSOR_CHANNEL3]]); |
| mahphalke |
0:08ba94bc5a30 | 1933 | printf("\t TC5 %d - AIN%d AIN%d %c" EOL, |
| mahphalke |
0:08ba94bc5a30 | 1934 | SENSOR_CHANNEL4, THERMOCOUPLE5_AINP, THERMOCOUPLE5_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1935 | status_info[sensor_enable_status[SENSOR_CHANNEL4]]); |
| mahphalke |
0:08ba94bc5a30 | 1936 | printf("\t TC6 %d - AIN%d AIN%d %c" EOL, |
| mahphalke |
0:08ba94bc5a30 | 1937 | SENSOR_CHANNEL5, THERMOCOUPLE6_AINP, THERMOCOUPLE6_AINM, |
| mahphalke |
0:08ba94bc5a30 | 1938 | status_info[sensor_enable_status[SENSOR_CHANNEL5]]); |
| mahphalke |
0:08ba94bc5a30 | 1939 | #endif |
| mahphalke |
0:08ba94bc5a30 | 1940 | |
| mahphalke |
0:08ba94bc5a30 | 1941 | printf(EOL "\t Current CJC: %s" EOL, cjc_sensor_names[current_cjc_sensor]); |
| mahphalke |
0:08ba94bc5a30 | 1942 | printf("\t ----------------------------------------------" EOL); |
| mahphalke |
0:08ba94bc5a30 | 1943 | |
| mahphalke |
0:08ba94bc5a30 | 1944 | switch (current_cjc_sensor) { |
| mahphalke |
0:08ba94bc5a30 | 1945 | case PT100_4WIRE_RTD: |
| mahphalke |
5:90166c496b01 | 1946 | case PT1000_2WIRE_RTD: |
| mahphalke |
0:08ba94bc5a30 | 1947 | printf("\t CJC %d AIN%d AIN%d AIN%d Y" |
| mahphalke |
0:08ba94bc5a30 | 1948 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1949 | CJC_RTD_CHN, |
| mahphalke |
5:90166c496b01 | 1950 | CJC_RTD_IOUT0, |
| mahphalke |
5:90166c496b01 | 1951 | CJC_RTD_AINP, |
| mahphalke |
5:90166c496b01 | 1952 | CJC_RTD_AINM); |
| mahphalke |
0:08ba94bc5a30 | 1953 | break; |
| mahphalke |
0:08ba94bc5a30 | 1954 | |
| mahphalke |
0:08ba94bc5a30 | 1955 | case THERMISTOR_PTC_KY81_110: |
| mahphalke |
0:08ba94bc5a30 | 1956 | printf("\t CJC %d AIN%d AIN%d AIN%d Y" |
| mahphalke |
0:08ba94bc5a30 | 1957 | EOL, |
| mahphalke |
0:08ba94bc5a30 | 1958 | CJC_THERMISTOR_CHN, |
| mahphalke |
0:08ba94bc5a30 | 1959 | CJC_PTC_THERMISTOR_IOUT0, |
| mahphalke |
0:08ba94bc5a30 | 1960 | CJC_PTC_THERMISTOR_AINP, |
| mahphalke |
0:08ba94bc5a30 | 1961 | CJC_PTC_THERMISTOR_AINM); |
| mahphalke |
0:08ba94bc5a30 | 1962 | break; |
| mahphalke |
0:08ba94bc5a30 | 1963 | |
| mahphalke |
0:08ba94bc5a30 | 1964 | default: |
| mahphalke |
0:08ba94bc5a30 | 1965 | printf("\t No CJC selected!!" EOL); |
| mahphalke |
0:08ba94bc5a30 | 1966 | break; |
| mahphalke |
0:08ba94bc5a30 | 1967 | } |
| mahphalke |
0:08ba94bc5a30 | 1968 | } |
| mahphalke |
0:08ba94bc5a30 | 1969 | |
| mahphalke |
0:08ba94bc5a30 | 1970 | |
| mahphalke |
0:08ba94bc5a30 | 1971 | /*! |
| mahphalke |
0:08ba94bc5a30 | 1972 | * @brief Display header information for ADC calibration menu |
| mahphalke |
0:08ba94bc5a30 | 1973 | * @return none |
| mahphalke |
0:08ba94bc5a30 | 1974 | */ |
| mahphalke |
0:08ba94bc5a30 | 1975 | void adc_calibration_menu_header(void) |
| mahphalke |
0:08ba94bc5a30 | 1976 | { |
| mahphalke |
0:08ba94bc5a30 | 1977 | printf("\tCurrent Config: %s" EOL, current_sensor_config); |
| mahphalke |
0:08ba94bc5a30 | 1978 | printf("\t----------------------------------------------------" EOL); |
| mahphalke |
0:08ba94bc5a30 | 1979 | printf("\t CHN0: %c | CHN1: %c | CHN2: %c | CHN3: %c" EOL |
| mahphalke |
0:08ba94bc5a30 | 1980 | "\t CHN4: %c | CHN5: %c | CHN6: %c | CHN7: %c" EOL, |
| mahphalke |
0:08ba94bc5a30 | 1981 | status_info[sensor_enable_status[SENSOR_CHANNEL0]], |
| mahphalke |
0:08ba94bc5a30 | 1982 | status_info[sensor_enable_status[SENSOR_CHANNEL1]], |
| mahphalke |
0:08ba94bc5a30 | 1983 | status_info[sensor_enable_status[SENSOR_CHANNEL2]], |
| mahphalke |
0:08ba94bc5a30 | 1984 | status_info[sensor_enable_status[SENSOR_CHANNEL3]], |
| mahphalke |
0:08ba94bc5a30 | 1985 | status_info[sensor_enable_status[SENSOR_CHANNEL4]], |
| mahphalke |
0:08ba94bc5a30 | 1986 | status_info[sensor_enable_status[SENSOR_CHANNEL5]], |
| mahphalke |
0:08ba94bc5a30 | 1987 | status_info[sensor_enable_status[SENSOR_CHANNEL6]], |
| mahphalke |
0:08ba94bc5a30 | 1988 | status_info[sensor_enable_status[SENSOR_CHANNEL7]]); |
| mahphalke |
0:08ba94bc5a30 | 1989 | } |
| mahphalke |
0:08ba94bc5a30 | 1990 | |
| mahphalke |
0:08ba94bc5a30 | 1991 | |
| mahphalke |
0:08ba94bc5a30 | 1992 | /*! |
| mahphalke |
0:08ba94bc5a30 | 1993 | * @brief Display header information for main menu |
| mahphalke |
0:08ba94bc5a30 | 1994 | * @return none |
| mahphalke |
0:08ba94bc5a30 | 1995 | */ |
| mahphalke |
0:08ba94bc5a30 | 1996 | void main_menu_header(void) |
| mahphalke |
0:08ba94bc5a30 | 1997 | { |
| mahphalke |
0:08ba94bc5a30 | 1998 | printf("\tCurrent Config: %s,", current_sensor_config); |
| mahphalke |
0:08ba94bc5a30 | 1999 | printf(" Active Device: %s" EOL, ACTIVE_DEVICE); |
| mahphalke |
0:08ba94bc5a30 | 2000 | } |
| mahphalke |
0:08ba94bc5a30 | 2001 | |
| mahphalke |
0:08ba94bc5a30 | 2002 | |
| mahphalke |
0:08ba94bc5a30 | 2003 | /*! |
| mahphalke |
0:08ba94bc5a30 | 2004 | * @brief Display 2-wire RTD measurement main menu |
| mahphalke |
0:08ba94bc5a30 | 2005 | * @param menu_id[in]- Optional menu ID |
| mahphalke |
0:08ba94bc5a30 | 2006 | * @return MENU_CONTINUE |
| mahphalke |
0:08ba94bc5a30 | 2007 | */ |
| mahphalke |
0:08ba94bc5a30 | 2008 | int32_t display_2wire_rtd_menu(uint32_t menu_id) |
| mahphalke |
0:08ba94bc5a30 | 2009 | { |
| mahphalke |
0:08ba94bc5a30 | 2010 | return adi_do_console_menu(&rtd_2wire_menu); |
| mahphalke |
0:08ba94bc5a30 | 2011 | } |
| mahphalke |
0:08ba94bc5a30 | 2012 | |
| mahphalke |
0:08ba94bc5a30 | 2013 | |
| mahphalke |
0:08ba94bc5a30 | 2014 | /*! |
| mahphalke |
0:08ba94bc5a30 | 2015 | * @brief Display 3-wire RTD measurement main menu |
| mahphalke |
0:08ba94bc5a30 | 2016 | * @param menu_id[in]- Optional menu ID |
| mahphalke |
0:08ba94bc5a30 | 2017 | * @return MENU_CONTINUE |
| mahphalke |
0:08ba94bc5a30 | 2018 | */ |
| mahphalke |
0:08ba94bc5a30 | 2019 | int32_t display_3wire_rtd_menu(uint32_t menu_id) |
| mahphalke |
0:08ba94bc5a30 | 2020 | { |
| mahphalke |
0:08ba94bc5a30 | 2021 | return adi_do_console_menu(&rtd_3wire_menu); |
| mahphalke |
0:08ba94bc5a30 | 2022 | } |
| mahphalke |
0:08ba94bc5a30 | 2023 | |
| mahphalke |
0:08ba94bc5a30 | 2024 | |
| mahphalke |
0:08ba94bc5a30 | 2025 | /*! |
| mahphalke |
0:08ba94bc5a30 | 2026 | * @brief Display 3-wire RTD calibration main menu |
| mahphalke |
0:08ba94bc5a30 | 2027 | * @param menu_id[in]- Optional menu ID |
| mahphalke |
0:08ba94bc5a30 | 2028 | * @return MENU_CONTINUE |
| mahphalke |
0:08ba94bc5a30 | 2029 | */ |
| mahphalke |
0:08ba94bc5a30 | 2030 | int32_t display_3wire_rtd_calibration_menu(uint32_t menu_id) |
| mahphalke |
0:08ba94bc5a30 | 2031 | { |
| mahphalke |
0:08ba94bc5a30 | 2032 | return adi_do_console_menu(&rtd_3wire_calibration_menu); |
| mahphalke |
0:08ba94bc5a30 | 2033 | } |
| mahphalke |
0:08ba94bc5a30 | 2034 | |
| mahphalke |
0:08ba94bc5a30 | 2035 | |
| mahphalke |
0:08ba94bc5a30 | 2036 | /*! |
| mahphalke |
0:08ba94bc5a30 | 2037 | * @brief Display 4-wire RTD measurement main menu |
| mahphalke |
0:08ba94bc5a30 | 2038 | * @param menu_id[in]- Optional menu ID |
| mahphalke |
0:08ba94bc5a30 | 2039 | * @return MENU_CONTINUE |
| mahphalke |
0:08ba94bc5a30 | 2040 | */ |
| mahphalke |
0:08ba94bc5a30 | 2041 | int32_t display_4wire_rtd_menu(uint32_t menu_id) |
| mahphalke |
0:08ba94bc5a30 | 2042 | { |
| mahphalke |
0:08ba94bc5a30 | 2043 | return adi_do_console_menu(&rtd_4wire_menu); |
| mahphalke |
0:08ba94bc5a30 | 2044 | } |
| mahphalke |
0:08ba94bc5a30 | 2045 | |
| mahphalke |
0:08ba94bc5a30 | 2046 | |
| mahphalke |
0:08ba94bc5a30 | 2047 | /*! |
| mahphalke |
0:08ba94bc5a30 | 2048 | * @brief Display thermoucouple measurement main menu |
| mahphalke |
0:08ba94bc5a30 | 2049 | * @param menu_id[in]- Optional menu ID |
| mahphalke |
0:08ba94bc5a30 | 2050 | * @return MENU_CONTINUE |
| mahphalke |
0:08ba94bc5a30 | 2051 | */ |
| mahphalke |
0:08ba94bc5a30 | 2052 | int32_t display_thermocouple_menu(uint32_t menu_id) |
| mahphalke |
0:08ba94bc5a30 | 2053 | { |
| mahphalke |
0:08ba94bc5a30 | 2054 | return adi_do_console_menu(&thermocouple_menu); |
| mahphalke |
0:08ba94bc5a30 | 2055 | } |
| mahphalke |
0:08ba94bc5a30 | 2056 | |
| mahphalke |
0:08ba94bc5a30 | 2057 | |
| mahphalke |
0:08ba94bc5a30 | 2058 | /*! |
| mahphalke |
0:08ba94bc5a30 | 2059 | * @brief Display thermistor measurement main menu |
| mahphalke |
0:08ba94bc5a30 | 2060 | * @param menu_id[in]- Optional menu ID |
| mahphalke |
0:08ba94bc5a30 | 2061 | * @return MENU_CONTINUE |
| mahphalke |
0:08ba94bc5a30 | 2062 | */ |
| mahphalke |
0:08ba94bc5a30 | 2063 | int32_t display_ntc_thermistor_menu(uint32_t menu_id) |
| mahphalke |
0:08ba94bc5a30 | 2064 | { |
| mahphalke |
0:08ba94bc5a30 | 2065 | return adi_do_console_menu(&ntc_thermistor_menu); |
| mahphalke |
0:08ba94bc5a30 | 2066 | } |
| mahphalke |
0:08ba94bc5a30 | 2067 | |
| mahphalke |
0:08ba94bc5a30 | 2068 | |
| mahphalke |
0:08ba94bc5a30 | 2069 | /*! |
| mahphalke |
0:08ba94bc5a30 | 2070 | * @brief Display ADC calibration main menu |
| mahphalke |
0:08ba94bc5a30 | 2071 | * @param menu_id[in]- Optional menu ID |
| mahphalke |
0:08ba94bc5a30 | 2072 | * @return MENU_CONTINUE |
| mahphalke |
0:08ba94bc5a30 | 2073 | */ |
| mahphalke |
0:08ba94bc5a30 | 2074 | int32_t display_adc_calibration_menu(uint32_t menu_id) |
| mahphalke |
0:08ba94bc5a30 | 2075 | { |
| mahphalke |
0:08ba94bc5a30 | 2076 | return adi_do_console_menu(&adc_calibration_menu); |
| mahphalke |
0:08ba94bc5a30 | 2077 | } |
| mahphalke |
0:08ba94bc5a30 | 2078 | |
| mahphalke |
0:08ba94bc5a30 | 2079 | |
| mahphalke |
5:90166c496b01 | 2080 | /*! |
| mahphalke |
5:90166c496b01 | 2081 | * @brief Display ADC calibration main menu |
| mahphalke |
5:90166c496b01 | 2082 | * @param menu_id[in]- Optional menu ID |
| mahphalke |
5:90166c496b01 | 2083 | * @return MENU_CONTINUE |
| mahphalke |
5:90166c496b01 | 2084 | */ |
| mahphalke |
5:90166c496b01 | 2085 | int32_t reset_device_config(uint32_t menu_id) |
| mahphalke |
5:90166c496b01 | 2086 | { |
| mahphalke |
5:90166c496b01 | 2087 | if (init_with_configuration(AD7124_CONFIG_RESET) != SUCCESS) { |
| mahphalke |
5:90166c496b01 | 2088 | printf(EOL "\t Error resetting config!!" EOL); |
| mahphalke |
5:90166c496b01 | 2089 | adi_press_any_key_to_continue(); |
| mahphalke |
5:90166c496b01 | 2090 | } else { |
| mahphalke |
5:90166c496b01 | 2091 | /* Disable all sensor channels except channel 0 */ |
| mahphalke |
5:90166c496b01 | 2092 | for (uint8_t chn = SENSOR_CHANNEL1; chn < NUM_OF_SENSOR_CHANNELS; chn++) { |
| mahphalke |
5:90166c496b01 | 2093 | sensor_enable_status[chn] = false; |
| mahphalke |
5:90166c496b01 | 2094 | } |
| mahphalke |
5:90166c496b01 | 2095 | } |
| mahphalke |
5:90166c496b01 | 2096 | |
| mahphalke |
5:90166c496b01 | 2097 | return MENU_CONTINUE; |
| mahphalke |
5:90166c496b01 | 2098 | } |
| mahphalke |
5:90166c496b01 | 2099 | |
| mahphalke |
5:90166c496b01 | 2100 | |
| mahphalke |
0:08ba94bc5a30 | 2101 | /* =========== Menu Declarations =========== */ |
| mahphalke |
0:08ba94bc5a30 | 2102 | |
| mahphalke |
0:08ba94bc5a30 | 2103 | static console_menu_item rtd_2wire_menu_items[] = { |
| mahphalke |
0:08ba94bc5a30 | 2104 | { "Enable/Disable RTD1", '1', enable_disable_sensor, SENSOR_CHANNEL0 }, |
| mahphalke |
0:08ba94bc5a30 | 2105 | { "Enable/Disable RTD2", '2', enable_disable_sensor, SENSOR_CHANNEL1 }, |
| mahphalke |
0:08ba94bc5a30 | 2106 | #if defined(AD7124_8) |
| mahphalke |
0:08ba94bc5a30 | 2107 | { "Enable/Disable RTD3", '3', enable_disable_sensor, SENSOR_CHANNEL2 }, |
| mahphalke |
0:08ba94bc5a30 | 2108 | { "Enable/Disable RTD4", '4', enable_disable_sensor, SENSOR_CHANNEL3 }, |
| mahphalke |
0:08ba94bc5a30 | 2109 | { "Enable/Disable RTD5", '5', enable_disable_sensor, SENSOR_CHANNEL4 }, |
| mahphalke |
0:08ba94bc5a30 | 2110 | #endif |
| mahphalke |
0:08ba94bc5a30 | 2111 | { " " }, |
| mahphalke |
5:90166c496b01 | 2112 | { "Perform Averaged Measurement", 'A', perform_2wire_rtd_measurement, AVERAGED_MEASUREMENT }, |
| mahphalke |
5:90166c496b01 | 2113 | { "Perform Single Measurement", 'S', perform_2wire_rtd_measurement, SINGLE_MEASUREMENT }, |
| mahphalke |
5:90166c496b01 | 2114 | { "Perform Continuos Measurement",'C', perform_2wire_rtd_measurement, CONTINUOUS_MEASUREMENT }, |
| mahphalke |
0:08ba94bc5a30 | 2115 | }; |
| mahphalke |
0:08ba94bc5a30 | 2116 | |
| mahphalke |
0:08ba94bc5a30 | 2117 | console_menu rtd_2wire_menu = { |
| mahphalke |
0:08ba94bc5a30 | 2118 | .title = "2-Wire RTD Measurement", |
| mahphalke |
0:08ba94bc5a30 | 2119 | .items = rtd_2wire_menu_items, |
| mahphalke |
0:08ba94bc5a30 | 2120 | .itemCount = ARRAY_SIZE(rtd_2wire_menu_items), |
| mahphalke |
0:08ba94bc5a30 | 2121 | .headerItem = rtd_2wire_menu_header, |
| mahphalke |
0:08ba94bc5a30 | 2122 | .footerItem = NULL, |
| mahphalke |
0:08ba94bc5a30 | 2123 | .enableEscapeKey = true |
| mahphalke |
0:08ba94bc5a30 | 2124 | }; |
| mahphalke |
0:08ba94bc5a30 | 2125 | |
| mahphalke |
0:08ba94bc5a30 | 2126 | static console_menu_item rtd_3wire_menu_items[] = { |
| mahphalke |
0:08ba94bc5a30 | 2127 | { "Enable/Disable RTD1", '1', enable_disable_sensor, SENSOR_CHANNEL0 }, |
| mahphalke |
0:08ba94bc5a30 | 2128 | { "Enable/Disable RTD2", '2', enable_disable_sensor, SENSOR_CHANNEL1 }, |
| mahphalke |
0:08ba94bc5a30 | 2129 | #if defined(AD7124_8) |
| mahphalke |
0:08ba94bc5a30 | 2130 | { "Enable/Disable RTD3", '3', enable_disable_sensor, SENSOR_CHANNEL2 }, |
| mahphalke |
0:08ba94bc5a30 | 2131 | { "Enable/Disable RTD4", '4', enable_disable_sensor, SENSOR_CHANNEL3 }, |
| mahphalke |
0:08ba94bc5a30 | 2132 | #endif |
| mahphalke |
0:08ba94bc5a30 | 2133 | { " " }, |
| mahphalke |
5:90166c496b01 | 2134 | { "Calibrate RTD and Perform Measurement", 'M', display_3wire_rtd_calibration_menu }, |
| mahphalke |
0:08ba94bc5a30 | 2135 | { " " }, |
| mahphalke |
5:90166c496b01 | 2136 | { "No Calibration Measurement:" }, |
| mahphalke |
5:90166c496b01 | 2137 | { "Perform Averaged Measurement", 'A', perform_3wire_rtd_measurement, AVERAGED_MEASUREMENT }, |
| mahphalke |
5:90166c496b01 | 2138 | { "Perform Single Measurement", 'S', perform_3wire_rtd_measurement, SINGLE_MEASUREMENT }, |
| mahphalke |
5:90166c496b01 | 2139 | { "Perform Continuos Measurement",'C', perform_3wire_rtd_measurement, CONTINUOUS_MEASUREMENT }, |
| mahphalke |
0:08ba94bc5a30 | 2140 | }; |
| mahphalke |
0:08ba94bc5a30 | 2141 | |
| mahphalke |
0:08ba94bc5a30 | 2142 | console_menu rtd_3wire_menu = { |
| mahphalke |
0:08ba94bc5a30 | 2143 | .title = "3-Wire RTD Measurement", |
| mahphalke |
0:08ba94bc5a30 | 2144 | .items = rtd_3wire_menu_items, |
| mahphalke |
0:08ba94bc5a30 | 2145 | .itemCount = ARRAY_SIZE(rtd_3wire_menu_items), |
| mahphalke |
0:08ba94bc5a30 | 2146 | .headerItem = rtd_3wire_menu_header, |
| mahphalke |
0:08ba94bc5a30 | 2147 | .footerItem = NULL, |
| mahphalke |
0:08ba94bc5a30 | 2148 | .enableEscapeKey = true |
| mahphalke |
0:08ba94bc5a30 | 2149 | }; |
| mahphalke |
0:08ba94bc5a30 | 2150 | |
| mahphalke |
0:08ba94bc5a30 | 2151 | static console_menu_item rtd_3wire_calibration_menu_items[] = { |
| mahphalke |
5:90166c496b01 | 2152 | { "Change type to Measuring Excitation Current", 'E', change_3wire_rtd_calibration_type, MEASURING_EXCITATION_CURRENT }, |
| mahphalke |
5:90166c496b01 | 2153 | { "Change type to Chopping Excitation Current", 'P', change_3wire_rtd_calibration_type, CHOPPING_EXCITATION_CURRENT }, |
| mahphalke |
0:08ba94bc5a30 | 2154 | { " " }, |
| mahphalke |
5:90166c496b01 | 2155 | { "Perform Averaged Measurement", 'A', calibrate_and_measure_3wire_rtd, AVERAGED_MEASUREMENT }, |
| mahphalke |
5:90166c496b01 | 2156 | { "Perform Single Measurement", 'S', calibrate_and_measure_3wire_rtd, SINGLE_MEASUREMENT }, |
| mahphalke |
5:90166c496b01 | 2157 | { "Perform Continuos Measurement",'C', calibrate_and_measure_3wire_rtd, CONTINUOUS_MEASUREMENT }, |
| mahphalke |
0:08ba94bc5a30 | 2158 | }; |
| mahphalke |
0:08ba94bc5a30 | 2159 | |
| mahphalke |
0:08ba94bc5a30 | 2160 | console_menu rtd_3wire_calibration_menu = { |
| mahphalke |
0:08ba94bc5a30 | 2161 | .title = "Calibrate 3-Wire RTD Excitation Source", |
| mahphalke |
0:08ba94bc5a30 | 2162 | .items = rtd_3wire_calibration_menu_items, |
| mahphalke |
0:08ba94bc5a30 | 2163 | .itemCount = ARRAY_SIZE(rtd_3wire_calibration_menu_items), |
| mahphalke |
0:08ba94bc5a30 | 2164 | .headerItem = rtd_3wire_calibration_menu_header, |
| mahphalke |
0:08ba94bc5a30 | 2165 | .footerItem = NULL, |
| mahphalke |
0:08ba94bc5a30 | 2166 | .enableEscapeKey = true |
| mahphalke |
0:08ba94bc5a30 | 2167 | }; |
| mahphalke |
0:08ba94bc5a30 | 2168 | |
| mahphalke |
0:08ba94bc5a30 | 2169 | static console_menu_item rtd_4wire_menu_items[] = { |
| mahphalke |
0:08ba94bc5a30 | 2170 | { "Enable/Disable RTD1", '1', enable_disable_sensor, SENSOR_CHANNEL0 }, |
| mahphalke |
0:08ba94bc5a30 | 2171 | { "Enable/Disable RTD2", '2', enable_disable_sensor, SENSOR_CHANNEL1 }, |
| mahphalke |
0:08ba94bc5a30 | 2172 | #if defined(AD7124_8) |
| mahphalke |
0:08ba94bc5a30 | 2173 | { "Enable/Disable RTD3", '3', enable_disable_sensor, SENSOR_CHANNEL2 }, |
| mahphalke |
0:08ba94bc5a30 | 2174 | { "Enable/Disable RTD4", '4', enable_disable_sensor, SENSOR_CHANNEL3 }, |
| mahphalke |
0:08ba94bc5a30 | 2175 | { "Enable/Disable RTD5", '5', enable_disable_sensor, SENSOR_CHANNEL4 }, |
| mahphalke |
0:08ba94bc5a30 | 2176 | #endif |
| mahphalke |
0:08ba94bc5a30 | 2177 | { " " }, |
| mahphalke |
5:90166c496b01 | 2178 | { "Perform Averaged Measurement", 'A', perform_4wire_rtd_measurement, AVERAGED_MEASUREMENT }, |
| mahphalke |
5:90166c496b01 | 2179 | { "Perform Single Measurement", 'S', perform_4wire_rtd_measurement, SINGLE_MEASUREMENT }, |
| mahphalke |
5:90166c496b01 | 2180 | { "Perform Continuos Measurement",'C', perform_4wire_rtd_measurement, CONTINUOUS_MEASUREMENT }, |
| mahphalke |
0:08ba94bc5a30 | 2181 | }; |
| mahphalke |
0:08ba94bc5a30 | 2182 | |
| mahphalke |
0:08ba94bc5a30 | 2183 | console_menu rtd_4wire_menu = { |
| mahphalke |
0:08ba94bc5a30 | 2184 | .title = "4-Wire RTD Measurement", |
| mahphalke |
0:08ba94bc5a30 | 2185 | .items = rtd_4wire_menu_items, |
| mahphalke |
0:08ba94bc5a30 | 2186 | .itemCount = ARRAY_SIZE(rtd_4wire_menu_items), |
| mahphalke |
0:08ba94bc5a30 | 2187 | .headerItem = rtd_4wire_menu_header, |
| mahphalke |
0:08ba94bc5a30 | 2188 | .footerItem = NULL, |
| mahphalke |
0:08ba94bc5a30 | 2189 | .enableEscapeKey = true |
| mahphalke |
0:08ba94bc5a30 | 2190 | }; |
| mahphalke |
0:08ba94bc5a30 | 2191 | |
| mahphalke |
0:08ba94bc5a30 | 2192 | static console_menu_item ntc_thermistor_menu_items[] = { |
| mahphalke |
0:08ba94bc5a30 | 2193 | { "Enable/Disable NTC1", '1', enable_disable_sensor, SENSOR_CHANNEL0 }, |
| mahphalke |
0:08ba94bc5a30 | 2194 | { "Enable/Disable NTC2", '2', enable_disable_sensor, SENSOR_CHANNEL1 }, |
| mahphalke |
0:08ba94bc5a30 | 2195 | { "Enable/Disable NTC3", '3', enable_disable_sensor, SENSOR_CHANNEL2 }, |
| mahphalke |
0:08ba94bc5a30 | 2196 | { "Enable/Disable NTC4", '4', enable_disable_sensor, SENSOR_CHANNEL3 }, |
| mahphalke |
0:08ba94bc5a30 | 2197 | #if defined(AD7124_8) |
| mahphalke |
0:08ba94bc5a30 | 2198 | { "Enable/Disable NTC5", '5', enable_disable_sensor, SENSOR_CHANNEL4 }, |
| mahphalke |
0:08ba94bc5a30 | 2199 | { "Enable/Disable NTC6", '6', enable_disable_sensor, SENSOR_CHANNEL5 }, |
| mahphalke |
0:08ba94bc5a30 | 2200 | { "Enable/Disable NTC7", '7', enable_disable_sensor, SENSOR_CHANNEL6 }, |
| mahphalke |
0:08ba94bc5a30 | 2201 | { "Enable/Disable NTC8", '8', enable_disable_sensor, SENSOR_CHANNEL7 }, |
| mahphalke |
0:08ba94bc5a30 | 2202 | #endif |
| mahphalke |
0:08ba94bc5a30 | 2203 | { " " }, |
| mahphalke |
5:90166c496b01 | 2204 | { "Perform Averaged Measurement", 'A', perform_ntc_thermistor_measurement, AVERAGED_MEASUREMENT }, |
| mahphalke |
5:90166c496b01 | 2205 | { "Perform Single Measurement", 'S', perform_ntc_thermistor_measurement, SINGLE_MEASUREMENT }, |
| mahphalke |
5:90166c496b01 | 2206 | { "Perform Continuos Measurement", 'C', perform_ntc_thermistor_measurement, CONTINUOUS_MEASUREMENT }, |
| mahphalke |
0:08ba94bc5a30 | 2207 | }; |
| mahphalke |
0:08ba94bc5a30 | 2208 | |
| mahphalke |
0:08ba94bc5a30 | 2209 | console_menu ntc_thermistor_menu = { |
| mahphalke |
0:08ba94bc5a30 | 2210 | .title = "NTC Thermistor Measurement", |
| mahphalke |
0:08ba94bc5a30 | 2211 | .items = ntc_thermistor_menu_items, |
| mahphalke |
0:08ba94bc5a30 | 2212 | .itemCount = ARRAY_SIZE(ntc_thermistor_menu_items), |
| mahphalke |
0:08ba94bc5a30 | 2213 | .headerItem = ntc_thermistor_menu_header, |
| mahphalke |
0:08ba94bc5a30 | 2214 | .footerItem = NULL, |
| mahphalke |
0:08ba94bc5a30 | 2215 | .enableEscapeKey = true |
| mahphalke |
0:08ba94bc5a30 | 2216 | }; |
| mahphalke |
0:08ba94bc5a30 | 2217 | |
| mahphalke |
0:08ba94bc5a30 | 2218 | static console_menu_item thermocouple_menu_items[] = { |
| mahphalke |
0:08ba94bc5a30 | 2219 | { "Enable/Disable TC1", '1', enable_disable_sensor, SENSOR_CHANNEL0 }, |
| mahphalke |
0:08ba94bc5a30 | 2220 | { "Enable/Disable TC2", '2', enable_disable_sensor, SENSOR_CHANNEL1 }, |
| mahphalke |
0:08ba94bc5a30 | 2221 | #if defined(AD7124_8) |
| mahphalke |
0:08ba94bc5a30 | 2222 | { "Enable/Disable TC3", '3', enable_disable_sensor, SENSOR_CHANNEL2 }, |
| mahphalke |
0:08ba94bc5a30 | 2223 | { "Enable/Disable TC4", '4', enable_disable_sensor, SENSOR_CHANNEL3 }, |
| mahphalke |
0:08ba94bc5a30 | 2224 | { "Enable/Disable TC5", '5', enable_disable_sensor, SENSOR_CHANNEL4 }, |
| mahphalke |
0:08ba94bc5a30 | 2225 | { "Enable/Disable TC6", '6', enable_disable_sensor, SENSOR_CHANNEL5 }, |
| mahphalke |
0:08ba94bc5a30 | 2226 | #endif |
| mahphalke |
0:08ba94bc5a30 | 2227 | { " " }, |
| mahphalke |
0:08ba94bc5a30 | 2228 | { "Select CJC (PT100 4-wire RTD)", '7', select_cjc_sensor, PT100_4WIRE_RTD }, |
| mahphalke |
0:08ba94bc5a30 | 2229 | { "Select CJC (PTC KY81/110 Thermistor)", '8', select_cjc_sensor, THERMISTOR_PTC_KY81_110 }, |
| mahphalke |
5:90166c496b01 | 2230 | { "Select CJC (PT1000 2-wire RTD)", '9', select_cjc_sensor, PT1000_2WIRE_RTD }, |
| mahphalke |
0:08ba94bc5a30 | 2231 | { " " }, |
| mahphalke |
5:90166c496b01 | 2232 | { "Perform Averaged Measurement", 'A', perform_thermocouple_measurement, AVERAGED_MEASUREMENT }, |
| mahphalke |
5:90166c496b01 | 2233 | { "Perform Single Measurement", 'S', perform_thermocouple_measurement, SINGLE_MEASUREMENT }, |
| mahphalke |
5:90166c496b01 | 2234 | { "Perform Continuos Measurement",'C', perform_thermocouple_measurement, CONTINUOUS_MEASUREMENT }, |
| mahphalke |
0:08ba94bc5a30 | 2235 | }; |
| mahphalke |
0:08ba94bc5a30 | 2236 | |
| mahphalke |
0:08ba94bc5a30 | 2237 | console_menu thermocouple_menu = { |
| mahphalke |
0:08ba94bc5a30 | 2238 | .title = "Thermocouple Measurement", |
| mahphalke |
0:08ba94bc5a30 | 2239 | .items = thermocouple_menu_items, |
| mahphalke |
0:08ba94bc5a30 | 2240 | .itemCount = ARRAY_SIZE(thermocouple_menu_items), |
| mahphalke |
0:08ba94bc5a30 | 2241 | .headerItem = thermocouple_menu_header, |
| mahphalke |
0:08ba94bc5a30 | 2242 | .footerItem = NULL, |
| mahphalke |
0:08ba94bc5a30 | 2243 | .enableEscapeKey = true |
| mahphalke |
0:08ba94bc5a30 | 2244 | }; |
| mahphalke |
0:08ba94bc5a30 | 2245 | |
| mahphalke |
0:08ba94bc5a30 | 2246 | static console_menu_item adc_calibration_menu_items[] = { |
| mahphalke |
0:08ba94bc5a30 | 2247 | { "Perform Internal Calibration", 'I', perform_adc_calibration, INTERNAL_CALIBRATION }, |
| mahphalke |
0:08ba94bc5a30 | 2248 | { "Perform System Calibration", 'S', perform_adc_calibration, SYSTEM_CALIBRATION }, |
| mahphalke |
0:08ba94bc5a30 | 2249 | }; |
| mahphalke |
0:08ba94bc5a30 | 2250 | |
| mahphalke |
0:08ba94bc5a30 | 2251 | console_menu adc_calibration_menu = { |
| mahphalke |
0:08ba94bc5a30 | 2252 | .title = "AD7124 Calibration", |
| mahphalke |
0:08ba94bc5a30 | 2253 | .items = adc_calibration_menu_items, |
| mahphalke |
0:08ba94bc5a30 | 2254 | .itemCount = ARRAY_SIZE(adc_calibration_menu_items), |
| mahphalke |
0:08ba94bc5a30 | 2255 | .headerItem = adc_calibration_menu_header, |
| mahphalke |
0:08ba94bc5a30 | 2256 | .footerItem = NULL, |
| mahphalke |
0:08ba94bc5a30 | 2257 | .enableEscapeKey = true |
| mahphalke |
0:08ba94bc5a30 | 2258 | }; |
| mahphalke |
0:08ba94bc5a30 | 2259 | |
| mahphalke |
0:08ba94bc5a30 | 2260 | /* |
| mahphalke |
0:08ba94bc5a30 | 2261 | * Definition of the Main Menu Items and menu itself |
| mahphalke |
0:08ba94bc5a30 | 2262 | */ |
| mahphalke |
0:08ba94bc5a30 | 2263 | static console_menu_item main_menu_items[] = { |
| mahphalke |
0:08ba94bc5a30 | 2264 | {"2-Wire RTD", 'A', display_2wire_rtd_menu }, |
| mahphalke |
0:08ba94bc5a30 | 2265 | {"3-Wire RTD", 'B', display_3wire_rtd_menu }, |
| mahphalke |
0:08ba94bc5a30 | 2266 | {"4-Wire RTD", 'C', display_4wire_rtd_menu }, |
| mahphalke |
0:08ba94bc5a30 | 2267 | {"Thermocouple", 'D', display_thermocouple_menu }, |
| mahphalke |
0:08ba94bc5a30 | 2268 | {"Thermistor", 'E', display_ntc_thermistor_menu }, |
| mahphalke |
0:08ba94bc5a30 | 2269 | {"Calibrate ADC", 'F', display_adc_calibration_menu }, |
| mahphalke |
5:90166c496b01 | 2270 | { " " }, |
| mahphalke |
5:90166c496b01 | 2271 | {"Reset Config", 'R', reset_device_config, AD7124_CONFIG_RESET }, |
| mahphalke |
0:08ba94bc5a30 | 2272 | }; |
| mahphalke |
0:08ba94bc5a30 | 2273 | |
| mahphalke |
0:08ba94bc5a30 | 2274 | console_menu ad7124_main_menu = { |
| mahphalke |
0:08ba94bc5a30 | 2275 | .title = "AD7124 Sensor Measurement Menu", |
| mahphalke |
0:08ba94bc5a30 | 2276 | .items = main_menu_items, |
| mahphalke |
0:08ba94bc5a30 | 2277 | .itemCount = ARRAY_SIZE(main_menu_items), |
| mahphalke |
0:08ba94bc5a30 | 2278 | .headerItem = main_menu_header, |
| mahphalke |
0:08ba94bc5a30 | 2279 | .footerItem = NULL, |
| mahphalke |
0:08ba94bc5a30 | 2280 | .enableEscapeKey = false |
| mahphalke |
0:08ba94bc5a30 | 2281 | }; |