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.

Using both TIMER_A and TIMER_B in LM4F120H5QR?

Greetings,

I'm trying to set up both subtimers of Timer3 to trigger every millisecond but I'm having a hard time getting it to work.

Here is the relevant code snippet:

   TimerDisable(TIMER3_BASE, TIMER_BOTH);
   TimerConfigure(TIMER3_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_ONE_SHOT | TIMER_CFG_B_ONE_SHOT);
   TimerIntEnable(TIMER3_BASE, TIMER_TIMA_TIMEOUT | TIMER_TIMB_TIMEOUT);
   TimerMatchSet(TIMER3_BASE, TIMER_A, 0x0001);
   TimerMatchSet(TIMER3_BASE, TIMER_B, 0x0001);
   TimerControlStall(TIMER3_BASE, TIMER_BOTH, true);
   TimerPrescaleSet(TIMER3_BASE, TIMER_A | TIMER_B, 1);
   TimerLoadSet(TIMER3_BASE, TIMER_A, 50000);
   TimerLoadSet(TIMER3_BASE, TIMER_B, 50000);
   TimerDisable(TIMER3_BASE, TIMER_BOTH);   (**)
    
   IntEnable(INT_TIMER3A);                     (*)
   IntEnable(INT_TIMER3B);

First problem is that as soon as the code executes the line marked with a (*), the timer A starts running at a very high rate (for testing, I am re-enabling the timer in the interrupt handlers)

The interrupt handlers (I have two, one for TimerA and one for TimerB look similar); here is the code for TimerB.

void Timer3BIntHandler(void)
{
   unsigned long statusTimer = TimerIntStatus(TIMER3_BASE, true);
   TimerIntClear(TIMER3_BASE, statusTimer & TIMER_TIMB_TIMEOUT);

   debug_pin_toggle();
   timer_3b_fired ++;
   
   TimerEnable(TIMER3_BASE, TIMER_B);
}

I am testing the timer behavior right now. Eventually I'll have the setup code run at startup, then enable either of the timers when I need a precise delay of 1 ms.

My two questions are:

  1. Why do the timers start right away, since they are disabled.  In fact, I have added line marked with (**) and it makes no difference.
  2. Why does TimerA run at such a high rate (100Khz)?

This is my clock setup:

   ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

Thank you,

florin

  • And the winner is:

    ROM_TimerIntClear(TIMER3_BASE,
                      TIMER_TIMB_MATCH |
                      TIMER_CAPB_EVENT |
                      TIMER_CAPB_MATCH |
                      TIMER_TIMB_TIMEOUT |
                      TIMER_TIMA_MATCH |
                      TIMER_RTC_MATCH |
                      TIMER_CAPA_EVENT |
                      TIMER_CAPA_MATCH |
                      TIMER_TIMA_TIMEOUT);

    in the configuration section and a change to the interrupt handler:

    void Timer3BIntHandler(void)
    {
       unsigned long status = TimerIntStatus(TIMER3_BASE, true);
       TimerIntClear(TIMER3_BASE, status);
       
       if (status & TIMER_TIMB_TIMEOUT)
       {
           // do whatever
       }
    }

    I am surprised that interrupt raised persist across MCU reset (from IAR).