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
Diff: app/ad7124_console_app.c
- Revision:
- 6:622270f7d476
- Parent:
- 5:90166c496b01
- Child:
- 7:ef6fffc246a6
diff -r 90166c496b01 -r 622270f7d476 app/ad7124_console_app.c
--- a/app/ad7124_console_app.c Fri Mar 19 12:33:00 2021 +0530
+++ b/app/ad7124_console_app.c Tue Mar 23 20:29:51 2021 +0530
@@ -140,8 +140,9 @@
/* ADC raw data for n samples */
static int32_t n_sample_data[NUM_OF_SENSOR_CHANNELS][MAX_ADC_SAMPLES];
-/* RTD calibraed IOUT values */
-static float rtd_calib_iout[2][MAX_ADC_SAMPLES]; // Iout0 + Iout1
+/* RTD calibraed IOUT values for n samples */
+static float rtd_calib_iout0[MAX_RTD_SENSORS][MAX_ADC_SAMPLES];
+static float rtd_calib_iout1[MAX_RTD_SENSORS][MAX_ADC_SAMPLES];
/* CJC sensor ADC raw data for n samples */
static int32_t n_cjc_sample_data[MAX_THERMOCOUPLE_SENSORS][MAX_ADC_SAMPLES];
@@ -152,17 +153,9 @@
'Y'
};
-/* Tab counting strings */
-static const char *tab_cnt_str[NUM_OF_SENSOR_CHANNELS] = {
- "\t",
- "\t\t",
- "\t\t\t",
- "\t\t\t\t",
- "\t\t\t\t\t",
- "\t\t\t\t\t\t",
- "\t\t\t\t\t\t\t",
- "\t\t\t\t\t\t\t\t"
-};
+/* For storing decimal value(s) in character form */
+static char decimal_eqv_str[50] = "";
+static char decimal_eqv_str_arr[50 * NUM_OF_SENSOR_CHANNELS] = "";
/* Sensor enable status */
static bool sensor_enable_status[NUM_OF_SENSOR_CHANNELS] = {
@@ -590,7 +583,6 @@
uint8_t rtd_gain;
uint16_t sample_cnt;
bool continue_measurement = false;
- uint8_t tab_cnt = 0;
float temperature;
if (measurement_type == CONTINUOUS_MEASUREMENT) {
@@ -604,12 +596,10 @@
for (uint8_t chn = SENSOR_CHANNEL0;
chn < max_supported_sensors[rtd_config_id]; chn++) {
if (sensor_enable_status[chn]) {
- printf(VT100_MOVE_UP_1_LINE "%s RTD%d" EOL,
- tab_cnt_str[tab_cnt++], chn + 1);
+ printf("\tRTD%d ", chn+1);
}
}
- tab_cnt = 0;
- printf("\t-----------------------------------------------" EOL EOL);
+ printf(EOL "\t-----------------------------------------------" EOL EOL);
/* Perform additional configs for 3-wire RTD measurement */
if (rtd_config_id == AD7124_CONFIG_3WIRE_RTD) {
@@ -649,23 +639,24 @@
chn++) {
if (sensor_enable_status[chn]) {
temperature = get_rtd_temperature(n_sample_data[chn][0], rtd_gain);
- printf(VT100_MOVE_UP_1_LINE "%s %.3f" EOL, tab_cnt_str[tab_cnt++],
- temperature);
+ sprintf(decimal_eqv_str, "%.4f ", temperature);
+ strcat(decimal_eqv_str_arr, decimal_eqv_str);
}
}
- tab_cnt = 0;
+ printf("\t%s" EOL EOL, decimal_eqv_str_arr);
+ decimal_eqv_str_arr[0] = '\0';
} else {
for (sample_cnt = 0; sample_cnt < MAX_ADC_SAMPLES; sample_cnt++) {
for (uint8_t chn = SENSOR_CHANNEL0; chn < max_supported_sensors[rtd_config_id];
chn++) {
if (sensor_enable_status[chn]) {
temperature = get_rtd_temperature(n_sample_data[chn][sample_cnt], rtd_gain);
- printf(VT100_MOVE_UP_1_LINE "%s %.3f" EOL, tab_cnt_str[tab_cnt++],
- temperature);
+ sprintf(decimal_eqv_str, "%.4f ", temperature);
+ strcat(decimal_eqv_str_arr, decimal_eqv_str);
}
}
- printf(EOL);
- tab_cnt = 0;
+ printf("\t%s" EOL EOL, decimal_eqv_str_arr);
+ decimal_eqv_str_arr[0] = '\0';
}
}
}
@@ -746,7 +737,6 @@
bool multiple_3wire_rtd_enabled = false;
uint16_t sample_cnt;
bool continue_measurement = false;
- uint8_t tab_cnt = 0;
const uint8_t rtd_3wire_iout0_source[] = {
RTD1_3WIRE_IOUT0, RTD2_3WIRE_IOUT0, RTD3_3WIRE_IOUT0, RTD4_3WIRE_IOUT0
@@ -790,12 +780,10 @@
for (uint8_t chn = SENSOR_CHANNEL0;
chn < max_supported_sensors[AD7124_CONFIG_3WIRE_RTD]; chn++) {
if (sensor_enable_status[chn]) {
- printf(VT100_MOVE_UP_1_LINE "%s RTD%d" EOL,
- tab_cnt_str[tab_cnt++], chn + 1);
+ printf("\tRTD%d ", chn + 1);
}
}
- tab_cnt = 0;
- printf("\t-----------------------------------------------" EOL EOL);
+ printf(EOL "\t-----------------------------------------------" EOL EOL);
do {
/* Calibrate, Sample and Read all enabled RTD channels in sequence */
@@ -831,7 +819,7 @@
RTD_3WIRE_REF_MEASUREMENT_CHN, n_sample_data[RTD_3WIRE_REF_MEASUREMENT_CHN][0]);
/* Calculate equivalent Iout0 current flowing through Rref resistance */
- rtd_calib_iout[0][0] = voltage / get_rtd_rref();
+ rtd_calib_iout0[chn][0] = voltage / get_rtd_rref();
} else {
for (sample_cnt = 0; sample_cnt < MAX_ADC_SAMPLES; sample_cnt++) {
/* Get the equivalent ADC voltage */
@@ -840,7 +828,7 @@
n_sample_data[RTD_3WIRE_REF_MEASUREMENT_CHN][sample_cnt]);
/* Calculate equivalent Iout0 current flowing through Rref resistance */
- rtd_calib_iout[0][sample_cnt] = voltage / get_rtd_rref();
+ rtd_calib_iout0[chn][sample_cnt] = voltage / get_rtd_rref();
}
}
@@ -874,7 +862,7 @@
n_sample_data[RTD_3WIRE_REF_MEASUREMENT_CHN][0]);
/* Calculate equivalent Iout1 current flowing through Rref resistance */
- rtd_calib_iout[1][0] = voltage / get_rtd_rref();
+ rtd_calib_iout1[chn][0] = voltage / get_rtd_rref();
} else {
for (sample_cnt = 0; sample_cnt < MAX_ADC_SAMPLES; sample_cnt++) {
/* Get the equivalent ADC voltage */
@@ -883,7 +871,7 @@
n_sample_data[RTD_3WIRE_REF_MEASUREMENT_CHN][sample_cnt]);
/* Calculate equivalent Iout1 current flowing through Rref resistance */
- rtd_calib_iout[1][sample_cnt] = voltage / get_rtd_rref();
+ rtd_calib_iout1[chn][sample_cnt] = voltage / get_rtd_rref();
}
}
@@ -995,16 +983,17 @@
chn++) {
if (sensor_enable_status[chn]) {
if (rtd_3wire_calibration_type == MEASURING_EXCITATION_CURRENT) {
- store_rtd_calibrated_iout_ratio((rtd_calib_iout[1][0] /
- rtd_calib_iout[0][0]), true);
+ store_rtd_calibrated_iout_ratio((rtd_calib_iout0[chn][0] /
+ rtd_calib_iout0[chn][0]), true);
}
temperature = get_rtd_temperature(n_sample_data[chn][0], MULTI_3WIRE_RTD_GAIN);
- printf(VT100_MOVE_UP_1_LINE "%s %.3f" EOL,
- tab_cnt_str[tab_cnt++], temperature);
+ sprintf(decimal_eqv_str, "%.4f ", temperature);
+ strcat(decimal_eqv_str_arr, decimal_eqv_str);
}
}
- tab_cnt = 0;
+ printf("\t%s" EOL EOL, decimal_eqv_str_arr);
+ decimal_eqv_str_arr[0] = '\0';
} else {
for (sample_cnt = 0; sample_cnt < MAX_ADC_SAMPLES; sample_cnt++) {
for (uint8_t chn = SENSOR_CHANNEL0;
@@ -1012,18 +1001,18 @@
chn++) {
if (sensor_enable_status[chn]) {
if (rtd_3wire_calibration_type == MEASURING_EXCITATION_CURRENT) {
- store_rtd_calibrated_iout_ratio((rtd_calib_iout[1][sample_cnt] /
- rtd_calib_iout[0][sample_cnt]), true);
+ store_rtd_calibrated_iout_ratio((rtd_calib_iout0[chn][sample_cnt] /
+ rtd_calib_iout1[chn][sample_cnt]), true);
}
temperature = get_rtd_temperature(n_sample_data[chn][sample_cnt],
MULTI_3WIRE_RTD_GAIN);
- printf(VT100_MOVE_UP_1_LINE "%s %.3f" EOL,
- tab_cnt_str[tab_cnt++], temperature);
+ sprintf(decimal_eqv_str, "%.4f ", temperature);
+ strcat(decimal_eqv_str_arr, decimal_eqv_str);
}
}
- printf(EOL);
- tab_cnt = 0;
+ printf("\t%s" EOL EOL, decimal_eqv_str_arr);
+ decimal_eqv_str_arr[0] = '\0';
}
}
}
@@ -1053,7 +1042,6 @@
bool adc_error = false;
uint16_t sample_cnt;
bool continue_measurement = false;
- uint8_t tab_cnt = 0;
float temperature;
if (measurement_type == CONTINUOUS_MEASUREMENT) {
@@ -1067,12 +1055,10 @@
for (uint8_t chn = SENSOR_CHANNEL0;
chn < max_supported_sensors[AD7124_CONFIG_THERMISTOR]; chn++) {
if (sensor_enable_status[chn]) {
- printf(VT100_MOVE_UP_1_LINE "%s NTC%d" EOL,
- tab_cnt_str[tab_cnt++], chn + 1);
+ printf("\tNTC%d ", chn + 1);
}
}
- tab_cnt = 0;
- printf("\t-----------------------------------------------" EOL EOL);
+ printf(EOL "\t-----------------------------------------------" EOL EOL);
do {
/* Sample and Read all enabled NTC channels in sequence */
@@ -1099,11 +1085,12 @@
chn++) {
if (sensor_enable_status[chn]) {
temperature = get_ntc_thermistor_temperature(n_sample_data[chn][0]);
- printf(VT100_MOVE_UP_1_LINE "%s %.3f" EOL,
- tab_cnt_str[tab_cnt++], temperature);
+ sprintf(decimal_eqv_str, "%.4f ", temperature);
+ strcat(decimal_eqv_str_arr, decimal_eqv_str);
}
}
- tab_cnt = 0;
+ printf("\t%s" EOL EOL, decimal_eqv_str_arr);
+ decimal_eqv_str_arr[0] = '\0';
} else {
for (sample_cnt = 0; sample_cnt < MAX_ADC_SAMPLES; sample_cnt++) {
for (uint8_t chn = SENSOR_CHANNEL0;
@@ -1111,12 +1098,12 @@
chn++) {
if (sensor_enable_status[chn]) {
temperature = get_ntc_thermistor_temperature(n_sample_data[chn][sample_cnt]);
- printf(VT100_MOVE_UP_1_LINE "%s %.3f" EOL,
- tab_cnt_str[tab_cnt++], temperature);
+ sprintf(decimal_eqv_str, "%.4f ", temperature);
+ strcat(decimal_eqv_str_arr, decimal_eqv_str);
}
}
- printf(EOL);
- tab_cnt = 0;
+ printf("\t%s" EOL EOL, decimal_eqv_str_arr);
+ decimal_eqv_str_arr[0] = '\0';
}
}
}
@@ -1222,7 +1209,6 @@
bool continue_measurement = false;
float tc_temperature;
float cjc_temperature;
- uint8_t tab_cnt = 0;
#if defined(AD7124_8)
const int32_t tc_vbias_input[] = {
@@ -1247,16 +1233,12 @@
for (uint8_t chn = SENSOR_CHANNEL0;
chn < max_supported_sensors[AD7124_CONFIG_THERMOCOUPLE]; chn++) {
if (sensor_enable_status[chn]) {
- if (tab_cnt == 0) {
- printf("\t TC%d CJC" EOL, chn+1);
- } else {
- printf(VT100_MOVE_UP_1_LINE "%s%s TC%d CJC" EOL,
- tab_cnt_str[tab_cnt], tab_cnt_str[tab_cnt-1], chn+1);
- }
- tab_cnt++;
+ sprintf(decimal_eqv_str, "TC%d CJC ", chn+1);
+ strcat(decimal_eqv_str_arr, decimal_eqv_str);
}
}
- tab_cnt = 0;
+ printf("\t%s" EOL EOL, decimal_eqv_str_arr);
+ decimal_eqv_str_arr[0] = '\0';
printf("\t----------------------------------------------------------------------------------------------"
EOL EOL);
@@ -1322,16 +1304,12 @@
tc_temperature = get_tc_temperature(n_sample_data[chn][0],
n_cjc_sample_data[chn][0], current_cjc_sensor,
&cjc_temperature);
- if (tab_cnt == 0) {
- printf("\t %.3f %.3f" EOL, tc_temperature, cjc_temperature);
- } else {
- printf(VT100_MOVE_UP_1_LINE "%s%s %.3f %.3f" EOL,
- tab_cnt_str[tab_cnt], tab_cnt_str[tab_cnt-1], tc_temperature, cjc_temperature);
- }
- tab_cnt++;
+ sprintf(decimal_eqv_str, "%.4f %.4f ", tc_temperature, cjc_temperature);
+ strcat(decimal_eqv_str_arr, decimal_eqv_str);
}
}
- tab_cnt = 0;
+ printf("\t%s" EOL EOL, decimal_eqv_str_arr);
+ decimal_eqv_str_arr[0] = '\0';
} else {
for (sample_cnt = 0; sample_cnt < MAX_ADC_SAMPLES; sample_cnt++) {
for (uint8_t chn = SENSOR_CHANNEL0;
@@ -1341,17 +1319,12 @@
tc_temperature = get_tc_temperature(n_sample_data[chn][sample_cnt],
n_cjc_sample_data[chn][sample_cnt], current_cjc_sensor,
&cjc_temperature);
- if (tab_cnt == 0) {
- printf("\t %.3f %.3f" EOL, tc_temperature, cjc_temperature);
- } else {
- printf(VT100_MOVE_UP_1_LINE "%s%s %.3f %.3f" EOL,
- tab_cnt_str[tab_cnt], tab_cnt_str[tab_cnt-1], tc_temperature, cjc_temperature);
- }
- tab_cnt++;
+ sprintf(decimal_eqv_str, "%.4f %.4f ", tc_temperature, cjc_temperature);
+ strcat(decimal_eqv_str_arr, decimal_eqv_str);
}
}
- printf(EOL);
- tab_cnt = 0;
+ printf("\t%s" EOL EOL, decimal_eqv_str_arr);
+ decimal_eqv_str_arr[0] = '\0';
}
}
}