cancel
Showing results for 
Search instead for 
Did you mean: 

RTC Subsecond syncronization

mvonahnen
Associate III
Posted on February 20, 2017 at 20:04

I am trying to synchronize the RTC of a NUCLEO-L476RG board to a GPS.  I am using the 1PPS signal from the GPS to generate a timestamp.  I then use the LL_RTC_TIME_Syncronize function to adjust the subsecond counter.  I read the subsecond register right after that and I can see the value changes.  But each 1PPS time stamp occurs at almost the identical count on the subsecond register.  It is not exactly the same, so I know that the timestamp is occurring.

Here is the interrupt routine:

void

TAMP_STAMP_IRQHandler(

void

)

{

/* USER CODE BEGIN TAMP_STAMP_IRQn 0 */

/* USER CODE END TAMP_STAMP_IRQn 0 */

/* USER CODE BEGIN TAMP_STAMP_IRQn 1 */

//

printf

('\r\nTime Stamp IRQ Handler\r\n');

/* Get the TimeStamp interrupt source enable status */

if

(LL_RTC_IsEnabledIT_TS(RTC) != 0)

{

/* Get the pending status of the TIMESTAMP Interrupt */

if

(LL_RTC_IsActiveFlag_TS(RTC) != 0)

{

/* TIMESTAMP callback */

TimeStampEvent_Callback();

/* Clear the TIMESTAMP interrupt pending bit */

LL_RTC_ClearFlag_TS(RTC);

}

}

/* Clear the EXTI's Flag for RTC TimeStamp and Tamper */

LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_19);

/* USER CODE END TAMP_STAMP_IRQn 1 */

}

And here is the callback routine:

void

TimeStampEvent_Callback(

void

)

{

uint8_t

byte3;

uint8_t

byte2;

uint8_t

byte1;

uint8_t

byte0;

// WaitForSynchro_RTC();

rtc_sub_seconds = LL_RTC_TS_GetSubSecond(RTC);

urtc_sub_seconds = LL_RTC_TIME_GetSubSecond(RTC);

LL_RTC_DisableWriteProtection(RTC);

LL_RTC_TIME_Synchronize(RTC, LL_RTC_SHIFT_SECOND_ADVANCE, (

uint32_t

)0x10);

WaitForSynchro_RTC();

crtc_sub_seconds = LL_RTC_TIME_GetSubSecond(RTC);

byte3 = (

uint8_t

) ((rtc_sub_seconds >> 24) & 0x000000ff);

byte2 = (

uint8_t

) ((rtc_sub_seconds >> 16) & 0x000000ff);

byte1 = (

uint8_t

) ((rtc_sub_seconds >> 8) & 0x000000ff);

byte0 = (

uint8_t

) (rtc_sub_seconds & 0x000000ff);

printf

(

'TS

Subseconds

register: 0x%02x%02x%02x%02x\r\n'

,byte3, byte2, byte1, byte0);

byte3 = (

uint8_t

) ((urtc_sub_seconds >> 24) & 0x000000ff);

byte2 = (

uint8_t

) ((urtc_sub_seconds >> 16) & 0x000000ff);

byte1 = (

uint8_t

) ((urtc_sub_seconds >> 8) & 0x000000ff);

byte0 = (

uint8_t

) (urtc_sub_seconds & 0x000000ff);

printf

(

'Uncorrected

subseconds

register: 0x%02x%02x%02x%02x\r\n'

,byte3, byte2, byte1, byte0);

byte3 = (

uint8_t

) ((crtc_sub_seconds >> 24) & 0x000000ff);

byte2 = (

uint8_t

) ((crtc_sub_seconds >> 16) & 0x000000ff);

byte1 = (

uint8_t

) ((crtc_sub_seconds >> 8) & 0x000000ff);

byte0 = (

uint8_t

) (crtc_sub_seconds & 0x000000ff);

printf

(

'Corrected

subseconds

register: 0x%02x%02x%02x%02x\r\n'

,byte3, byte2, byte1, byte0);

}

In this version, I am just adjusting the subsecond register by a fixed amount (0x10).

1 ACCEPTED SOLUTION

Accepted Solutions
mvonahnen
Associate III
Posted on February 20, 2017 at 20:17

I found my issue, reinitializing the time reset the subsecond register.

View solution in original post

1 REPLY 1
mvonahnen
Associate III
Posted on February 20, 2017 at 20:17

I found my issue, reinitializing the time reset the subsecond register.