Hi,
We have developed our own board with Kinetis KL46 processor. There is no external crystal in the board, I'm using only the internal referance clock.
RTC need 32KHz clock input so I did what they have given in the following link Using RTC module on FRDM-KL25Z.
the result of the above experiment is the time counter is slow by 10 seconds.
I have also tried using the LPO clock source even that time the result is same.
How can I get over form the 10 seconds delay??
And also If I connect the Clock out to RTC clock In as said in the document, will the whole processor run in 32khz??
Reply soon!!!
Best Regards,
shabana
Solved! Go to Solution.
Hi Shabana m,
The function below is to convert RTC seconds to date and time. It have been provided by Freescale Japan. Even if the RTC clock is not 32.768kHz but 32kHz, you can use the function by varying the constants by 32/32.768 (=0.9765625) times. That is,
86400 => 84375,
3600 => 3515,
60 => 58, and so on.
If the RTC source clock is LPO (1kHz), the constants conversion would be more simpler.
Can it help you?
Best regards,
Yasuhiko Koumoto.
----[snip]------
typedef struct {
uint32_t Second; /*!< seconds (0 - 59) */
uint32_t Minute; /*!< minutes (0 - 59) */
uint32_t Hour; /*!< hours (0 - 23) */
uint32_t DayOfWeek; /*!< day of week (0-Sunday, .. 6-Saturday) */
uint32_t Day; /*!< day (1 - 31) */
uint32_t Month; /*!< month (1 - 12) */
uint32_t Year; /*!< year */
} LDD_RTC_TTime;
static void RTC1_ConvertSecondsToDateAndTime(LDD_RTC_TTime *TimePtr, uint32_t Seconds)
{
uint32_t x;
uint32_t Days;
Days = Seconds / 86400U; /* Days */
Seconds = Seconds % 86400U; /* Seconds left */
TimePtr->Hour = Seconds / 3600U; /* Hours */
Seconds = Seconds % 3600u; /* Seconds left */
TimePtr->Minute = Seconds / 60U; /* Minutes */
TimePtr->Second = Seconds % 60U; /* Seconds */
TimePtr->DayOfWeek = (Days + 6U) % 7U; /* Day of week */
TimePtr->Year = (4U * (Days / ((4U * 365U) + 1U))) + 2000U; /* Year */
Days = Days % ((4U * 365U) + 1U);
if (Days == ((0U * 365U) + 59U)) { /* 59 */
TimePtr->Day = 29U;
TimePtr->Month = 2U;
return;
} else if (Days > ((0U * 365U) + 59U)) {
Days--;
} else {
}
x = Days / 365U;
TimePtr->Year += x;
Days -= x * 365U;
for (x=1U; x <= 12U; x++) {
if (Days < ULY[x]) {
TimePtr->Month = x;
break;
} else {
Days -= ULY[x];
}
}
TimePtr->Day = Days + 1U;
}
----[snip]------
Hi Shabana m,
The Using RTC module on FRDM-KL25Z thread just shows RTC could works with internal 32KHz reference clock, while it is not a recommend way.
We recommend customer to use external 32.768KHz oscillator to provide more accuracy clock from RTC_CLKIN pin.
More detailed info, customer could refer TWR-KL25Z48M board schematics:
http://cache.freescale.com/files/soft_dev_tools/hardware_tools/schematics/TWR-KL25Z48M_SCH.pdf
From KL25 datasheet, the internal 32KHz reference clock need be trimmed to 32.768KHz and less accuracy than external 32.768KHz oscillator.
The clock frequency deviation will cause the RTC runs faster or slower.
Wish it helps.
best regards
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Ma Hui,
Thank u so much for your reply..
but unfortunately there is no external crystal or oscillator on our board :smileysad: .
Can I do anything with the internal clock to make it accurate??
Hi, Shabana,
From KL46 datasheet, the KL46 MCG internal slow clock source accuracy is below:
Customer need to trim the MCG internal slow clock before using it as RTC reference clock.
And customer also could consider to use RTC compensation feature to get more accuracy RTC performance.
Wish it helps.
best regards
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi shabana m,
what is the meaning of "slow by 10 seconds"? Is the RTC_TSR counted up at every 11 second? Also do you mean that the RTC behavior did not change at OSC32KCLK and LPO? I cannot believe. Please show us the SIM_SOPT1 and RTC setting.
Best regards.
Yasuhiko Koumoto.
Hi Yasuhiko Koumoto,
Actually now I tried with the processor expert. Earlier there may be some issue with the clock setting. Now let me tell you what is my problem.
I have follow all the steps given in the document Using RTC module on FRDM-KL25Z
using processor expert. The result of this test is..
in the first minute and second minute it is fine
3rd min - kl46 rtc is first by 1 sec
4th min - fast by 1 sec
5th - 2 secs
6th - 3 secs
7th - 4 secs
8th - 4 secs
9th - 4 secs
10th - 4 secs
11th - 5 secs
12th - 5 secs
likewise, in 20th min its 9 secs.
can u help me??
Best regards,
Shabana
Hi Shabana m,
did you make the feedback loop from the PTC1 to PTC3? Also did you make the following setting?
RTC_TCR = RTC_TCR_CIR(1) | RTC_TCR_TCR(0xFF);
If it would be true, how about to set the zero to RTC_TCR.
By the above setting, RTC would be counted up by every 32769 clock cycles. It means RTC would be slower than usual.
Best regards,
Yasuhiko Koumoto.
Hi Yasuhiko Koumoto,
did you make the feedback loop from the PTC1 to PTC3? yes
Also did you make the following setting?
RTC_TCR = RTC_TCR_CIR(1) | RTC_TCR_TCR(0xFF);
yes
can you tell me how to calculate this compensation??
Hi Shabana m,
I guess that you use MCGIRCLK as CLKOUT (i.e. CLKIN). In this case, MCGIRCLK frequency might be 32KHz. Therefore you should select 'Time Prescaler Register overflows every 32000 clock cycles' as the compensation value. Unfortunately the possible setting of RTC_TCR would be 0x7F at the slowest (this means Time Prescaler Register overflows every 32641 clock cycles). By this setting it would cause 32641/32000=1.020 (i.e. 2%) error. I must correct my former comment. You could set as the following value for the least error.
RTC_TCR = RTC_TCR_CIR(1) | RTC_TCR_TCR(0x7F);
Best regards,
Yasuhiko Koumoto.
Hi Shabana m,
by the way, for what is the purpose you use RTC? If you want to make a second wise timer, there would be several ways. For example, you can use an interrupt which occurs by every one second.
Best regards,
Yasuhiko Koumoto.
Hi Yasuhiko Koumoto,
I need to keep track of date and time.. is there any other way to do this??
Best regards,
Shabana
Hi Shabana m,
The function below is to convert RTC seconds to date and time. It have been provided by Freescale Japan. Even if the RTC clock is not 32.768kHz but 32kHz, you can use the function by varying the constants by 32/32.768 (=0.9765625) times. That is,
86400 => 84375,
3600 => 3515,
60 => 58, and so on.
If the RTC source clock is LPO (1kHz), the constants conversion would be more simpler.
Can it help you?
Best regards,
Yasuhiko Koumoto.
----[snip]------
typedef struct {
uint32_t Second; /*!< seconds (0 - 59) */
uint32_t Minute; /*!< minutes (0 - 59) */
uint32_t Hour; /*!< hours (0 - 23) */
uint32_t DayOfWeek; /*!< day of week (0-Sunday, .. 6-Saturday) */
uint32_t Day; /*!< day (1 - 31) */
uint32_t Month; /*!< month (1 - 12) */
uint32_t Year; /*!< year */
} LDD_RTC_TTime;
static void RTC1_ConvertSecondsToDateAndTime(LDD_RTC_TTime *TimePtr, uint32_t Seconds)
{
uint32_t x;
uint32_t Days;
Days = Seconds / 86400U; /* Days */
Seconds = Seconds % 86400U; /* Seconds left */
TimePtr->Hour = Seconds / 3600U; /* Hours */
Seconds = Seconds % 3600u; /* Seconds left */
TimePtr->Minute = Seconds / 60U; /* Minutes */
TimePtr->Second = Seconds % 60U; /* Seconds */
TimePtr->DayOfWeek = (Days + 6U) % 7U; /* Day of week */
TimePtr->Year = (4U * (Days / ((4U * 365U) + 1U))) + 2000U; /* Year */
Days = Days % ((4U * 365U) + 1U);
if (Days == ((0U * 365U) + 59U)) { /* 59 */
TimePtr->Day = 29U;
TimePtr->Month = 2U;
return;
} else if (Days > ((0U * 365U) + 59U)) {
Days--;
} else {
}
x = Days / 365U;
TimePtr->Year += x;
Days -= x * 365U;
for (x=1U; x <= 12U; x++) {
if (Days < ULY[x]) {
TimePtr->Month = x;
break;
} else {
Days -= ULY[x];
}
}
TimePtr->Day = Days + 1U;
}
----[snip]------
Hi Yasuhiko Koumoto,
Thank u sooo much.. your answer is really helpful. :smileyhappy:
Support from freescale is awesome.. :smileyhappy:
Best regards,
Shabana
Looking at the MCG specs in the datasheet, it isn't entirely clear what the 32,768 internal clock tolerance is, but I might expect a total +/-1% variation looking at the other internal-clock-related specs.
Hi Earl Goodrich ll,
Is it like the 32768 is not very accurate?? if yes, what I need to do?? can any compensation can be done in RTC_TCR??
The internal 32KHz has no construction that would allow it to be accurate. Yes, you could probably compensate with TCR, but characterizing each part, especially over temperature, sounds onerous. If you are looking for something like 50ppm, any external 'watch crystal' will do, hooked to the Kinetis 32KHz-oscillator pins. If you want more like 10ppm, then a 'tight' watch crystal is called for, as well as temperature-compensation for THAT as all such 'tuning fork' crystals have a negative tempco both above and below 'room temperature;.