I need a controller with a clock accuracy better than what the internal clocks can deliver so I need to connect an external clock signal.
Thanks in advance, Tim
I see. Because the lptmr's time base can be between 900 and 1100us, I see those variances in my clock. It's actually quite a bit, up to 10% error.
However, I need something more accurate so I am planning to use one of the TPMs to generate a periodic time base, ideally a 1ms interrupt. If I use the 47.972352MHz system clock and set a TPM to output-compare mode with a compare value of 47972, I would expect to get about a 1ms time base.
Here's my problem: I started by using the output-compare driver example. Compare value is set to 0x1000 and I see a 366Hz signal at the output. But when I change that compare value, the output frequency stays the same.
What am I doing wrong here?
If you want to set KL02 run on the higher frequency (such as below red clock route), the frequency range of an external clock at EXTAL0 should meet the "ffll_ref FLL reference frequency range" in KL02P32M48SF0.pdf.
Example code can be found after download SDK_2.0_MKL02Z32xxx4 package( for example: ...\SDK_2.0_MKL02Z32xxx4\boards\frdmkl02z\driver_examples\mcg)
You need read the "Kinetis SDK API Reference Manual MKL02Z4_v2.0.0.pdf".( It's in ...\SDK_2.0_MKL02Z32xxx4\docs folder.)
If you have never used Kinetis SDK2.0, "Getting Started with Kinetis SDK (KSDK) v.2.0.pdf" is recommand read first.
Thanks, that explains it. Did a bit more reading in the meantime and hope to have a slightly better understanding by now.
I was actually thinking of something like using a 24-48MHz oscillator at Extal0 and routing it straight through with MCGOUTCLK.
From what I read out of the SDK examples, they are all using the external 32.768kHz as clock source and generating a 47.972352MHz system clock, correct?
Unfortunately, my initial problem still exists: when I am running LPTMR driver example the time is not exactly 1s but about 1.0007s. Which is no real issue on a 1s timebase. But when I switched to 1ms by changing LPTMR_USEC_COUNT to 1000[us], the time base was 1.7ms, which is far out of range.
Looks like I got something wrong with the IRQ rather then system clock?
1. I think you can using a 24-48MHz oscillator at Extal0 and routing it straight through with MCGOUTCLK.(such as below red clock route)
3. It is not caused by system clock, this example use 1kHz LPO as clock source of LPTMR. You need set the LPTMRx_CMR=0x00 to get a 1ms IRQ. Please try to change LPTMR_USEC_COUNT=999, or use LPTMR_SetTimerPeriod(LPTMR0,0);
Observe the waveform on LED_Red (Pin7 J8 FRDM-KL02Z). The example toggle that pin in LPTMR_LED_HANDLER().