cancel
Showing results for 
Search instead for 
Did you mean: 

External interrupt for trigger ADC

hamed_solar
Associate II
Posted on July 07, 2016 at 10:38

Hi

I use EXTI for trigger ADC for stm32f

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
/* DMA1 Channel1 Configuration ----------------------------------------------*/
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADC3ConvertedValue;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 300;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
/* Enable DMA Stream Half / Transfer Complete interrupt */
//DMA_ITConfig(DMA1_Channel1, DMA_IT_TC | DMA_IT_HT, ENABLE);
/* Enable DMA1 channel1 */
DMA_Cmd(DMA1_Channel1, ENABLE);
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
/* ADC1 configuration ------------------------------------------------------*/
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConv =ADC_ExternalTrigConv_Ext_IT11_TIM8_TRGO ;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 1;
ADC_Init(ADC1, &ADC_InitStructure);
//////////////////////////////////////////////////////////////////////////////////////////////////
 ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 1, ADC_SampleTime_1Cycles5); //c2 ==for voltage /* Regular discontinuous mode channel number configuration */
 ADC_DiscModeChannelCountConfig(ADC1, 1);
 /* Enable regular discontinuous mode */
 ADC_DiscModeCmd(ADC1, ENABLE);
 /* Enable ADC1 external trigger conversion */ 
 ADC_ExternalTrigConvCmd(ADC1, ENABLE);
 
 /* Enable ADC1 DMA */
 ADC_DMACmd(ADC1, ENABLE);
 
 
 /* Enable ADC1 */
 ADC_Cmd(ADC1, ENABLE);
 /* Enable ADC1 reset calibration register */ 
 ADC_ResetCalibration(ADC1);
 /* Check the end of ADC1 reset calibration register */
 while(ADC_GetResetCalibrationStatus(ADC1));
 /* Start ADC1 calibration */
 ADC_StartCalibration(ADC1);
 /* Check the end of ADC1 calibration */
 while(ADC_GetCalibrationStatus(ADC1));

//////////////////////////////////////////////////////////////////////////////////////////////////

The below code is for configuring EXTI.

void EXTI11_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable GPIOA clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
/* Configure PA.00 pin as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Enable AFIO clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
/* Connect EXTI0 Line to PB.11 pin */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource11);
/* Configure EXTI0 line */
EXTI_InitStructure.EXTI_Line = EXTI_Line11;
EXTI_InitStructure.EXTI_Mode =EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; 
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
// /* Enable and set EXTI0 Interrupt to the lowest priority */
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}

It works. When I connect the

EXTI_Line11

to the square wave the ADC convert the analog input and put them into the ADC3ConvertedValue. I adjust EXTI for rising and falling edge. I want to calculate data between two rising and falling edge of the external interrupt . But I dont know which section of the ADC3ConvertedValue is linked to the time of converting between two rising and falling edge of external interrupt? 0690X00000605QDQAY.png Regards
This discussion is locked. Please start a new topic to ask your question.
1 REPLY 1
Posted on July 08, 2016 at 00:15

What exactly do you want to measure? The maximum/peak of the triangular waveform? You might perhaps want to build an (analogue) peak detector (basically a diode and a capacitor) and measure the voltage on that, perhaps at the falling edge; you can also discharge the capacitor actively after the voltage is measured. To work out the details is upon you though.

JW