cancel
Showing results for 
Search instead for 
Did you mean: 

Analog window watchdog

JAN R
Associate III
Posted on October 05, 2017 at 10:36

Hi Guys,

I have STM32L071 and I want to use analog window watchdog for detecting if voltage on channel 2 is bellow my threshold. I use it and it works really nice.

I use this settings for ADC:

/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)

*/

hadc.Instance = ADC1;

hadc.Init.OversamplingMode = DISABLE;

hadc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;

hadc.Init.Resolution = ADC_RESOLUTION_12B;

hadc.Init.SamplingTime = ADC_SAMPLETIME_39CYCLES_5;

hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;

hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;

hadc.Init.ContinuousConvMode = ENABLE;

hadc.Init.DiscontinuousConvMode = DISABLE;

hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;

hadc.Init.DMAContinuousRequests = ENABLE;

hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;

hadc.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;

hadc.Init.LowPowerAutoWait = DISABLE;

hadc.Init.LowPowerFrequencyMode = DISABLE;

hadc.Init.LowPowerAutoPowerOff = DISABLE;

if (HAL_ADC_Init(&hadc) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

/**Configure the analog watchdog

*/

AnalogWDGConfig.WatchdogMode = ADC_ANALOGWATCHDOG_SINGLE_REG;

AnalogWDGConfig.Channel = ADC_CHANNEL_2;

AnalogWDGConfig.ITMode = ENABLE;

AnalogWDGConfig.HighThreshold = 4095;

AnalogWDGConfig.LowThreshold = 2808;

if (HAL_ADC_AnalogWDGConfig(&hadc, &AnalogWDGConfig) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

And whenever the voltage is bellow the level threshold onchannel 2 so interrupt occurs.

But now I want to use also classical measuring on channel 1.

I want to the analog watchdog works still independenty on CPU performance. And in some time I want to read voltage on channel 1.  But it does not work with nalog watchdog. How to combine this 2 methods?

0690X0000060483QAA.jpg

#awd #adc #analog-watchdog
2 REPLIES 2
AvaTar
Lead
Posted on October 05, 2017 at 11:23

The 'old' SPL used to come with simple ADC examples that configured one ADC channel in conjunction with DMA, without any interrupt (neither ADC nor DMA).

This examples just came by to read the conversion resultss occasionally from the DMA target address.

I don't have a L071, not sure if the method would interfere with the watchdog interrupt.

Alternatively, you can use a second ADC channel, externally connecting them.

John Craven
Senior
Posted on October 05, 2017 at 17:44

I start using the AWD to detect peaks. The AWD interrupt fires continuously while the peak exists and you are sampling. Its the way it is.

Take a look at this thread:

https://community.st.com/0D50X00009XkYXZSA3