This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

RTC Inaccuracy

I'm finding fairly large lags with the RTC2 I'm using. I use an app_timer to sample the current RTC count value as a timestamp (MM:SS:Hundredth-of-a-second) and send it out via an HVX. However I'm noticing after about 2mins the RTC is lagging a reference time by almost a second. I have set the prescalar to 327 (to get ~10msec resolution), to capture fractions of a seconds. I don't use the interrupts except for on overflow, so I know its not an interrupt lag from a BLE event. Could the BLE traffic really interrupt my RTC counter get function enough to cause this drift?

I'm really at a loss how to get accuracy (millisecond) timestamps for HVX transmissions, almost seems impossible on this chip.

  • Sorry, this just isn't very clear to me. Does this mean I could assign an RTC timeout to sample the value in a TIMER? Since the TIMER values are abstracted this is all seems overly complex.

  • Dave - Yes, you can use PPI so that when the RTC's EVENT is triggered some TASK is started. But I'm more concerned with why this seems to have become so complex. The first issue is that you can't get 10ms times from a 327 pre-scaler value. For that matter, you can't get 1.000ms anything from a 32,768Hz clock. You can get a 1/1024th of a second, or 10/1024ths of a second, but those aren't even multiples of 1.000ms. One solution would be to count 1/1024ths of a second, and convert that to 1ms approximations. If you multiply by 1,000 and then divide by 1,024, you'll get something that's pretty close. If you wrap your counter at 1,024, so that you never have more than 1,024 "mibiseconds", the ((mibiseconds * 1000) / 1024) will never overflow and life will be just fine.

  • no Dave I meant absolutely nothing of the sort. Going back to my original answer have you actually measured the accuracy of your RTC using a GPIO yet and how accurate were your 'about 2 minutes and about almost a second' which I asked way back at the start.

  • Yes, an I've verify similar inaccuracy with the RTC. However the inaccuracy is affected by BLE traffic. Testing with different connection parameters and data transfer rates, sampling the RTC rarely so as to not be affect by BLE interrupts, I see variance between 1-4sec per minute. Worse with high BLE data thru put.

Related