Has anyone operated a timer with a running match value? That is, each time the match interrupt occurs, reload the match register with the present counter value plus a constant.
I want the counter to run continuously so I can keep track of the time when a given I/O condition is detected. At the same time I want a periodic interrupt. I can’t get a new match value to take effect unless I reset the counter via the TCR. Then I have to restore the previous counter value, in the meantime losing some counts.
Here’s a code snippet:
uint32_t timer_ctr;
uint32_t saved_match_value;
void app_set_match( void )
{
T1TCR=0; /* disable counting */
timer_ctr = T1TC; /* get present counter */
saved_match_value = timer_ctr + 0x1770;
T1MCR=0x0; /* disable irq on match */
T1MR0 = saved_match_value; /* store new value for match value */
T1MCR=0x1; /* enable interrupt on a match*/
++match_ctr; /* leave evidence function was called */
T1TCR = 0x2; /* reset the counter */
T1TC = timer_ctr; /* set the counter to value at entry */
T1TCR=1; /* re-enable counting */
}