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:
Mario Hüttel 2021-01-26 21:59:41 +01:00
parent 20a65fd7f9
commit 4c1797aa24
2 changed files with 14 additions and 3 deletions

View File

@ -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) static inline float adc_pt1000_apply_calibration(float raw_resistance)
{ {
if (calibration_active) if (calibration_active)
return (raw_resistance - pt1000_offset) * (1.0f + pt1000_sens_dev); return (raw_resistance - pt1000_offset) * (1.0f + pt1000_sens_dev);
else else
return raw_resistance; return raw_resistance;
@ -304,9 +304,11 @@ static inline __attribute__((optimize("O3"))) void adc_pt1000_filter(float adc_p
float alpha; float alpha;
float res; float res;
static uint8_t old_state = 0; static uint8_t old_state = 0;
static uint32_t stable_sample_counter = 0;
res = ADC_TO_RES(adc_prefiltered_value); res = ADC_TO_RES(adc_prefiltered_value);
if (ABS(res - pt1000_res_raw_lf) >= ADC_PT1000_FILTER_UNSTABLE_DIFF) { if (ABS(res - pt1000_res_raw_lf) >= ADC_PT1000_FILTER_UNSTABLE_DIFF) {
stable_sample_counter = 0;
alpha = ADC_PT1000_FILTER_WEIGHT_FAST; alpha = ADC_PT1000_FILTER_WEIGHT_FAST;
if (old_state != 1) { if (old_state != 1) {
safety_controller_report_error_with_key(ERR_FLAG_MEAS_ADC_UNSTABLE, MEAS_ADC_SAFETY_FLAG_KEY); 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 { } else {
alpha = filter_alpha; alpha = filter_alpha;
if (old_state != 2) { if (old_state != 2) {
safety_controller_ack_flag_with_key(ERR_FLAG_MEAS_ADC_UNSTABLE, MEAS_ADC_SAFETY_FLAG_KEY); stable_sample_counter++;
old_state = 2; 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;
}
} }
} }

View File

@ -49,6 +49,12 @@
*/ */
#define ADC_PT1000_FILTER_UNSTABLE_DIFF 10 #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 * @brief ADC channel number of PT1000 sensor input
*/ */