cancel
Showing results for 
Search instead for 
Did you mean: 

Rtc sync with Remote clock (Gps)

bhargavi ale
Associate II
Posted on October 24, 2017 at 14:59

Hi community,

If any face this issue earlier, please help me out.

I am working on stm32f417 board. Right now Am trying to sync rtc time with gps timing, but Am seeing drift in subseconds field of rtc.

Am programming the shift register of rtc every 10sec & reading rtc time in wakeup timer callback fun every one second.

Here is the my synchronzing code.

int8_t Sync_RTC_GPS()

{

static int sec_10 = 0;

RTC_TimeTypeDef gTime;

RTC_DateTypeDef gDate;

HAL_RTC_GetTime(&hrtc, &gTime, RTC_FORMAT_BIN);

HAL_RTC_GetDate(&hrtc, &gDate, RTC_FORMAT_BIN);

prev_ss = current_ss;

current_ss = gTime.SubSeconds;

count++;

sec_10++;

/*

* Skipping calculation of delta for the first time

*/

if(count == 2)

{

delta_time = current_ss - prev_ss;

count = 1;

if(sec_10 == 10)

{

   sec_10 = 0;

   if(delta_time != 0)

   {

   if(delta_time > 0)

   {

     HAL_RTCEx_SetSynchroShift(&hrtc, RTC_SHIFTADD1S_RESET, delta_time );

   }

   else if(delta_time < 0)

   {

      HAL_RTCEx_SetSynchroShift(&hrtc, RTC_SHIFTADD1S_SET, 1 - delta_time);

   }

    return 1;

}

else

{

/*

* synchronized

*/

return 0;

}

}

}

return 0;

}/*END OF Sync_RTC_GPS()*/

//================================================
4 REPLIES 4
bhargavi ale
Associate II
Posted on October 24, 2017 at 15:17

Hi All,

In above post Am calling 

Sync_RTC_GPS() in pps interrupt context.

This is the log for rtc sync with Gps. I observed like, when transition from 59 sec to 0 sec the drift is happening.

18:41:50:2

18:41:51:2

18:41:52:2

18:41:53:2

18:41:54:2

18:41:55:2

18:41:56:2

18:41:57:2

18:41:58:2

18:41:59:2

18:42:0:25

18:42:1:25

18:42:2:25

18:42:3:25

1

8:42:4:25

18:42:5:25

18:42:6:25

18:42:7:25

18:42:8:25

18:42:9:25

18:42:10:2

18:42:11:2

18:42:12:2

18:42:13:2

.

.

.

.

18:42:50:2

18:42:51:2

18:42:52:2

18:42:53:2

18:42:54:2

18:42:55:2

18:42:56:2

18:42:57:2

18:42:58:2

18:42:59:2

18:43:0:25

18:43:1:25

18:43:2:25

18:43:3:25

18:43:4:25

18:43:5:25

18:43:6:25

18:43:7:25

18:43:8:25

1

8:43:9:25

18:43:10:2

18:43:11:2

18:43:12:2

18:43:13:2

Posted on October 24, 2017 at 17:34

What is the RTC clock source? Can you tune/calibrate that? Can you change the prescaler?

Personally, I'd clock TIM2 at its maximal rate, use PWM Input to benchmark the 1PPS, and then compute sub-second from TIM2->CNT vs TIM2->CCR1 and use TIM5 to count seconds.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
AVI-crak
Senior
Posted on October 24, 2017 at 21:34

Calibration of the real-time clock does not change the frequency of the quartz, but generates additional pulses and passes the controlled number of pulses past the main clock counter. RTC_CALR

bhargavi ale
Associate II
Posted on October 25, 2017 at 09:51

Hi,

Thanks for your reply.

I am using LSE clock i.e., 32.768 KHz & didn't try by changing the prescalar value. I will try that.