I have created an ADuC7124 project using KEIL uVision to sample an ADC channel at 25KHz. First, I used Timer1, a GPIO pin, and oscilloscope to confirm the timer is running at 25KHz. However, when I added the ADC code, the timer seems to slow down slightly to ~18KHz. When I comment out the ADC code, the timer goes back to 25KHz. Can someone please tell me what's causing this? My code snippit is below:
#define IRQ_BIT_TIMER1 0x00000008
#define IRQ_BIT_ADC 0x00000100
volatile U16 adc_val = 0;
void ConfigTimer1(void)
{
// configure timer 0
IRQCLR = IRQ_BIT_TIMER1; // Timer1 IRQ
IRQ = InterruptIRQHndlr; // Specify Interrupt Service Rountine
T1LD = 100;
T1CON = 0x00E0; // clock/1; binary; 32.768 clock
IRQEN |= IRQ_BIT_TIMER1; // Timer0 IRQ
}
void InterruptIRQHndlr(void)
{
// Timer1 IRQ
if ((IRQSTA & IRQ_BIT_TIMER1) != 0)
{
PinToggle();
ADCCP = ADC1;
ADCCON = 0x04E3; // fADC/2; enable start conv; enable ADCbusy; normal mode; single conv
T1CLRI = 0x0; // Clear the interrupt
}
// ADC IRQ
if ((IRQSTA & IRQ_BIT_ADC) != 0)
{
adc_val = ADCDAT >> 16;
// place holder to process data
}
}