cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with ADC interruptsin continuous mode

eng_shenawy
Associate II
Posted on November 30, 2014 at 20:08

Hi , I have a problem in the program after enabling the ADC interrupt , The processor doesn't do anything after starting ADC_READ

Here is a simple program which reads data from ADC in continuous mode and when the conversion ends it calls the ADC interrupt handler to send these data to USART and be displayed on the terminal and All of this works fine and the data are displayed continuously. When I tried to add lines of code after the function TM_ADC_Read ,These lines are not executed (for example in this example I am setting pin A6 and Pin A4 , but they are not set!)

void EnableADCInterrupts(void )
{
NVIC_InitTypeDef nvicStructure;
nvicStructure.NVIC_IRQChannel = ADC_IRQn ;
nvicStructure.NVIC_IRQChannelPreemptionPriority = 2;
nvicStructure.NVIC_IRQChannelSubPriority = 2;
/*There are no other interrupts enabled in my code , However I gave*/ /*those the value 2 and I tried to give them all value to 15 and the problem exists*/
nvicStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvicStructure);
}
int main(void) {
/* Initialize system */
SystemInit();
/* Initialize Delay library */
TM_DELAY_Init();
/* Initialize USART1, 115200baud, TX: PB6 */
TM_USART_Init(USART1, TM_USART_PinsPack_2, 115200);
InitializeGP();
EnableADCInterrupts(); /*After calling this function problems happened, see downwards*/
/* Initialize ADC1 on channel 5, this is pin PA5 */
TM_ADC_Init(ADC1, ADC_Channel_5);
TM_USART_Puts(USART1 , ''USART IS OKAY \n \r'');
sprintf(str, ''%4d: \n\r'', TM_ADC_Read(ADC1, ADC_Channel_5));
/* Put to USART *
TM_USART_Puts(USART1, str);
/**These two functions don't execute after I called EnableAdcInterrupts**/
GPIO_WriteBit(GPIOD , GPIO_Pin_5 , Bit_SET);
 GPIO_WriteBit(GPIOD , GPIO_Pin_4 , Bit_SET);
/* Little delay */
Delayms(100);
while (1);
}
void ADC_IRQHandler (void)
{
if (ADC_GetITStatus( ADC1,ADC_IT_EOC) != RESET)
{
/* Send reading to USART6*/
sprintf(str, ''%4d: \n\r'', TM_ADC_Read(ADC1, ADC_Channel_5));
/* Put to USART */
TM_USART_Puts(USART1, str);
}
ADC_ClearITPendingBit( ADC1, ADC_IT_EOC);
}
void InitializeGP(void)
{
 GPIO_InitTypeDef gpioStructureD,gpioStructureA,gpioStructureB;
 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
 GPIO_StructInit(&gpioStructureD);
 
 gpioStructureD.GPIO_Pin=0x0030; // GPIO_Pin_5|GPIO_Pin_4;
 gpioStructureD.GPIO_Mode = GPIO_Mode_OUT;
 GPIO_Init(GPIOD, &gpioStructureD);

The PA6 and PA4 pins are not set , however when I disable the interrupt through the function EnableAdcInterrupt , they work fine . would Any one tell me why this problem happens?
3 REPLIES 3
eng_shenawy
Associate II
Posted on November 30, 2014 at 20:11 my ADC configuration is the following

ADC_InitDef.ADC_ContinuousConvMode = ENABLE;
ADC_InitDef.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitDef.ADC_ExternalTrigConv = DISABLE;
ADC_InitDef.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitDef.ADC_NbrOfConversion = 1;
ADC_InitDef.ADC_ScanConvMode = DISABLE;
ADC_CommonInitDef.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_CommonInitDef.ADC_Mode = ADC_Mode_Independent;
ADC_CommonInitDef.ADC_Prescaler = ADC_Prescaler_Div4;
ADC_CommonInitDef.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_8Cycles;
ADC_CommonInit(&ADC_CommonInitDef);
ADC_ContinuousModeCmd(ADCx, ENABLE );
/* Initialize ADC */
ADC_Init(ADCx, &ADC_InitDef);
/* Enable ADC */
ADC_Cmd(ADCx, ENABLE);
ADC_ITConfig(ADCx,ADC_IT_EOC,ENABLE) ;

frankmeyer9
Associate II
Posted on December 01, 2014 at 09:04

Have you tried to calculate/measure the time you need to send the string through the UART in your ADC interrupt routine, and compared it with the ADC cycle time in continuous mode ?

You get an overflow, and so cycling endless in the ADC interrupt.

eng_shenawy
Associate II
Posted on December 02, 2014 at 13:48

Thank you very much. That was actually the problem

when I deleted the USART part and increased the two sampling delay to 20 cycles .

The code worked fine.