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.

Cannot set timer period

Anonymous
Anonymous

Hi All,

I would like to ask a question on timer period register.

 

I have set TGCR.TIMMODE register to let the Timer0 run at 64-bit mode.  The PRD12 and PRD34 bit, however, revert to 0x00000000 every time after I am attempting to set them.

 

 

What should I do to enable these period counters?


 

Sincerely,

Zheng

 

  • Hi Zheng,

    The timer period registers can not be changed after the timer is enabled (running).

    Please see below for an example to configure the timer.

    Hope this helps.

    Thanks,

    Tai

     

     

     

    #include <tmr_util.h>

    extern volatile Uint32 Tmr_12_Count[],Tmr_34_Count[];
    extern volatile Uint32 TmrErrorCount;

    #define TMR_NUM 1

    Uint32 tmr_doTest()
    {
        Uint32 test_result = 0;
        Uint32 intPeriod    = 0x00000400;
        Uint32 testDuration = 0x0000F000;
        Uint32 intExpected = testDuration / intPeriod;

        tmrReset(TMR_NUM);
        TMR_intcInit(TMR_INT_BOTH);

        // Set PERIOD registers
        TMR_REGS[TMR_NUM]->PRD12 = intPeriod;
        TMR_REGS[TMR_NUM]->PRD34 = testDuration;

        // Set up DUAL 32-bit
        CSL_FINST(TMR_REGS[TMR_NUM]->TGCR, TIMER64P_TGCR_TIMMODE, DUAL);
        CSL_FINST(TMR_REGS[TMR_NUM]->TGCR, TIMER64P_TGCR_TIM34RS, NOTINRESET);
        CSL_FINST(TMR_REGS[TMR_NUM]->TGCR, TIMER64P_TGCR_TIM12RS, NOTINRESET);

        if( Tmr_12_Count[TMR_NUM] != 0 ) {
          test_result++;
        }
        if( Tmr_34_Count[TMR_NUM] != 0 ) {
          test_result++;
        }

        // Enable Timer for single-shot
        TMR_REGS[TMR_NUM]->TCR  = CSL_FMKT(TIMER64P_TCR_ENAMODE34, ONCE) |
                                  CSL_FMKT(TIMER64P_TCR_ENAMODE12, CONTRESET);

        // Wait for interrupt
        while( Tmr_34_Count[TMR_NUM] == 0 );

        TMR_REGS[TMR_NUM]->TCR  = CSL_FMKT(TIMER64P_TCR_ENAMODE34, DISABLED) |
                                  CSL_FMKT(TIMER64P_TCR_ENAMODE12, DISABLED);

        if( Tmr_12_Count[TMR_NUM] < intExpected ) {
          test_result++;
        }

        test_result += TmrErrorCount;

        return test_result;
    } // Uint32 tmr_doTest()

  • Anonymous
    0 Anonymous in reply to Tai Nguyen

    Dear Tai,

    Tai Nguyen said:

    The timer period registers can not be changed after the timer is enabled (running).

    This makes all the difference. After I changed the order to

    1. 1) first set period registers
    2. 2) then set TCR and TGCR register 

     

    Everything works as expected.

     

     

    Thanks,

    Zheng

  • Dear Zheng,

    Thank you for let us know the issue is now resolved.

    -Tai