AnsweredAssumed Answered

Analog watchdog is not firing more than once

Question asked by Patrick Morwald on Jan 19, 2018
Latest reply on Jan 22, 2018 by waclawek.jan



i want to use the analog watchdog (ADC) on my STM32F4. I have an analog sensor attached to channel 1 of ADC1. I dont want to use CPU to make constant function calls to ADC, even with ADC interrupt mode i have to handle every "conversion finished" interrupt even if the level of the input doesnt change. 


In my situation, the analog sensor is a door switch with most of the time doesnt change. So i want a solution that needs no CPU interference whatsoever as long as the analog level doesnt change. So i wanted to use the analog watchdog and define a guard band between the voltage level for "door open" and "door closed". When switching between those states, the voltage would traverse the boundaries of the guard band and fire the interrupt of the analog watchdog.


So far is the plan. I implemented a prototype, but the analog watchdog only fires once when starting the application. I am trying to pinpoint the problem but have no idea why its not firing again. See my code attached. 


/* ADC1 init function */
static void MX_ADC1_Init(void)

ADC_ChannelConfTypeDef sConfig;

/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.ScanConvMode = DISABLE;
hadc1.Init.ContinuousConvMode = ENABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
_Error_Handler(__FILE__, __LINE__);

/**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
sConfig.Channel = ADC_CHANNEL_11;
sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
_Error_Handler(__FILE__, __LINE__);

/** Configure the analog watchdog witch fires an interrupt when a certain
* guard band (defined by LowThreshold and HighThreshold) is left.
ADC_AnalogWDGConfTypeDef aWDGConfig;

aWDGConfig.WatchdogNumber = 0; /**< Reserved for future use, can be set to 0 */
aWDGConfig.Channel = ADC_CHANNEL_11;
aWDGConfig.HighThreshold = 3500; //TODO: Use defines
aWDGConfig.LowThreshold = 2500; //TODO: Use defines
aWDGConfig.ITMode = ENABLE;

if (HAL_ADC_AnalogWDGConfig(&hadc1, &aWDGConfig) != HAL_OK)
_Error_Handler(__FILE__, __LINE__);