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:
parent
20a65fd7f9
commit
4c1797aa24
@ -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,10 +317,13 @@ 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) {
|
||||||
|
stable_sample_counter++;
|
||||||
|
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);
|
safety_controller_ack_flag_with_key(ERR_FLAG_MEAS_ADC_UNSTABLE, MEAS_ADC_SAFETY_FLAG_KEY);
|
||||||
old_state = 2;
|
old_state = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pt1000_res_raw_lf = (1.0f - alpha) * pt1000_res_raw_lf +
|
pt1000_res_raw_lf = (1.0f - alpha) * pt1000_res_raw_lf +
|
||||||
alpha * res;
|
alpha * res;
|
||||||
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user