Issue #24: Make UNSTABLE flag only go away, if the PT1000 value stays within the stable region for a given amount of samples
This commit is contained in:
		@@ -214,7 +214,7 @@ void adc_pt1000_get_resistance_calibration(float *offset, float *sensitivity_dev
 | 
			
		||||
static inline float adc_pt1000_apply_calibration(float raw_resistance)
 | 
			
		||||
{
 | 
			
		||||
	if (calibration_active)
 | 
			
		||||
        return (raw_resistance - pt1000_offset) * (1.0f + pt1000_sens_dev);
 | 
			
		||||
		return (raw_resistance - pt1000_offset) * (1.0f + pt1000_sens_dev);
 | 
			
		||||
	else
 | 
			
		||||
		return raw_resistance;
 | 
			
		||||
 | 
			
		||||
@@ -304,9 +304,11 @@ static inline __attribute__((optimize("O3"))) void adc_pt1000_filter(float adc_p
 | 
			
		||||
	float alpha;
 | 
			
		||||
	float res;
 | 
			
		||||
	static uint8_t old_state = 0;
 | 
			
		||||
	static uint32_t stable_sample_counter = 0;
 | 
			
		||||
 | 
			
		||||
	res = ADC_TO_RES(adc_prefiltered_value);
 | 
			
		||||
	if (ABS(res - pt1000_res_raw_lf) >= ADC_PT1000_FILTER_UNSTABLE_DIFF) {
 | 
			
		||||
		stable_sample_counter = 0;
 | 
			
		||||
		alpha = ADC_PT1000_FILTER_WEIGHT_FAST;
 | 
			
		||||
		if (old_state != 1) {
 | 
			
		||||
			safety_controller_report_error_with_key(ERR_FLAG_MEAS_ADC_UNSTABLE, MEAS_ADC_SAFETY_FLAG_KEY);
 | 
			
		||||
@@ -315,8 +317,11 @@ static inline __attribute__((optimize("O3"))) void adc_pt1000_filter(float adc_p
 | 
			
		||||
	} else {
 | 
			
		||||
		alpha = filter_alpha;
 | 
			
		||||
		if (old_state != 2) {
 | 
			
		||||
			safety_controller_ack_flag_with_key(ERR_FLAG_MEAS_ADC_UNSTABLE, MEAS_ADC_SAFETY_FLAG_KEY);
 | 
			
		||||
			old_state = 2;
 | 
			
		||||
			stable_sample_counter++;
 | 
			
		||||
			if (stable_sample_counter >= ADC_PT1000_FILTER_STABLE_SAMPLE_COUNT) {
 | 
			
		||||
				safety_controller_ack_flag_with_key(ERR_FLAG_MEAS_ADC_UNSTABLE, MEAS_ADC_SAFETY_FLAG_KEY);
 | 
			
		||||
				old_state = 2;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -49,6 +49,12 @@
 | 
			
		||||
 */
 | 
			
		||||
#define ADC_PT1000_FILTER_UNSTABLE_DIFF 10
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Sample count, the moving average filter has to be within @ref ADC_PT1000_FILTER_UNSTABLE_DIFF for the filter
 | 
			
		||||
 * to be considered stable
 | 
			
		||||
 */
 | 
			
		||||
#define ADC_PT1000_FILTER_STABLE_SAMPLE_COUNT 200
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief ADC channel number of PT1000 sensor input
 | 
			
		||||
 */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user