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.

TM4C123GH6PM timer won't work

Other Parts Discussed in Thread: EK-TM4C123GXL

Timer won't run.  ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER0) shows that peripheral is enabled.

Timer is enabled and ROM_TimerValueGet(TIMER0_BASE, TIMER_A) shows that correct value was loaded (20000).  But this value never changes.

I did not set any clock source for the timer because doc says it only uses the system clock and no place to set this.

The rest of my code works, so my basic setup and use of the TivaWare ROM libraries is working.

 

Many thanks if someone can help.

 

My code is:

ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);  // enable timer

ShortDelay();

ROM_SysCtlPeripheralPowerOn(SYSCTL_PERIPH_TIMER0);

ShortDelay();

if (!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER0)) j = 3;      // check contr Timer error

ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_ONE_SHOT);

ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet() / 1000);  // set for 1ms at 20MHz

ROM_TimerEnable(TIMER0_BASE, TIMER_A);

while (true)

{

j = ROM_TimerValueGet(TIMER0_BASE, TIMER_A);

if (j==10000) break;

}

 

  • Hi Anthony,

        There is a timer example program at "\\examples\boards\ek-tm4c123gxl\timers", that you can use as base for your project. Just modify it for your testing.

    -kel

  • Our group does not use/know "Tiva" SW - but have never past noted your use of,

    "ROM_SysCtlPeripheralEnable()" immediately followed by:

    "ROM_SysCtlPeripheralPowerOn()"

    Review of the key Timer Registers may reveal if that "PowerOn()" function in any way disturbs the earlier "PeripheralEnable()..."

    And - it is extremely rare that the xxxPeripheral, "won't work."  Far more common (and accurate) is that the user's applciation code, "does not yet work!"   Blame the part/peripheral last...

  • Thanks for the responses, but there is something else going on.

    With otherwise the same code:

    ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC) works!

    ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_ONE_SHOT) refuses to budge.

  • That's good information - by varying your Timer set-up/config you've gleaned knowledge.

    Have you given a good (thorough) read to the "One Shot" behavior?  Might it be that the value indeed changes during the "one-shot" interval - and then reverts to the original setting?  (I cannot recall...)

  • Ok problem solved, but don't understand why:

    ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_ONE_SHOT) will work, but only with interrupts:

     

    ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

    ROM_TimerEnable(TIMER0_BASE, TIMER_A);

    while (ROM_TimerIntStatus(TIMER0_BASE, true) != TIMER_TIMA_TIMEOUT)

    {

    j++;

    }

    ---------------------------

    ROM_TimerValueGet(TIMER0_BASE, TIMER_A) never changes.

     

  • Anthony Levine1 said:
    will work, but only with interrupts:

    Don't believe that to be strictly true...

    Look here - our implementation...

        GPIO_PORTD_DATA_R |= 0X10;   // PD4 HI  Test Out  
       
        ROM_TimerEnable(TIMER1_BASE, TIMER_B);  // Test timer enable


    void
    Timer1BIntHandler(void)
    {
     
          ROM_TimerIntClear(TIMER1_BASE, TIMER_TIMB_TIMEOUT);
     
          GPIO_PORTD_DATA_R &= ~0X10;   // PD4 Lo  Test Out
         
          ROM_TimerDisable(TIMER1_BASE, TIMER_B);
         
    }     

    Now we used the "Timeout" interrupt for ease of "detection" of the one-shot's expiration.  But - that interrupt is not strictly required - the one-shot will perform w/out it.  You may test by loading larger values - and then "testing" for the one-shot's expiration @ very fast, repeated intervals.

    Believe my original diagnosis (you simply could not or did not observe the one-shot's counting) to be correct...

    When in doubt - MCU Manual (this from LX4F) reveals: 

    "When the timer is counting down and it reaches the timeout event (0x0), the timer reloads its start
    value from the GPTMTnILR and the GPTMTnPR registers on the next cycle.

    In addition to reloading the count value, the GPTM generates interrupts and triggers when it reaches
    the time-out event."

    Thus - as earlier stated - the timer was reloaded - leading to the belief that it had not, "wiggled."  (it had)

  • You were 100% right.  A one shot timer simply times out, reloads and disables itself.

    That's why I could not see a value change.

    Many thanks.