AnsweredAssumed Answered

Help configure interrupts for WIDTH_CAP timer mode for ADSP21489

Question asked by klhett on May 6, 2012
Latest reply on May 8, 2012 by Harshit.Gaharwar

I am trying to use timer 1 in WIDTH_CAP mode to measure the period of a external clock source.

The problem I'm having is that the interrupt service routine is only called when the timer overflows and it appears that the timer has not accumulated any time in the period register.

 

Here is the code I'm using to configure the timer:

void WidthCaptureTimer_init(void)

{

     // init variables

          g_timerInterrupt = 0;

          g_MeasuredClockPeriod = 0;

 

          // route the timer 1 interrupt to a handler function

          interrupts(SIG_GPTMR1, width_capture_timer_interrupt);

 

          // configure IO lines

          SRU(DAI_PB17_O, TIMER1_I); // route the clock line into TIMER1

 

          // configure timer1 to be in width capture mode

          *pTM1CTL = TIMODEW | // width capture

                     PRDCNT |  // count period

                     PULSE |   // start counting on rising edge

                                 IRQEN;    // enable interrupt

                                

          // issue two NOP's to avoid synchronizer latency issue

          // see HRM path 16-14 for details

          asm("nop;");

          asm("nop;");                                

                                

          // Enable timer 1

          *pTM1STAT = TIM1EN;

}

 

Here is the ISR code:

void width_capture_timer_interrupt(int signal)

{

          g_timerInterrupt = 1;

 

          // record the last measured period

          g_MeasuredClockPeriod = *pTM1PRD;

 

          // Clear the sticky interrupt bits and always re-enable

          // the timers because the timers will be automatically

          // disabled if they overflow.

          // Clear the bits by writting a 1 to the overflow bits

          *pTM1STAT = 0x0433; // keep timer 1 enabled, write 1's to clear overflow bits

 

    // issue two NOP's to avoid synchronizer latency issue

          // see HRM path 16-14 for details

          asm("nop;");

          asm("nop;");

}


I have verified that the clock signal is applied to the clock input pin(PB17) but the ISR code is only called once when TIMER1 COUNT overflows.

After the ISR is called, if I halt the processor and inspect the timer register with the debugger I find that:

TIMER STATUS = 0x00000C00 - I think this means that timer 1 is enabled

TIMER 1 CONTROL = 0x0000001E - I think this means that timer1 is configured for period capture mode and the IRQ is enabled

TIMER 1 COUNT = 1 - after the interrupt the count value stays at 1 and no longer increments

TIMER 1 PERIOD = 0 - the period value is 0 during the period when the count register is incrementing but before the overflow interrupt occurs

 

I'm wondering if I need to do something else to route the DPI line into the timer input or if there are extra steps to get the TIMER 1 IRQ interrupt enabled.

 

Please let me know if you see a defect in the code above, or if you have other debug suggestions to help discover the root cause of this issue.

 

Thanks,

Kristopher

Outcomes