AnsweredAssumed Answered

Analog watchdog not working the second time.

Question asked by fantana.brian on Mar 28, 2012
Latest reply on Mar 28, 2012 by fantana.brian
I'm having some difficulty with getting the analog watchdog to work a second time. I am able to use it the first time correctly, but I think I might be missing something either when I disable it, or re-enable it because as soon as I start up the AWD the second time, the interrupt fires immediately even though the current ADC value no where near the AWD range I am specifying.

Startup code (Most of the time I do a single ADC read so we default to that):
01./* Initialize ADC defaults */
02.adc_init_def.ADC_Mode               = ADC_Mode_Independent;
03.adc_init_def.ADC_ScanConvMode       = DISABLE;
04.adc_init_def.ADC_ContinuousConvMode = DISABLE;
05.adc_init_def.ADC_ExternalTrigConv   = ADC_ExternalTrigConv_None
06.adc_init_def.ADC_DataAlign          = ADC_DataAlign_Right;
07.adc_init_def.ADC_NbrOfChannel       = 1;
08. 
09./* Reset the ADC */
10.ADC_DeInit(adc);
11. 
12./* Init the ADC */
13.ADC_Init(adc, &adc_init_def);
14. 
15./* Enable the ADC */
16.ADC_Cmd(adc, ENABLE);
17. 
18./* Calibrate the ADC */
19.ADC_ResetCalibration(adc);
20.while(ADC_GetResetCalibrationStatus(adc)) { }
21.ADC_StartCalibration(adc);
22.while(ADC_GetCalibrationStatus(adc)) { }


When I call the AWD function to set it up, I do the following:
01./* Set the mode to continous */
02.adc_init_def.ADC_ContinuousConvMode = ENABLE;
03. 
04./* Initialize the ADC again to enable continuous conversion mode */
05.ADC_DeInit(adc);
06.ADC_Init(adc, &adc_init_def);
07. 
08./* Configure the channel */
09.ADC_RegularChannelConfig(adc, adc_channel, 1, ADC_SampleTime_41Cycles5);
10. 
11./* Set the watchdog thresholds */
12.ADC_ClearFlag(adc, ADC_FLAG_AWD);
13.ADC_AnalogWatchdogThresholdsConfig(adc, current_pos, future_pos);
14. 
15./* Set the configuration for the watchdog channel */
16.ADC_AnalogWatchdogSingleChannelConfig(adc, adc_channel);
17.ADC_AnalogWatchdogCmd(adc, ADC_AnalogWatchdog_SingleRegEnable);
18. 
19./* Enable the analog watchdog interrupt then enable the interrupts */
20.ADC_ITConfig(adc, ADC_IT_AWD, ENABLE);
21. 
22./* Turn on the ADC if its not already on */
23.ADC_Cmd(adc, ENABLE);
24. 
25./* Calibrate the ADC */
26.ADC_ResetCalibration(adc);
27.while(ADC_GetResetCalibrationStatus(adc));
28.ADC_StartCalibration(adc);
29.while(ADC_GetCalibrationStatus(adc));

And I handle the AWD inside the ISR as follows:
01./* Analog watchdog interrupt */
02.if(ADC_GetITStatus(adc, ADC_IT_AWD) != RESET)
03.{
04.    /* Clear the analog watchdog interrupt flag */
05.    ADC_ClearFlag(adc, ADC_FLAG_AWD);
06.    ADC_ClearITPendingBit(adc, ADC_IT_AWD);
07.    ADC_ITConfig(adc, ADC_IT_AWD, DISABLE);
08. 
09.    /* Call the ISR function */
10.    awd_isr->ISR();
11. 
12.    /* Disable continous conversion mode, and the watchdog status/owner */
13.    adc_init_def.ADC_ContinuousConvMode = DISABLE;
14. 
15.    /* Re-initialize the ADC with continous conversion mode disabled */
16.    ADC_DeInit(adc);
17.    ADC_Init(adc, &adc_init_def);
18.}


Outcomes