diff --git a/stm-firmware/adc-meas.c b/stm-firmware/adc-meas.c index 1699efb..2323291 100644 --- a/stm-firmware/adc-meas.c +++ b/stm-firmware/adc-meas.c @@ -322,6 +322,7 @@ static inline __attribute__((optimize("O3"))) float adc_pt1000_dma_avg_pre_filte void ADC_IRQHandler(void) { uint32_t adc1_sr; + static uint32_t watchdog_errors; adc1_sr = ADC1->SR; @@ -330,11 +331,17 @@ void ADC_IRQHandler(void) pt1000_error |= ADC_PT1000_OVERFLOW; /* Disable ADC in case of overrrun*/ adc_pt1000_disable(); + + if (!(adc1_sr & ADC_SR_AWD)) { + watchdog_errors = 0; + } } if (adc1_sr & ADC_SR_AWD) { ADC1->SR &= ~ADC_SR_AWD; - pt1000_error |= ADC_PT1000_WATCHDOG_ERROR; + watchdog_errors++; + if (watchdog_errors >= ADC_PT1000_WATCHDOG_SAMPLE_COUNT) + pt1000_error |= ADC_PT1000_WATCHDOG_ERROR; } } diff --git a/stm-firmware/include/reflow-controller/adc-meas.h b/stm-firmware/include/reflow-controller/adc-meas.h index b850962..d9b0a31 100644 --- a/stm-firmware/include/reflow-controller/adc-meas.h +++ b/stm-firmware/include/reflow-controller/adc-meas.h @@ -59,6 +59,12 @@ */ #define ADC_PT1000_UPPER_WATCHDOG 4000U +/** + * @brief Number of ADC samples the value has to be outside the Watchdog limit (@ref ADC_PT1000_UPPER_WATCHDOG and @ref ADC_PT1000_LOWER_WATCHDOG) + * in order to produce a watchdog error + */ +#define ADC_PT1000_WATCHDOG_SAMPLE_COUNT 10U + enum adc_pt1000_error {ADC_PT1000_NO_ERR= 0, ADC_PT1000_WATCHDOG_ERROR=(1UL<<0), ADC_PT1000_OVERFLOW=(1UL<<1), ADC_PT1000_INACTIVE = (1UL<<2)}; /**