diff --git a/stm-firmware/adc-meas.c b/stm-firmware/adc-meas.c index 1526457..e4d0fa2 100644 --- a/stm-firmware/adc-meas.c +++ b/stm-firmware/adc-meas.c @@ -303,14 +303,23 @@ void adc_pt1000_disable(void) static inline __attribute__((optimize("O3"))) void adc_pt1000_filter(float adc_prefiltered_value) { + 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); } - pt1000_res_raw_lf = (1.0f - filter_alpha) * pt1000_res_raw_lf + - filter_alpha * ADC_TO_RES(adc_prefiltered_value); + res = ADC_TO_RES(adc_prefiltered_value); + if (ABS(res - pt1000_res_raw_lf) > 20) + alpha = ADC_PT1000_FILTER_WEIGHT_FAST; + else + alpha = filter_alpha; + + pt1000_res_raw_lf = (1.0f - alpha) * pt1000_res_raw_lf + + alpha * res; safety_controller_report_timing(ERR_TIMING_MEAS_ADC); } diff --git a/stm-firmware/include/reflow-controller/adc-meas.h b/stm-firmware/include/reflow-controller/adc-meas.h index 5c07236..073977a 100644 --- a/stm-firmware/include/reflow-controller/adc-meas.h +++ b/stm-firmware/include/reflow-controller/adc-meas.h @@ -38,6 +38,12 @@ */ #define ADC_PT1000_FILTER_WEIGHT 0.005f +/** + * @brief Moving average filter weight used for fast regaulation. This is used when the measured resistance + * is more than 20 Ohms away from the current averaged value. + */ +#define ADC_PT1000_FILTER_WEIGHT_FAST 0.05 + /** * @brief ADC channel number of PT1000 sensor input */ @@ -99,6 +105,8 @@ */ #define ADC_TO_RES(adc) ((float)(adc) / 4096.0f * 2500.0f) +#define RES_TO_ADC(res) ((float)(res) / 2500.0f * 4096.0f) + /** * @brief This function sets up the ADC measurement fo the external PT1000 temperature sensor *