Hi everyone,
I have a project running on a 1064 that will be using multiple timers, specifically the Quad Timer (TMR) and the Periodic Interrupt Timer (PIT). No matter what I try, I cannot keep these two timers in sync relative to each other, the PIT starts to lead the TMR after 10-30s depending on the clock configurations, and the lead is additive over time. What I have tried so far:
Set both the IPGCLK (TMR clock) and PERCLK (PIT clock) to 50MHz, PERCLK is derived from IPG
Set both compare registers in TMR and PIT to 50,000, which is a 1ms tick
Minimize ISR as much as possible, ISR went from what we need in our application to literally {clear status flags; ++time_ms; SDK_ISR_EXIT_BARRIER;} for both PIT and TMR.
Set both interrupts to NVIC Priority 10 (10 is an arbitrary priority, what is important is they have the same priority.)
Is it possible to have these timers tick at the same rate (or some clock multiple of each other) and not drift apart from each other over time, or is there some hardware detail I am missing that makes it impossible to have these timers in sync?
With the help of an NXP representative I found the solution and would like to share. In our original code, The PIT's LDVAL register was set to USECTOCOUNT(us, clock) - 1, and the PIT counts down to 0, whereas the QTMR was set to count up with a CMP value of USECTOCOUNT(us, clock) (The NXP API did not decrement this value by one, whereas it did decrement the PIT value, so we followed that convention initially). When testing, I tried to decrement the CMP value by 1 but still ran into this desync issue, just with a longer period required for the desync. The NXP rep suggested we run the QTMR in count down mode, with a LOAD register value of USECTOCOUNT(us, clock) - 1 to match the PIT, and that ended up solving our issue. I ran an example program for 45 minutes and the QTMR did not drift away relative to the PIT.
Hi @johndebrino ,
It sounds the QTMR is a bit slower than PIT. Did you use the example code at Example: 54.4.5.2.2 in reference manual?
Regards,
Jing