From 20a65fd7f9d670446edc44dbe731e45c7b9936f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Tue, 26 Jan 2021 21:46:44 +0100 Subject: [PATCH] Issue #24: Implement new handling for Unstable flag. * Unstable flag will now be set, whenever the output of the moving average filter differs more than 10 Ohms from the measured prefilterd input. --- stm-firmware/adc-meas.c | 22 ++++++++++--------- .../include/reflow-controller/adc-meas.h | 11 +++++----- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/stm-firmware/adc-meas.c b/stm-firmware/adc-meas.c index aa33e3e..3aef6b9 100644 --- a/stm-firmware/adc-meas.c +++ b/stm-firmware/adc-meas.c @@ -45,7 +45,6 @@ static float IN_SECTION(.ccm.bss) filter_alpha; static volatile float IN_SECTION(.ccm.bss) pt1000_res_raw_lf; static volatile int * volatile streaming_flag_ptr; -static uint32_t IN_SECTION(.ccm.bss) filter_startup_cnt; static volatile float IN_SECTION(.ccm.bss) adc_pt1000_raw_reading_hf; static volatile uint16_t dma_sample_buffer[ADC_PT1000_DMA_AVG_SAMPLES]; static volatile uint32_t IN_SECTION(.ccm.bss) adc_watchdog_counter; @@ -188,7 +187,6 @@ void adc_pt1000_set_moving_average_filter_param(float alpha) { filter_alpha = alpha; safety_controller_report_error_with_key(ERR_FLAG_MEAS_ADC_UNSTABLE, MEAS_ADC_SAFETY_FLAG_KEY); - filter_startup_cnt = ADC_FILTER_STARTUP_CYCLES; } void adc_pt1000_set_resistance_calibration(float offset, float sensitivity_deviation, bool active) @@ -305,18 +303,22 @@ static inline __attribute__((optimize("O3"))) void adc_pt1000_filter(float adc_p { float alpha; float res; - - if (filter_startup_cnt > 0) { - filter_startup_cnt--; - if (filter_startup_cnt == 0) - safety_controller_ack_flag_with_key(ERR_FLAG_MEAS_ADC_UNSTABLE, MEAS_ADC_SAFETY_FLAG_KEY); - } + static uint8_t old_state = 0; res = ADC_TO_RES(adc_prefiltered_value); - if (ABS(res - pt1000_res_raw_lf) > 20) + if (ABS(res - pt1000_res_raw_lf) >= ADC_PT1000_FILTER_UNSTABLE_DIFF) { alpha = ADC_PT1000_FILTER_WEIGHT_FAST; - else + if (old_state != 1) { + safety_controller_report_error_with_key(ERR_FLAG_MEAS_ADC_UNSTABLE, MEAS_ADC_SAFETY_FLAG_KEY); + old_state = 1; + } + } 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; + } + } pt1000_res_raw_lf = (1.0f - alpha) * pt1000_res_raw_lf + alpha * res; diff --git a/stm-firmware/include/reflow-controller/adc-meas.h b/stm-firmware/include/reflow-controller/adc-meas.h index 073977a..9e96b81 100644 --- a/stm-firmware/include/reflow-controller/adc-meas.h +++ b/stm-firmware/include/reflow-controller/adc-meas.h @@ -44,6 +44,11 @@ */ #define ADC_PT1000_FILTER_WEIGHT_FAST 0.05 +/** + * @brief Difference in Ohm between filter input and output that determines if the filter is stable or unstable. + */ +#define ADC_PT1000_FILTER_UNSTABLE_DIFF 10 + /** * @brief ADC channel number of PT1000 sensor input */ @@ -64,12 +69,6 @@ */ #define ADC_PT1000_PIN 2U -/** - * @brief The cycle count the moving average filter is labeled 'instable' after startup of the measurement or changing - * the alpha value @ref ADC_PT1000_FILTER_WEIGHT - */ -#define ADC_FILTER_STARTUP_CYCLES 800U - /** * @brief The delay value programmed into the sample timer */