cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 RTC Calibration Problem

Murat Sevil
Associate II

Hello everyone,

I am working on RTC of STM32F042C6. But I have a calibration problem.

This is my measurement mechanism:

0690X0000088rUMQAY.png

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.

0690X0000088rVPQAY.png

I observe that the CALM value is written correctly:

0690X0000088rVoQAI.png

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

4 REPLIES 4

This is strange.

Can you please try also different CALM values?

JW

Murat Sevil
Associate II

I already tried. The following table is includes the other values:

"clocks" column is count of masked clocks.

0690X00000896MrQAI.png

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.

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

Murat Sevil
Associate II

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.