Add fast moving average filter for faster startup
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user