This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

OMAP L137 Timer ticks or counter



Hello,

I have code already for TIMER 0:12 running with interrupt and I would like to set a separate counter ticks or timer counter that should be independent of interrupts I mean even if I disable interrupts the tick should continue running and output an accurate variable of 1 second.

I am attaching this snippet

static void setup_Timer0 (void)
{
// Set Timer0 as 32 Bit Unchain
CSL_FINST(tmr0Regs->TGCR, TMR_TGCR_TIMMODE, 32BIT_UNCHAIN);

// Remove Timer0 from Reset
CSL_FINST(tmr0Regs->TGCR, TMR_TGCR_TIM12RS, NO_RESET);
CSL_FINST(tmr0Regs->TGCR, TMR_TGCR_TIM34RS, NO_RESET);

// Select Internal Clock for Timer0 (24 MHz)
CSL_FINST(tmr0Regs->TCR, TMR_TCR_CLKSRC12, INTERNAL);
CSL_FINST(tmr0Regs->TCR, TMR_TCR_CLKSRC34, INTERNAL);

// Disable the New Timer Features
CSL_FINST(tmr0Regs->TGCR, TMR_TGCR_PLUSEN, DISABLE);
}/* setup_Timer0 */

static void Timer0_freq (void)
{
// Disable Timer0:12 to Allow for a Reset & Change in Period
CSL_FINST(tmr0Regs->TCR, TMR_TCR_ENAMODE12, DISABLE);
CSL_FINST(tmr0Regs->TCR, TMR_TCR_ENAMODE34, DISABLE);


//Set Timer 0:34 to output a signal clock every 1 sec
CSL_FINST(tmr0Regs->TCR, TMR_TCR_CP34, CLOCK);
CSL_FINST(tmr0Regs->TCR, TMR_TCR_TSTAT34, HIGH);


// Reset the Counter for Timer0:12
CSL_FINST(tmr0Regs->TIM12, TMR_TIM12_TIM12, RESETVAL);
CSL_FINST(tmr0Regs->TIM34, TMR_TIM34_TIM34, RESETVAL);

// load Timer to trigger at 100k
CSL_FINS(tmr0Regs->PRD12, TMR_PRD12_PRD12, (CSL_ASYNC_2_FREQ / 100000) * 1);
CSL_FINS(tmr0Regs->PRD34, TMR_PRD34_PRD34, CSL_ASYNC_2_FREQ );

// Enable Timer0:12 Continuously
CSL_FINST(tmr0Regs->TCR, TMR_TCR_ENAMODE12, EN_CONT);
CSL_FINST(tmr0Regs->TCR, TMR_TCR_ENAMODE34, EN_CONT);
}

and inside main I am trying to read the status bit TSTAT34

main(void)

{

for(;;)

{

   if (CSL_FEXT(tmr0Regs->TCR, TMR_TCR_TSTAT34))

     {  

// do something after one second is elapsed 

     }   

                       else 

                                   {    

                                       // do something else 

                                   }

                               }

         }

the problem is I can't have this working properly. is there any easy way of using Timer0: 34 for counting ticks without setting timer pin TM64P_OUT12 as clock and how I can read this tick or clock pulse and assign it to a variable.

Thank you for the support 

  • Hi Ahmed,

    As per timer functionality , when timer interrupt is disabled, it stops incrementing the tick value and when we enable interrupt again it starts counting the tick value.
    Timer interrupt is called after fixed time period, time period is pre-configurd using PRDn Registers.


    if (CSL_FEXT(tmr0Regs->TCR, TMR_TCR_TSTAT34))


    In TCR register their is no TSTAT34 field. Will you please confirm ?
  • Hi Arvind,

    Thanks for the reply.

    here is a snapshot from my debugger showing TSTAT34 but it is not mentioned on the Doc.

    So I use TSTAT34 field in polling mode to check for 1 second elapsed time.

    I believe it is running independent of the interrupt triggered by Timer 0:12 since the unchained mode is selected and I am using Timer0:34.

    I  also  commented the line   //CSL_FINST(tmr0Regs->TCR, TMR_TCR_TSTAT34, HIGH);  giving that  TSTAT is a Timer status. Drives the value

    of timer output TM64P_OUT12 when it is configured to function as timer output.

    0 TM64P_OUT12 signal is not asserted.
    1 TM64P_OUT12 signal is asserted.

    so I don't need to set it high, I will just wait for TM64P_OUT12 event to update TSTAT status field when Timer reaches PRD34 loaded value. (please confirm)

    One thing I need your help what would be the best approach to poll for one second 

    1. use CP34 as clock with PRD34 =  24000000 or

    2. use CP34 as pulse PRD34 =  24000000

    Thank you for the support