see last commit

This commit is contained in:
Mario Hüttel 2020-11-01 20:58:32 +01:00
parent 1166477a6c
commit 8ff276e30d
2 changed files with 8 additions and 19 deletions

View File

@ -140,14 +140,12 @@ static float calculate_standard_deviation(float *values, uint32_t count, float m
return res; return res;
} }
static int calibration_poll_data_acquisition(float *mem_array, uint32_t count, volatile int *flag, float *mu, float *max_dev) static int calibration_poll_data_acquisition(float *mem_array, uint32_t count, volatile int *flag, float *mu, float *std_dev)
{ {
int ret_val = 0; int ret_val = 0;
float min_val = FLT_MAX;
float max_val = -FLT_MAX;
uint32_t i; uint32_t i;
if (!flag || !mem_array || !mu || !max_dev) if (!flag || !mem_array || !mu || !std_dev)
return -1000; return -1000;
if (*flag == 0) { if (*flag == 0) {
@ -166,16 +164,7 @@ static int calibration_poll_data_acquisition(float *mem_array, uint32_t count, v
/* Do not compute std-deviation. Too imprecise */ /* Do not compute std-deviation. Too imprecise */
*mu = calculate_mean(mem_array, count); *mu = calculate_mean(mem_array, count);
*max_dev = calculate_standard_deviation(mem_array, count, *mu); *std_dev = calculate_standard_deviation(mem_array, count, *mu);
/* Find min and max values of array */
for (i = 0U; i < count; i++) {
min_val = MIN(min_val, mem_array[i]);
max_val = MAX(max_val, mem_array[i]);
}
/* Compute maximum deviation range */
//*max_dev = max_val - min_val;
ret_free_mem: ret_free_mem:
free(mem_array); free(mem_array);
@ -245,7 +234,7 @@ shellmatta_retCode_t calibration_sequence_shell_cmd(shellmatta_handle_t shell, c
ret_val = SHELLMATTA_BUSY; ret_val = SHELLMATTA_BUSY;
cal_state = CAL_MEAS_RES1; cal_state = CAL_MEAS_RES1;
} else if (res == 0) { } else if (res == 0) {
shellmatta_printf(shell, "R=%.2f, Noise peak-peak: %.2f\r\n", mu, dev); shellmatta_printf(shell, "R=%.2f, Std-Dev: %.2f\r\n", mu, dev);
error_occured = safety_controller_get_flags_by_mask(meas_adc_err_mask); error_occured = safety_controller_get_flags_by_mask(meas_adc_err_mask);
if (error_occured) { if (error_occured) {
shellmatta_printf(shell, "Error in resistance measurement"); shellmatta_printf(shell, "Error in resistance measurement");
@ -296,7 +285,7 @@ shellmatta_retCode_t calibration_sequence_shell_cmd(shellmatta_handle_t shell, c
ret_val = SHELLMATTA_BUSY; ret_val = SHELLMATTA_BUSY;
cal_state = CAL_MEAS_RES2; cal_state = CAL_MEAS_RES2;
} else if (res == 0) { } else if (res == 0) {
shellmatta_printf(shell, "R=%.2f, Noise peak-peak: %.2f\r\n", mu2, dev2); shellmatta_printf(shell, "R=%.2f, Std-Dev: %.2f\r\n", mu2, dev2);
error_occured = safety_controller_get_flags_by_mask(meas_adc_err_mask); error_occured = safety_controller_get_flags_by_mask(meas_adc_err_mask);
if (error_occured) { if (error_occured) {
shellmatta_printf(shell, "Error in resistance measurement"); shellmatta_printf(shell, "Error in resistance measurement");
@ -306,8 +295,8 @@ shellmatta_retCode_t calibration_sequence_shell_cmd(shellmatta_handle_t shell, c
ret_val = SHELLMATTA_OK; ret_val = SHELLMATTA_OK;
cal_state = CAL_START; cal_state = CAL_START;
if (dev > CALIBRATION_MAX_PEAK_PEAK_NOISE_OHM || if (dev > CALIBRATION_MAX_NOISE_OHM ||
dev2 > CALIBRATION_MAX_PEAK_PEAK_NOISE_OHM) { dev2 > CALIBRATION_MAX_NOISE_OHM) {
shellmatta_printf(shell, "Calibration failed! Too much noise. Check your hardware.\r\n"); shellmatta_printf(shell, "Calibration failed! Too much noise. Check your hardware.\r\n");
break; break;
} }

View File

@ -21,7 +21,7 @@
#ifndef __CALIBRATION_H__ #ifndef __CALIBRATION_H__
#define __CALIBRATION_H__ #define __CALIBRATION_H__
#define CALIBRATION_MAX_PEAK_PEAK_NOISE_OHM 8.0f #define CALIBRATION_MAX_NOISE_OHM 3.0f
#include <stdint.h> #include <stdint.h>
#include <shellmatta.h> #include <shellmatta.h>