ADC is not working properly in ADuC7021

I’m working on  ADuC 7021 microcontroller. But now I’m stucked with ADC reading. While reading the ADC channel directly it gives the correct count. But if I’m trying to read the ADC count on the timer ISR, some error occurred. Timer 0 (400ms)and timer 1 (50ms)are enabled. But by giving some delay (delay count 1500)on the ADC reading routine, exact value have been obtained. Here what may be the issue?

                Also the temperature obtained by means of the internal temperature is also wrong. Say, for 30c it gives 130c.

Here is the routine.

ADCCON = 0x0624;

unsigned short usGetADCChannel(unsigned char ucChannel)

{

                unsigned short usADCData;

                IRQEN &= ~RTOS_TIMER_BIT;

                IRQEN &= ~GP_TIMER_BIT;

                ADCCP = ucChannel;

                REFCON = 0x01;

                ADCCON |= SWSTART;

                vDelay(1600);

                __nop();

                __nop();

                __nop();

                __nop();

                __nop();

                __nop();

                __nop();

                __nop();

                while((ADCSTA & EOC) == 0);

                ADCCON &= ~SWSTART;

                usADCData = ADCDAT>>16;

                IRQEN |= RTOS_TIMER_BIT;

                IRQEN |= GP_TIMER_BIT;

                return (usADCData);

}

Parents Reply Children
No Data