Periodic Frequency of S32K LPIT in Compare Mode

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Periodic Frequency of S32K LPIT in Compare Mode

Jump to solution
1,468 Views
damiendusha
Contributor II

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);

or

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%.

0 Kudos
1 Solution
1,158 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello Damien,

The first one is correct.

When it reaches 0, TVAL is loaded immediately.

..., 3, 2, 1, 0 (TVAL), TVAL - 1, ...

Regards,

Daniel

View solution in original post

1 Reply
1,159 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello Damien,

The first one is correct.

When it reaches 0, TVAL is loaded immediately.

..., 3, 2, 1, 0 (TVAL), TVAL - 1, ...

Regards,

Daniel