Appropriately calibrate for RTC drift

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Appropriately calibrate for RTC drift

1,763 次查看
CMoran
Contributor III

I'm running an i.MX RT1170 series processor for a GUI application. The application happens to display a clock. I've noticed that the time I'm displaying lags behind my PC (connected to the internet) by around 6 seconds per day.

I've tried to enter a calibration value to adjust for this drift, but it appears that it's not being applied. Below is my initialization code for the RTC module:

/* High power module */
snvs_hp_rtc_config_t rtcConfig;
SNVS_HP_RTC_GetDefaultConfig(&rtcConfig);
rtcConfig.rtcCalValue = 0xf; // +15 counts per each 32768 ticks of the counter
rtcConfig.rtcCalEnable = true; // enable RTC calibration
SNVS_HP_RTC_Init(SNVS, &rtcConfig);
SNVS_HP_RTC_StartTimer(SNVS);

/* Coin-cell powered low power module */
...

/* Synchronize RTC time and date with SRTC */
SNVS_HP_RTC_TimeSynchronize(SNVS);

...

 

Originally we calculated the calibration value to be +2 counts per 32768 ticks of the counter:

6 seconds behind = missing approximately 6s* 32768 ticks/s = missing approximately 196608 ticks

196608 ticks / (seconds per day) = 196608 ticks / (24hr/day * 60min/hr * 60s/min) = 2.275 ticks/s

Therefore every second and additional 2 counts need to be added to the RTC counter. After adding this it appeared to have no change. So I changed the value to +15 counts per 32768 ticks of the counter to see if I can notice a difference. Once again I can't see a change.

Is the code snippet above the appropriate way to use the RTC calibration value?

CMoran_0-1737561803859.png

Here's what the processor's reference manual says on the subject.

标记 (2)
0 项奖励
回复
3 回复数

1,748 次查看
EdwinHz
NXP TechSupport
NXP TechSupport

Hi @CMoran,

What do you mean you don't see any changes? Do you see the register's values change on the peripherals+ window? It should look something like this:

EdwinHz_0-1737584984294.png

I did the test on my side and are seeing increases of 15 ticks in between some counts, so I know it is working for me. How are you measuring your results?

BR,
Edwin.

0 项奖励
回复

1,735 次查看
CMoran
Contributor III

I do see this change in the Peripherals+ window too.

I have a GUI I setup for testing this, with a calendar to select a date, 2 rollers to select the hours and minutes (seconds default to 0), and a button to set the date and time. I synchronize the GUI with my PC by pressing the button the moment the minute changes. When I come into work the next day the RTC will be 6 seconds behind the clock on my PC despite changing the RTC calibration value. My observations would be like so:

No calibration, after 24hrs the clock is approximately 6 seconds behind.

+2 calibration, after 24hrs the clock is approximately 6 seconds behind.

+15 calibration, after 24hrs the clock is approximately 6 seconds behind.

0 项奖励
回复

1,723 次查看
CMoran
Contributor III
So I came in to work after letting the RTC run for another 24hrs. This time it is ahead of what my PC time is showing, the expected results for a +15 calibration value. I did not change my code from the last run. The only difference was that I placed a breakpoint right before the RTC initialization to confirm in the Peripherals+ window that the values I set were being assigned to the registers.
0 项奖励
回复