cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0XX analog watchdog config

guillaume2
Associate II
Posted on March 11, 2014 at 16:50

Hello everybody,

I'am trying to use analog watchdog on STM32F051K4 and I face some problems. 

I want to measure a pulse on PA0 (ADC_IN0) of 100us wide with an 1V amplitude above 0.5V offset. There is no example on this function for the F0. I tried to adapt F1 example without success yet.

Here is the relevant code:

//threshold values for watchdog

#define ADC_THR_H 0x708 //1V

#define ADC_THR_L 0x5DC //0.88V

 /* GPIOB GPIO A Periph clock enable */

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOA, ENABLE);

 

/* ADC1 Periph clock enable */

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

/*configure PA0 for ADC input*/

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

/*Enable interrupt on ADC Analog watchdog*/

  NVIC_InitStructure.NVIC_IRQChannel = ADC1_COMP_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

  

 ADC_ClearITPendingBit(ADC1,ADC_IT_AWD);

 ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE);

* Initialize ADC defaults */

  /* ADC1 Configuration *******************************************************/

  /* ADCs DeInit */  

  ADC_DeInit(ADC1);

  

  /* Configure the ADC1 with analog watchdog*/

  ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;

  ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

  ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;    

  ADC_InitStructure.ADC_ExternalTrigConv = ADC_AnalogWatchdog_Channel_0;

  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

  //ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward;

  //ADC_ChannelConfig(ADC1,ADC_Channel_0,ADC_SampleTime_1_5Cycles);

 ADC_Init(ADC1, &ADC_InitStructure); 

//Configure analog watchdog

  ADC_AnalogWatchdogSingleChannelConfig(ADC1, ADC_Channel_0);

  ADC_AnalogWatchdogThresholdsConfig(ADC1,ADC_THR_H,ADC_THR_L);

  ADC_AnalogWatchdogCmd(ADC1,ENABLE);

  ADC_AnalogWatchdogSingleChannelCmd(ADC1,ENABLE);

  ADC_StartOfConversion(ADC1);

  ADC_Cmd(ADC1,ENABLE);

/*and my interrupt routine:*/

void ADC1_COMP_IRQHandler(void)

{

   if (ADC_GetITStatus(ADC1, ADC_IT_AWD))

    {

      ADC_ClearFlag(ADC1, ADC_FLAG_AWD);

ADC_ClearITPendingBit(ADC1, ADC_IT_AWD);

    

if(ADC_threshold==0) ADC_threshold=1;

}

}

In my main program, I check ADC_threshold value to light a led and I reset it.

If somebody could help me, thanks.

2 REPLIES 2
Posted on March 11, 2014 at 16:57

There is no example on this function for the F0.

STM32F0xx_StdPeriph_Lib_V1.0.0\Project\STM32F0xx_StdPeriph_Examples\COMP\COMP_AnalogWatchdog\main.c

STM32F0xx_StdPeriph_Lib_V1.0.0\Project\STM32F0xx_StdPeriph_Examples\ADC\ADC1_AnalogWatchdog\main.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
guillaume2
Associate II
Posted on March 11, 2014 at 17:07

Sorry for this,

I looked in STM32F0-Discovery_FW_V1.0.0 only, I forgot STM32F0xx_StdPeriph_Lib_V1.3.1. and google didn't find anything about it.

I check this, thanks