AnsweredAssumed Answered

Periodic Frequency of S32K LPIT in Compare Mode

Question asked by Damien Dusha on Aug 26, 2018
Latest reply on Aug 27, 2018 by Daniel Martynek

Dear All,


I am looking to determine the precise periodic frequency of the LPIT peripheral when operating in Compare Mode. Unfortunately, Figure 46-5 on p1392 (Rev 8. 06/2018) does not show the sequence in sufficient detail.


In short, my question is which formula is correct?


f_periodic = f_peripheral / (TVAL);


f_periodic = f_peripheral / (TVAL + 1);


The cook-book example ("hello_interrupts") suggests the first version since is specifies a divider of 40000000:

void LPIT0_init (void) {
  PCC->PCCn[PCC_LPIT_INDEX] = PCC_PCCn_PCS(6);    /* Clock Src = 6 (SPLL2_DIV2_CLK)*/
  PCC->PCCn[PCC_LPIT_INDEX] |= PCC_PCCn_CGC_MASK; /* Enable clk to LPIT0 regs */
  LPIT0->MCR = 0x00000001;    /* DBG_EN-0: Timer chans stop in Debug mode */
                              /* DOZE_EN=0: Timer chans are stopped in DOZE mode */
                              /* SW_RST=0: SW reset does not reset timer chans, regs */
                           /* M_CEN=1: enable module clk (allows writing other LPIT0 regs)*/
  LPIT0->MIER = 0x00000001;   /* TIE0=1: Timer Interrupt Enabled fot Chan 0 */
  LPIT0->TMR[0].TVAL = 40000000;    /* Chan 0 Timeout period: 40M clocks */
  LPIT0->TMR[0].TCTRL = 0x00000001; /* T_EN=1: Timer channel is enabled */
                              /* CHAIN=0: channel chaining is disabled */
                              /* MODE=0: 32 periodic counter mode */
                              /* TSOT=0: Timer decrements immediately based on restart */
                              /* TSOI=0: Timer does not stop after timeout */
                              /* TROT=0 Timer will not reload on trigger */
                              /* TRG_SRC=0: External trigger soruce */
                              /* TRG_SEL=0: Timer chan 0 trigger source is selected*/

However, the reference manual says the TVAL value is loaded when the timer reaches zero.  So, if the peripheral spends a full clock at zero value, then the periodic value in the example is slightly wrong since there are (TVAL+1) clocks per interrupt.


This will matter more when the timer values are short (e.g. TVAL = 100), where it would result in a timing error of roughly 1%.