AnsweredAssumed Answered

Free-running Timer on KL25

Question asked by gmscribe on May 4, 2013
Latest reply on Sep 30, 2017 by Robert Poor

Hi guys,

 

I'm requiring the services of a high-speed timer and as I see it on the KL25 I have the following options:

 

  • TPM
  • LPTMR
  • PIR

 

I'm concerned that later on in my project, the 4MHz max clock of the LPTMR will be too slow for my needs, likewise, I feel as though I'm somehow misappropriating the PIR if I use it as a simple free-running timer. It's my hope to use the TPM, all I require is for it to free run and for my software to sample the current timer value.

 

I currently have the following code, however the timer doesn't appear to begin counting:

 

SIM->SOPT2 &= ~(1UL << 16); // Use FLL clock
SIM->SOPT2 |= (1UL << 24);  // Timer will run off FLL clock
SIM->SCGC6 |= (1UL << 24);  // Activate clock to Timer 0

TPM0->CNT   = 0;
TPM0->SC    = (1UL << 3);  // Enable the counter to increment on each counter clock

 

I'm now expecting CNT to increment, however this doesn't appear to be the case. Do I need to do something to trigger the timer? Will this allow it to function as a true free-running counter?

 

Many thanks

Outcomes