AnsweredAssumed Answered

ADC Analog Watchdog

Question asked by Rygel.Troy1818 on Feb 22, 2014
Latest reply on Feb 23, 2014 by Rygel.Troy1818
Hi All,

I have noticed that there are not much information in this forum regarding the subject.

(stm32f4):

0. Configure GPIO for ADC (PC0 - ADC channel 10)
  GPIO_InitTypeDef  GPIO_InitStructure;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOC, &GPIO_InitStructure);

1. Activate IRQ
  NVIC_InitTypeDef NVIC_InitStructure;
  NVIC_InitStructure.NVIC_IRQChannel = ADC_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE);

2. Configure ADC
  ADC_InitTypeDef   ADC_init_structure;
  ADC_init_structure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_init_structure.ADC_Resolution = ADC_Resolution_12b;
  ADC_init_structure.ADC_ContinuousConvMode = ENABLE;
  ADC_init_structure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
  ADC_init_structure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
  ADC_init_structure.ADC_NbrOfConversion = 1;
  ADC_init_structure.ADC_ScanConvMode = DISABLE;
  ADC_Init(ADC1, &ADC_init_structure);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_480Cycles);

3. Configure AWD
  ADC_AnalogWatchdogSingleChannelConfig(ADC1, ADC_Channel_10);
  ADC_AnalogWatchdogThresholdsConfig(ADC1, 400, 0);
  ADC_AnalogWatchdogCmd(ADC1, ADC_AnalogWatchdog_SingleRegEnable);

4. Activate ADC
  ADC_Cmd(ADC1, ENABLE);

5. Set up IRQ function (everytime )
  void ADC_IRQHandler(void)
  {
    if (ADC_GetITStatus(ADC1, ADC_IT_AWD))
    {
      ADC_ClearITPendingBit(ADC1, ADC_IT_AWD);
    }
  }

So every time the analog input pin gets a higher value than 400 the interrupt will fire.

Is the configuration/statement correct above?

Regards,
/rygelxvi

Outcomes