Fix ADC Watchdog handling

This commit is contained in:
Mario Hüttel 2020-04-26 19:53:06 +02:00
parent 85fe0f6749
commit 2d3b61550b
2 changed files with 7 additions and 8 deletions

View File

@ -36,6 +36,7 @@ static volatile int * volatile streaming_flag_ptr = NULL;
static uint32_t filter_startup_cnt; static uint32_t filter_startup_cnt;
static volatile float adc_pt1000_raw_reading_hf; static volatile float adc_pt1000_raw_reading_hf;
static volatile uint16_t dma_sample_buffer[ADC_PT1000_DMA_AVG_SAMPLES]; static volatile uint16_t dma_sample_buffer[ADC_PT1000_DMA_AVG_SAMPLES];
static volatile uint32_t adc_watchdog_counter = 0UL;
volatile float * volatile stream_buffer = NULL; volatile float * volatile stream_buffer = NULL;
volatile uint32_t stream_count; volatile uint32_t stream_count;
@ -322,7 +323,6 @@ static inline __attribute__((optimize("O3"))) float adc_pt1000_dma_avg_pre_filte
void ADC_IRQHandler(void) void ADC_IRQHandler(void)
{ {
uint32_t adc1_sr; uint32_t adc1_sr;
static uint32_t watchdog_errors;
adc1_sr = ADC1->SR; adc1_sr = ADC1->SR;
@ -331,16 +331,12 @@ void ADC_IRQHandler(void)
pt1000_error |= ADC_PT1000_OVERFLOW; pt1000_error |= ADC_PT1000_OVERFLOW;
/* Disable ADC in case of overrrun*/ /* Disable ADC in case of overrrun*/
adc_pt1000_disable(); adc_pt1000_disable();
if (!(adc1_sr & ADC_SR_AWD)) {
watchdog_errors = 0;
}
} }
if (adc1_sr & ADC_SR_AWD) { if (adc1_sr & ADC_SR_AWD) {
ADC1->SR &= ~ADC_SR_AWD; ADC1->SR &= ~ADC_SR_AWD;
watchdog_errors++; adc_watchdog_counter++;
if (watchdog_errors >= ADC_PT1000_WATCHDOG_SAMPLE_COUNT) if (adc_watchdog_counter >= ADC_PT1000_WATCHDOG_SAMPLE_COUNT)
pt1000_error |= ADC_PT1000_WATCHDOG_ERROR; pt1000_error |= ADC_PT1000_WATCHDOG_ERROR;
} }
} }
@ -376,6 +372,9 @@ void DMA2_Stream0_IRQHandler()
if (streaming_flag_ptr) if (streaming_flag_ptr)
append_stream_buffer(adc_val); append_stream_buffer(adc_val);
if (adc_watchdog_counter > 0UL)
adc_watchdog_counter--;
/* Call moving average filter */ /* Call moving average filter */
adc_pt1000_filter(adc_val); adc_pt1000_filter(adc_val);
} }

View File

@ -63,7 +63,7 @@
* @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) * @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 * in order to produce a watchdog error
*/ */
#define ADC_PT1000_WATCHDOG_SAMPLE_COUNT 50U #define ADC_PT1000_WATCHDOG_SAMPLE_COUNT 25U
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)}; 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)};