2019-03-26 12:37 AM
Hello everyone,
I am working on RTC of STM32F042C6. But I have a calibration problem.
This is my measurement mechanism:
For example: I’m measuring a +23,2 ppm error. I’m writing the value 24 (+23,2 ppm / 0,954 = 24 clocks) for the CALM bits of the CALR register. However, I observe that it masked 18 clocks instead of 24 clocks for 32 seconds period.
The measurement unit can be count 10M for every second and 32 x 10000000 = 320000000 for 32 seconds period.
32 seconds = 2^20 RTCCLK = 1048576 RTCCLK = 320000000 This is equal to 305 for 1 clock.
The value of +23,2 ppm error is 9999768.
The value of 1 clock masked is 9999768 + 305 = 10000073.
The value of 2 clock masked is 9999768 + (2 x 305) = 10000378.
The following table shows masked measurements marked in yellow. Here it is seen that 14 x 1 clock + 2 x 2 clock = 18 clock masked. But 24 clock should have been masked.
I observe that the CALM value is written correctly:
This is my code:
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
PWR_BackupAccessCmd(ENABLE);
RCC_LSEConfig(RCC_LSE_ON);
RCC_LSEDriveConfig(RCC_LSEDrive_High);
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET){
}
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
RCC_RTCCLKCmd(ENABLE);
RTC_WaitForSynchro();
RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
RTC_InitStructure.RTC_SynchPrediv = 0xFF;
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
RTC_Init(&RTC_InitStructure);
RTC_CalibOutputConfig(RTC_CalibOutput_1Hz);
RTC_CalibOutputCmd(ENABLE);
RTC->WPR = 0xCA;
RTC->WPR = 0x53;
while((RTC->ISR & RTC_ISR_RECALPF) == RTC_ISR_RECALPF)
{
}
RTC->CALR = 24;
RTC->WPR = 0xFE;
RTC->WPR = 0x64;
In conclusion, the values I write don’t run correctly. I couldn’t find the reason. May you help me for this?
Thank you.
Solved! Go to Solution.
2019-03-28 03:39 AM
This is very irregular to be true.
Is your measuring unit measuring *consecutive* seconds, i.e. taking the 32 measurements from table in first post were measured lasted exactly 32 seconds?
JW
2019-03-27 03:10 PM
This is strange.
Can you please try also different CALM values?
JW
2019-03-27 11:58 PM
I already tried. The following table is includes the other values:
"clocks" column is count of masked clocks.
All of the CALM values are written correctly to the CALR register. The CALP (+488,5 ppm offset) is works correct, but CALM doesn't.
2019-03-28 03:39 AM
This is very irregular to be true.
Is your measuring unit measuring *consecutive* seconds, i.e. taking the 32 measurements from table in first post were measured lasted exactly 32 seconds?
JW
2019-03-28 07:20 AM
I solved the problem with your advice. The results were read by skipping one, not consecutive. I fixed my input capture code and its works correctly.
Thank you very much for your time.