Free-running timer TPM on KL17Z

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

Free-running timer TPM on KL17Z

Jump to solution
904 Views
gschelotto
Contributor V

Hi,

I'd need to implement a free-running timer using TPM timer without IRQ in order to get successive time-stamps between acquisition data samples. I know the concept is easy and trivial but I'm trying to do it using the latest SDK for KL17Z with no success. I'm also not able to find any TPM SDK examples with such behavior. Can anyone help me with this problem?

regards,
gaston

0 Kudos
1 Solution
812 Views
gschelotto
Contributor V

Solved.

At the end I used the Systick timer as free-running timer and it works as expected. Here's the code inside the sampling routine

    tmp = SysTick->VAL;

    // SysTick Reload Value register supports values between 1 and 0x00FFFFFF.
    SysTick->LOAD = 0x00FFFFFF;
    SysTick->VAL = 0;

    tmp = 0x00FFFFFF - tmp;
    timeStamp[tmStmpIdx] = COUNT_TO_USEC(tmp, CLOCK_GetFreq(kCLOCK_CoreSysClk));
    tmStmpIdx++;
‍‍‍‍‍‍‍‍‍‍

thanks,
gaston

View solution in original post

0 Kudos
3 Replies
812 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi gaston,

Have you try to refer the tpm_timer example in SDK_2.7.0_MKL17Z64xxx4?

tpm_timer.png
enableStopOnOverflow = false; means TPM counter continues running after overflow.
You can disable below IRQ related codes.

enableStopOnOverflow.png

Seems that you don't need to interrupt 1ms anymore, so configure MOD=0xffff by using TPM_SetTimerPeriod function.

TPM_SetTimerPeriod.png

Best Regards,

Robin

 

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

0 Kudos
812 Views
gschelotto
Contributor V

Yes indeed, I proceed as you suggested and the timer is running as expected but writing this code in my IRQ sampling process

timeStamp[tmStmpIdx] = TPM_GetCurrentTimerCount(TPM2);
tmStmpIdx++;

leads to the same results on the timeStamp array and I cannot see any increment on their values. Any hint?

How can I reset the timer counter?

regards,

gaston

0 Kudos
813 Views
gschelotto
Contributor V

Solved.

At the end I used the Systick timer as free-running timer and it works as expected. Here's the code inside the sampling routine

    tmp = SysTick->VAL;

    // SysTick Reload Value register supports values between 1 and 0x00FFFFFF.
    SysTick->LOAD = 0x00FFFFFF;
    SysTick->VAL = 0;

    tmp = 0x00FFFFFF - tmp;
    timeStamp[tmStmpIdx] = COUNT_TO_USEC(tmp, CLOCK_GetFreq(kCLOCK_CoreSysClk));
    tmStmpIdx++;
‍‍‍‍‍‍‍‍‍‍

thanks,
gaston

0 Kudos