see last commit
This commit is contained in:
		@@ -140,14 +140,12 @@ static float calculate_standard_deviation(float *values, uint32_t count, float m
 | 
			
		||||
	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;
 | 
			
		||||
	float min_val = FLT_MAX;
 | 
			
		||||
	float max_val = -FLT_MAX;
 | 
			
		||||
	uint32_t i;
 | 
			
		||||
 | 
			
		||||
	if (!flag || !mem_array || !mu || !max_dev)
 | 
			
		||||
	if (!flag || !mem_array || !mu || !std_dev)
 | 
			
		||||
		return -1000;
 | 
			
		||||
 | 
			
		||||
	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 */
 | 
			
		||||
	*mu = calculate_mean(mem_array, count);
 | 
			
		||||
	*max_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;
 | 
			
		||||
	*std_dev = calculate_standard_deviation(mem_array, count, *mu);
 | 
			
		||||
 | 
			
		||||
ret_free_mem:
 | 
			
		||||
	free(mem_array);
 | 
			
		||||
@@ -245,7 +234,7 @@ shellmatta_retCode_t calibration_sequence_shell_cmd(shellmatta_handle_t shell, c
 | 
			
		||||
			ret_val = SHELLMATTA_BUSY;
 | 
			
		||||
			cal_state = CAL_MEAS_RES1;
 | 
			
		||||
		} 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);
 | 
			
		||||
			if (error_occured) {
 | 
			
		||||
				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;
 | 
			
		||||
			cal_state = CAL_MEAS_RES2;
 | 
			
		||||
		} 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);
 | 
			
		||||
			if (error_occured) {
 | 
			
		||||
				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;
 | 
			
		||||
				cal_state = CAL_START;
 | 
			
		||||
 | 
			
		||||
				if (dev > CALIBRATION_MAX_PEAK_PEAK_NOISE_OHM ||
 | 
			
		||||
				    dev2 > CALIBRATION_MAX_PEAK_PEAK_NOISE_OHM) {
 | 
			
		||||
				if (dev > CALIBRATION_MAX_NOISE_OHM ||
 | 
			
		||||
				    dev2 > CALIBRATION_MAX_NOISE_OHM) {
 | 
			
		||||
					shellmatta_printf(shell, "Calibration failed! Too much noise. Check your hardware.\r\n");
 | 
			
		||||
					break;
 | 
			
		||||
				}
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,7 @@
 | 
			
		||||
#ifndef __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 <shellmatta.h>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user