Add fast moving average filter for faster startup

This commit is contained in:
Mario Hüttel 2021-01-09 22:26:31 +01:00
parent bbfcd429fe
commit 69ff13a991
2 changed files with 19 additions and 2 deletions

View File

@ -303,14 +303,23 @@ void adc_pt1000_disable(void)
static inline __attribute__((optimize("O3"))) void adc_pt1000_filter(float adc_prefiltered_value) static inline __attribute__((optimize("O3"))) void adc_pt1000_filter(float adc_prefiltered_value)
{ {
float alpha;
float res;
if (filter_startup_cnt > 0) { if (filter_startup_cnt > 0) {
filter_startup_cnt--; filter_startup_cnt--;
if (filter_startup_cnt == 0) if (filter_startup_cnt == 0)
safety_controller_ack_flag_with_key(ERR_FLAG_MEAS_ADC_UNSTABLE, MEAS_ADC_SAFETY_FLAG_KEY); 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 + res = ADC_TO_RES(adc_prefiltered_value);
filter_alpha * 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); safety_controller_report_timing(ERR_TIMING_MEAS_ADC);
} }

View File

@ -38,6 +38,12 @@
*/ */
#define ADC_PT1000_FILTER_WEIGHT 0.005f #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 * @brief ADC channel number of PT1000 sensor input
*/ */
@ -99,6 +105,8 @@
*/ */
#define ADC_TO_RES(adc) ((float)(adc) / 4096.0f * 2500.0f) #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 * @brief This function sets up the ADC measurement fo the external PT1000 temperature sensor
* *