I'm using MKM34Z256VLL7 and I'm trying to manage the rtc oscillator loss monitor and its flags.
At power up, the rtc monitor is set (at the end of BOARD_BootClockRUN() function):
/* Set Rtc osc. monitor mode */
then I wrote a function to check if rtc osc. is lost or not.
This is the function:
status_t status = kStatus_Fail;
if (CLOCK_GetStatusFlags() & kMCG_RtcOscLostFlag)
// Toggle pin to alert RTC osc. is lost
GPIO_TogglePinsOutput(GPIOA, 1u << BOARD_PIN1); // TODO : remove or debug only
status = kStatus_Fail;
GPIO_TogglePinsOutput(GPIOB, 1u << BOARD_PIN7); // TODO : remove or debug only
status = kStatus_Success;
This is my main function:
CheckRTC_OscStable(); // 1st call to check rtc
/* Enter an infinite loop */
The 1st call to CheckRTC_OscStable() returns kStatus_Success even if rtc osc is not stable.
The 2nd call to CheckRTC_OscStable() returns kStatus_Fail (that's right because rtc osc is not yet stable), and then after some hundreds ms
the function returns kStatus_Success (that's right, finally rtc osc is stable).
Probably there must be a delay between the configuration of the osc monitor mode and the 1st check of the flags, but I didn't find this data in the datasheet,
can you help me? How long does the monitor take to be fully operational?
There is no such a data in KM34's datasheet. Since Kinetis family share same IP and manufacturing process, we can refer to other device's datasheet. This time is tirefsts. Both KL82 and K80 is 32us. K60 is max 4us. So, I think this time is very short, less than 1ms.
Hello Jing Pan,
thanks for the answer, but it does not fit my question.
My question is about the rtc oscillator monitor and not the rtc oscillator.
I'd like to know how long does the monitor take to be fully operational, because the monitor (after being set) needs some time to set flags correctly (see code and considerations above).
The RTC monitor use IRC as clock base. It counts RTC clock. If it is out of range, MCG_C8.LOCS1 will be set. When the program is running, it IRC should be stable. But during the long start time, RTC counter sometimes in range, but sometimes not.
Hello Jing Pan,
thanks for the answer.
You mean SlowIRCLK?
You are talking about paragraph 35.4.4 of the manual?
In figure 35.1 seems the clock monitor can be sourced also from external crystal osc., or am I misunderstanding?
Yes, this monitor can check both external OSC and RTC. MCG_C6.CME0/MCG_C8.CME1 enable the function. From figure 35.1, it seems that it use the slow clock.
I'm using an external osc in my application, and I've never enabled the slowclock.
But paragraph 35.4.4 of the manual says "If any of the CME bits are asserted the slow internal reference clock is enabled along with the enabled external clock monitor".
So probably, after being set, the monitor gives "false positives" results because the slowclock is not yet stable. Do you agree?
So let's go back to my question: how long does the monitor take to be fully operational (no false positives)?
In other words, how long does the slowclock take to be stable?