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.

Problem reconfiguring WTimer0 on the fly



I am trying to reconfigure WTimer0 on the fly.  Basically I have a GUI and I want to click a button and have the ARM change it's timing intervals say from 10Hz to 100Hz etc.... I've gotten this running with the below code and it works fine for the first or second configuration message, but after that it just stops.  Is it possible to stop the timer, change the TAILR register with the TimerLoadSet command and then run TimerEnable(); to start it or do I have to use the match registers or something else?  I don't seem to be able to configure the timer, start it and then change it on the fly in the manner I have coded up.  Below is the code I'm using to configure and start/stop the WTimerA module.

To configure initially and reconfigure the timer I am re-running the same function:

void WTimer0A_32bit_config(uint32_t counter)
{
	// Disable Timer peripheral
	//SysCtlPeripheralDisable(SYSCTL_PERIPH_WTIMER0);
	//SysCtlDelay(1000);
	// Enable Timer peripheral
	SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER0);
	// Configure WTimer0 in 32-bit mode
	TimerConfigure(WTIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC_UP);
	// load timer with SysClk/100 (1mS increments)
	TimerLoadSet(WTIMER0_BASE, TIMER_A, counter);
	// Enable timer interrupt in master interrupt controller
	IntEnable(INT_WTIMER0A);
	// Enable interrupts
	TimerIntEnable(WTIMER0_BASE, TIMER_TIMA_TIMEOUT);
	// Register ISR
	TimerIntRegister(WTIMER0_BASE, TIMER_A, *WTimer0IntHandler);
}

Function to start the timer:

TimerEnable(WTIMER0_BASE, TIMER_A);

Function to stop the timer:

TimerDisable(WTIMER0_BASE, TIMER_A);

I've tried many many different variations of all of these form initially configuring it and just changing the TAILR register to disabling and re-enabling the peripheral every time.  I don't understand why this works fine once or twice, but then the timer just stops.  I've taken screen shots and compared all of the bits in the WTimer0 registers when it is running and when it fails and I don't see any difference.  The bit values in all the registers are the same when it fails and when it is running.  Is there something I'm not re-enabling in the interrupt controller?  Thanks for any input.

  • Hi,

    The last line of your initialization routine is not good : instead *WTimer0IntHandler must write &WTimer0IntHandler.

    And some other problems:

    a) Try to develop the habit to separate the initialization phase from the exploitation phase - because you may waste significant amount of time - for instance there is no need to register an interrupt every time you need to modify timer's value - particularly the register process can be long since several tens of vectors are moved (copied) from flash to ram. One registration is enough - or even you may avoid this step if you run from flash. Same about SysCtlPeripheralEnable() - since all these can involve some time to reach the working stage.

    b) Counting up in timers involves a mach compare to check for the limit - a better approach is to count down - in ARM architecture and C language this is more efficient in terms of code generation and execution time. And easier operation in timers since the implicit limit is 0 (also in arithmetic in some configurations).

  • Hey thanks for the advice! I agree that I shouldn't be reconfiguring all of the timer settings like I am in this example. I've tried many variations including setting up the timer and just using the load set function to change the value. None of that seems to work. I haven't tried counting down though. Ill give that a shot and report back. I wouldn't think changing the count and restarting the timer would be so difficult
  • So I got this working and wanted to post up my solution.  I just listened to the above post and changed the timer over to count down instead of counting up and my problem was solved.

  • Hi,

    Congratulations! You can post the solution here, but do not forget to add/insert tags, so others can find a ready made solution. And one last word: mark your question as answered.

    Petrei