I'm requiring the services of a high-speed timer and as I see it on the KL25 I have the following options:
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?
I know this is *years* after the fact, but maybe this will help someone else. If I understand your question, you don't need to generate any interrupts, you just want a free-running counter that you can read.
Have you looked at the PIT module? It's a (fast) free running counter tied to the bus clock. You can gang two counters together to get a 64 bit counter with sub-microsecond resolution. You can find coding examples in the KL25 Sub-Family Reference Manual.
It seems that your TPM initial code is not complete. For example, you did not set register TPM0_MOD value. You can download sample code from our website. The link is http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=KL2&nodeId=01624698C9E3EC&fpsp=1&tab=.... Sample code name is KL25_SC. In this file, there are many sample project for modules in KL25. After you install it, you can find TPM module sample code from folder: ...\Kinetis L Sample Code\kl25_sc_rev6\klxx-sc-baremetal\src\projects\LQRUG_tpm_ex2.
Hope my reply can help you.
I am not setting TPM0_MOD because it defaults to the maximum value of 0xFFFF, which is what I want for a free-running timer. Never-the-less I have tried setting this with no change. I have also tried out some configurations of the various channels, however this does not promote the timer to count. I have set the debug flag to ensure the timer does not freeze during debug and attempted to adjust it manually from my peripheral view (using Keil for the record) however this does not help.
I'm at a complete loss, were it the clock source, I would hard fault when attempting to access the module so it can't be this...
Would you please help to reference the code I mentioned in my last reply? You can also find this code as attached. You can use a variable to get value when you need or add a breakpoint. I tested to use a variable to read TPM0_CNT and value is changed not zero.
Hope my reply can help you.