Trying to use LPO to clock LPTMR

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

Trying to use LPO to clock LPTMR

2,809 Views
cburrus
Contributor I

I'm using a KL14, and cannot seem to get the LPTMR to clock properly from the LPO.  I get a single interrupt when the LPTMR is first configured, but never again.  I can change the LPTMR clock source to the MCGIRCLK and the interrupt will trigger every time, all the other settings being the same.  I'm not using any of the super low power modes, just normal WAIT mode.  Has anyone ever seen this issue or have an explanation for it?  Thanks.

Tags (2)
0 Kudos
7 Replies

1,339 Views
anthony_huereca
NXP Employee
NXP Employee

My best guess is that you're setting the LPTMR_CSR[TFC] bit which causes the counter to continue counting until it overflows back to zero, instead of resetting back to zero on the initial comparison. If you're literally not changing anything but the clock source, that would definitely explain it. Because the MCGIRCLK is so much faster, it'll cause the LPTMR counter to overflow quickly. The LPO will take a very long time as it's significantly slower.

Check out the LPTMR code in the KL26 sample code for an example of using the LPO clock for setting up a millisecond timer: \klxx-sc-baremetal\src\drivers\lptmr

   /* Make sure the clock to the LPTMR is enabled */

  SIM_SCGC5|=SIM_SCGC5_LPTMR_MASK;

  /* Reset LPTMR settings */

  LPTMR0_CSR=0;

  /* Set the compare value to the number of ms to delay */

  LPTMR0_CMR = count_val;

  /* Set up LPTMR to use 1kHz LPO with no prescaler as its clock source */

  LPTMR0_PSR = LPTMR_PSR_PCS(1)|LPTMR_PSR_PBYP_MASK;

  /* Start the timer */

  LPTMR0_CSR |= LPTMR_CSR_TEN_MASK;

  /* Wait for counter to reach compare value */

  while (!(LPTMR0_CSR & LPTMR_CSR_TCF_MASK));

  /* Disable counter and Clear Timer Compare Flag */

  LPTMR0_CSR &= ~LPTMR_CSR_TEN_MASK;

0 Kudos

1,339 Views
jadeanthonydela
Contributor I

Hello Anthony,

Where is this directory specifically found?

\klxx-sc-baremetal\src\drivers\lptmr

Also in the code you have written, aren't there any configurations for the CSR register such as setting it as counter mode and enabling the TIE flag? Thanks.

BR,

Jade

0 Kudos

1,339 Views
anthony_huereca
NXP Employee
NXP Employee

Hi Jade,

  The files described are in the KL25 bare-metal sample code package. However that code has not been updated for a few years, so the recommendation for new designs is to use Kinetis SDK which includes an LPTMR example in the \boards\<board_name>\driver_examples\lptmr directory and supports the latest IDEs. 

 The code I put in my response is very basic, so it didn't use interrupts or change the other default LPTMR parameters. It was intended only as a simple example to show how to use the LPO to clock the LPTMR module. 

-Anthony 

1,339 Views
jadeanthonydela
Contributor I

Thank you Anthony, very informative inputs.

Regards,

Jade

0 Kudos

1,339 Views
KL04_user
Contributor II

Had a similar problem like the original poster. And setting the TFC bit was the problem.

If you are setting up a interrupt to be triggered. Only write 1 to TFC bit inside the ISR and nowhere else.

1,339 Views
perlam_i_au
Senior Contributor I

Actually there is a note on the errata (attached), please review e6060: TSI: Out of Range interrupt shows incorrect behavior with some configurations.


Cheers,
Perla

-------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-------------------------------------------------------------------------------

0 Kudos

1,339 Views
cburrus
Contributor I

Bump

0 Kudos