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.

Issue when using timer4A and timer4B

Dear all

The following is my code, If I wanna using timer4A and timer4B, how could I modify the following, I couldn't make it work. Thank you :-)

void init_func1()
{
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4);
	TimerLoadSet(TIMER4_BASE, TIMER_A, 100 * (SysCtlClockGet()/1000));
	TimerConfigure(TIMER4_BASE,TIMER_CFG_16_BIT_PAIR|TIMER_CFG_A_PERIODIC);
	TimerIntEnable(TIMER4_BASE, TIMER_TIMA_TIMEOUT);
	IntEnable(INT_TIMER4A);
}

void init_func2()
{
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4);
	TimerLoadSet(TIMER4_BASE, TIMER_B, 100 * (SysCtlClockGet()/1000));
	TimerConfigure(TIMER4_BASE,TIMER_CFG_16_BIT_PAIR|TIMER_CFG_B_PERIODIC);
	TimerIntEnable(TIMER4_BASE, TIMER_TIMB_TIMEOUT);
	IntEnable(INT_TIMER4B);
}

void timer_func1()
{
    TimerIntClear(TIMER4_BASE, TIMER_TIMA_TIMEOUT);
}

void timer_func2()
{
    TimerIntClear(TIMER4_BASE, TIMER_TIMB_TIMEOUT);
}

void enable_funcs()
{
    TimerEnable(TIMER4_BASE, TIMER_A);
    TimerEnable(TIMER4_BASE, TIMER_B);
}

void main()
{
    init_func1();
    init_func2();
    enable_funcs();
    while(1);
}



  • Hi,

        Did you setup your timer interrupt handlers at your startup file?

    -kel

  • Tu,

    In addition to setting up the interrupt handlers in your startup file, you should use two different timers if you want to get interrupts every 10th of a second with your current clock configuration.

    The default clock speed is 16 MHz, and 1/10th of that is 1.6 million clock cycles. Since you are using 16 bit pair timers, the largest period they can have is 2^16 or 65535 clock cycles, much much shorter than 1.6 million and your desired 1/10th of a second interrupt period.

    If you switch to 2 32-bit timers, you can have periods of up to 2^32, or 4 billion or so clock cycles

  • Dear John

    Thanks for your reply. You mean If I want to use both 16-bit timers (timer 4A and timer 4B), I should set default clock speed such as 1MHz?

    If I switch to two 32-bit timers, in startup_ccs.c, there will be not enough timers, because I have used four 32-bit timers ( Timer 0, 1, 2, 5 subtimer A ).

    By the way, what's the difference between 「Wide Timer 0 subtimer A」 and 「Timer 0 subtimer A」 in startup_ccs.c? Is the initial code for 「Wide Timer 0 subtimer A」is different with 「Timer 0 subtimer A」?

    Maybe I should use 「Wide Timer 0 subtimer A」 and 「Wide Timer 0 subtimer B」 to solve this issue, is that right?

  • Tu,

    Reducing the clock speed to 1 MHz would still not solve the problem. You could use the timer prescaler to extend the 16 bit timer period.

    You could also use a wide timer instead. The wide timers are 64 bits wide, so the subtimers are each 32 bits wide, which will be long enough for your purposes.

    It looks like your code for timer configuration is out of date. This TivaWare code will work on both the wide and normal length timers:

    TimerConfigure(TIMER4_BASE,TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PERIODIC);

    TimerConfigure(TIMER4_BASE,TIMER_CFG_SPLIT_PAIR|TIMER_CFG_B_PERIODIC);

    Just to make sure, what Tiva part are you using? Only some of the parts have wide timers.

  • Hi, John

    I use your code, there is something wrong with my timer, it looks like the timer cannot run periodically, is the position in startup_ccs.c about timer_func1 and timer_func2 still at 「Timer 0 subtimer A」 & 「Timer 0 subtimer B」?

    My chip is TM4C1236H5QR.

  • Tu,

    When looking at your code earlier I concentrated on the configuration options for the TivaWare functions. When using wide timers, what needs to change is the TIMER_BASE part of the function call. So every time in your code that you have a "TIMER4_BASE", you should change it to "WTIMER4_BASE".

    Then put the timer_func1 and timer_func2 into the Wide Timer 4 subtimer A and B postitions in startup_ccs.c