cancel
Showing results for 
Search instead for 
Did you mean: 

ADC Interrupt problem

lima
Associate II
Posted on August 10, 2005 at 13:58

ADC Interrupt problem

3 REPLIES 3
lima
Associate II
Posted on August 10, 2005 at 11:53

Hi,

I'm using since few days an STR710FZ2-EVAL with Keil compiler, and i'm testing some simple applications. I try to use ADC in different mode, but I have a problem with ADC interrupt.

I use ADC in ''manual'' mode with the following code

while(1){

....

ADC12_Init();

ADC12_PrescalerConfig(50);

ADC12_ModeConfig(ADC12_SINGLE);

ADC12_ChannelSelect(ADC12_CHANNEL0);

ADC12_ConversionStart();

while (!ADC12_FlagStatus (ADC12_DA0));

data = ADC12_ConversionValue(ADC12_CHANNEL0);

ADC12->CSR &= ~ADC12_DA0;

...

}

and it works. I try also the roud robin mode and works too.

I have some problems when i try to use the interrupts. The code in main file is the following:

u16 data=0;

....

ADC12_Init();

ADC12_PrescalerConfig(50);

ADC12_ModeConfig(ADC12_SINGLE);

ADC12_ChannelSelect(ADC12_CHANNEL0);

ADC12_ITConfig(ENABLE);

ADC12_ConversionStart();

EIC_Init();

EIC_IRQChannelConfig(ADC_IRQChannel, ENABLE);

EIC_IRQChannelPriorityConfig(ADC_IRQChannel, 1);

EIC_IRQConfig(ENABLE);

while(1){

//control the value of data

}

and the interrupt routine

extern u16 data;

void ADC12_IRQHandler(void) __arm

{

data = ADC12_ConversionValue(ADC12_CHANNEL0);

ADC12->CSR &= ~ADC12_DA0;

}

but the application not enter in ADC12_IRQHandler, in fact the value of data is always equal to 0.

Someone can help me?

ben2
Associate II
Posted on August 10, 2005 at 13:04

Have not used the ADC part of the chip yet but are you sure the interrupt is not happening, the code looks ok?

You should also declare ''data'' as volatile. I dont know how you are using it, but the compiler may well be optermising it in such a way that it is not updating after the interrupt..

lima
Associate II
Posted on August 10, 2005 at 13:58

Now is OK. The problem is that i write an application to test all the modes of the ADC : ''manual'' & ''interrupt'' mode, single channel & round robin mode, so i define some directive in main file like this :

#define MANUAL_MODE

//#define INTERRUPT_MODE

#define SINGLE_CHANNEL_0

//define ROUND_ROBIN

....

and then i write the code for this directive in main file

#ifdef MANUAL_MODE

.....

#endif

#ifdef INTERRUPT_MODE

.....

#endif

... an so on

then i test the different mode comment some line.

The problem is that i make the same in interrupt routine like this :

extern vu16 datas;

void ADC12_IRQHandler(void) __arm

{

#ifdef MODE_SINGLE_0

datas = ADC12_ConversionValue(ADC12_CHANNEL0);

ADC12->CSR &= ~ADC12_DA0;

#endif

#ifdef MODE_SINGLE_3

datas = ADC12_ConversionValue(ADC12_CHANNEL3);

ADC12->CSR &= ~ADC12_DA3;

#endif

#ifdef MODE_ROUND

datas = ADC12_ConversionValue(ADC12_CHANNEL0);

....

ADC12->CSR = 0;

#endif

}

and i don't know why but this is wrong. In fact if i don't use the directive in interrupt routine the code works.

Moreover i see that is the same if i define a variable as volatile or not.