cancel
Showing results for 
Search instead for 
Did you mean: 

ADC Analog Watchdog

troy1818
Senior
Posted on February 22, 2014 at 13:39

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
1 REPLY 1
troy1818
Senior
Posted on February 23, 2014 at 16:09

There are also a common config that perhaps needs to be addressed (that I missed before):

ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;

ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;

ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;

ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_20Cycles;

ADC_CommonInit(&ADC_CommonInitStructure);

I found a good presentation for ADC that I have attached.

Regards,

/rygelxvi

________________

Attachments :

Lecture_4-handout.pdf : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I1MU&d=%2Fa%2F0X0000000bls%2FetFIUQ4Z5RtmUVXqbZX925pJ8Fx2gQItw4XyBSZO6hk&asPdf=false