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:
- Why do the timers start right away, since they are disabled. In fact, I have added line marked with (**) and it makes no difference.
- 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