I'm using the TM4C1294NCPDT microcontroller and am having problems getting deterministic results using the Wait On Trigger feature.
I have 3 timers: Two PWM half width timers and one one-shot timer to trigger a delay on one of the PWM timers. Both PWM timers have the same frequency and Duty Cycles. The one-shot timer counts up to and above the period of the PWM signals to impart a delay on one of the PWM timers relative to the other. My timers are configured as follows:
void initTimers()
{
// Delay between Timer 4A and Timer 5A
uint32_t Delay = 0;
// Enable Timer3B for one-shot count up, half width, period is 19999 + Delay
// This timer will trigger the start of 4A
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3);
TimerConfigure(TIMER3_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_ONE_SHOT_UP);
TimerPrescaleSet(TIMER3_BASE, TIMER_B, 1);
TimerLoadSet(TIMER3_BASE, TIMER_B, 119999 + Delay);
TimerControlStall(TIMER3_BASE, TIMER_B, true);
// Enable Timer5A for PWM, 1kHz 50% duty cycle
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER5);
TimerConfigure(TIMER5_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM);
TimerPrescaleSet(TIMER5_BASE, TIMER_A, 1);
TimerLoadSet(TIMER5_BASE, TIMER_A, 119999);
TimerMatchSet(TIMER5_BASE, TIMER_A, 59999);
TimerControlStall(TIMER5_BASE, TIMER_A, true);
// Enable Timer4A for PWM, 1kHz 50% duty cycle, counter will start on Timer3B timeout event
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4);
TimerConfigure(TIMER4_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PWM);
TimerControlWaitOnTrigger(TIMER4_BASE, TIMER_A, true);
TimerPrescaleSet(TIMER4_BASE, TIMER_A, 1);
TimerLoadSet(TIMER4_BASE, TIMER_A, 119999);
TimerMatchSet(TIMER4_BASE, TIMER_A, 59999);
TimerControlStall(TIMER4_BASE, TIMER_A, true);
// Enable Timer0. Seems to be required to sync all timers.
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
// Enable Timers
TimerEnable(TIMER3_BASE, TIMER_BOTH);
TimerEnable(TIMER5_BASE, TIMER_A);
TimerEnable(TIMER4_BASE, TIMER_BOTH);
// Sync Timers
TimerSynchronize(TIMER0_BASE, TIMER_3B_SYNC |
TIMER_4A_SYNC |
TIMER_5A_SYNC);
}
What I observe is that when Delay is set to 0, I observe an 8 count difference in the count value of timers 4A and 5A (instead of 1 count I expect). When I set Delay to a non zero value, such as 1000, I observe a 1008 count different instead of 1001. Even worse, when I step through an infinite while loop placed right after the TimerSynchronize command, and step right before and right after the TriggerOnWait event (when Timer 3B approaches it's load value), I can observe varying differences (4 or 1 instead of the 8 when Delay = 0). It seems to be non deterministic when debugging, but a static 7 count difference from what I expect when not debugging.
Can anyone provide some assistance in addressing this problem?