Hi
The TPM in the KL25 can be clocked from MCGIRCLK, OSCERCLK, MCGFLL or MCGPLLCLK/2 and your code sets it up to use MCGFLL, which is presumably about 20.9MHz if you have left it at its default speed.
With no prescaler this gives a resolution of 48ns and a maximum delay of about 3.125ms.
Setting the maximum prescaler (x128) gives a resolution of 6.14us and a maximum count of 400ms (if an output is toggled at each overflow it generates about 1.25Hz).
Based on the interval that you want (between 48ns and 400ms in the case of this clock speed) you can calculate the pre-scaler and remainder accordingly and program these into the SC and MOD registers to match.
You can also check the uTasker open source project at https://github.com/uTasker/uTasker-Kinetis to see its single-shot and periodic TPM interface allowing single short or periodic interrupts or DMA transfers on the KL25 (contains also Keil uVision project support).
It allows passing the delay/period in ms or us and calculates the pre-scaler and modulo value based on this and the clock used:
static __callback_interrupt void timer_int(void)
{
TOGGLE_TEST_OUTPUT();
}
static void fnConfigure_Timer(void)
{
static TIMER_INTERRUPT_SETUP timer_setup = {0};
timer_setup.int_type = TIMER_INTERRUPT;
timer_setup.int_priority = PRIORITY_TIMERS;
timer_setup.int_handler = timer_int;
timer_setup.timer_reference = 0;
timer_setup.timer_value = TIMER_US_DELAY(100000);
fnConfigureInterrupt((void *)&timer_setup);
}
It also simulates the timer operation so that complete projects can be developed, tested and debugger in visual studio.
Regards
Mark
Complete Kinetis solutions for professional needs, training and support:http://www.utasker.com/kinetis.html
Kinetis KL25:
- http://www.utasker.com/kinetis/FRDM-KL25Z.html
- http://www.utasker.com/kinetis/TWR-KL25Z48M.html
uTasker: supporting >1'000 registered Kinetis users get products faster and cheaper to market