AnsweredAssumed Answered

K22: LPTMR TCF overhead of 2 ms with LPO?

Question asked by Troels Østeraa on Nov 22, 2018
Latest reply on Nov 25, 2018 by Robin_Shen

Hi,

 

Device is MK22FN256VLL12, the LPTMR is currently using the LPO (1 kHz) with prescaler bypassed, running in time counter mode. What I am experiencing is about 2 ms overhead regardless of CMR value, e.g. until TCF is set. I check the LPO on PTE0 using the following setup:
SIM->SOPT1 |= SIM_SOPT1_OSC32KSEL(3) | SIM_SOPT1_OSC32KOUT(1);
The waveform looks as follows:

So about 1% slower, which is well within acceptable.

 

In the following, the clock output on PTE0 is disabled, it just works as a normal GPIO, configured as output
My LPTMR setups is as follows:

void LPTMR_init(void)

{

   SIM->SCGC5 |= SIM_SCGC5_LPTMR_MASK;

   LPTMR0->CSR = 0;

   LPTMR0->PSR = LPTMR_PSR_PCS(1) | LPTMR_PSR_PBYP_MASK;

}

 

The LPTMR delay function looks like this:

void LPTMR_delay(uint16_t uValue)

{

   LPTMR0->CMR = LPTMR_CMR_COMPARE(uValue);

   LPTMR0->CSR |= LPTMR_CSR_TEN_MASK;

   while(!(LPTMR0->CSR & LPTMR_CSR_TCF_MASK));
   LPTMR0->CSR &= ~LPTMR_CSR_TEN_MASK;

   GPIOE->PTOR = GPIO_PIN(0);

}

 

The function calling the LPTMR_delay is as follows:
do

{

   LPTMR_delay(10);

}

while(1);

 

This is just called from main. The ONLY other ISR running at 20 ms intervals is the SysTick ISR, which just increases a counter and nothing else. The results when monitoring PTE0 using a scope, is as follows:

So what ought to be 10 ms toggle intervals is now approximately 12 ms intervals.

Any suggestions why I have an overhead of 2 ms and what I've misunderstood about the LPTMR?

Thanks a lot.

Outcomes