ADuC7124 Timer1 drifts when sampling ADC

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
    }
}

  • Hi Shane,

    Can you please attach the full keil project as a zip file?

    It will save us time in creating the project and having to implement the main and PinToggle and whatever else is needed to get it to compile and running.

    Regards,

    Alex

  • Hi There!

    Thanks for the quick response.  Here is a quick summary of my objective: sample an ADC channel at 25KHz and later change to 4 channels with sampling rate of 125KHz.

    Initially, I thought about using a 25KHz (40us) timer to control the sampling rate with the assumption that the sampling time is much shorter than 40us.  However, I found out that just the sampling of ADC took around 40-50us.  I played with the ADCCON bits 12:10 and 9:8 but didn’t see any changes to the sampling time.

    I attached 2 projects for your reference:

    1.      Using ADC interrupt to start the next sampling to see how long it would take to do 1 sample

    2.      Using 25KHz timer interrupt to control the sampling rate

    I appreciate your help!

    Shane

  • Hello,

    We resolved our issue and just want to let you know.  Thanks!

    Shane

  • 0
    •  Analog Employees 
    on Aug 2, 2018 3:38 PM
    This question has been assumed as answered either offline via email or with a multi-part answer. This question has now been closed out. If you have an inquiry related to this topic please post a new question in the applicable product forum.

    Thank you,
    EZ Admin