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.

Parents
  • No the BLE traffic doesn't impact the RTC2 counter in any way. It's hardware. So what's your LF clock source for a start, how accurate is that? Given your use of 327 you should be lagging about 1/4 second after 2 minutes. So how accurate is your 'about 2 minutes' and how accurate is your 'almost a second'? Because if it's really 4 minutes and it's really 1/2 second .. that's about to be expected.

    You should set up a bare board test of your clock source outputting to a GPIO using hardware, PPI whatever you have and measure with some kind of signal analyser. In fact you could fairly easily add the PPI GPIO toggle to your current implementation and count rollover times or something, that will give you a reasonable way of determining what the RTC is counting.

    You seem to have inordinate difficulties with something very simple, both using the RTC and the HF clock (I saw the last post). It really shouldn't be hard at all.

Reply
  • No the BLE traffic doesn't impact the RTC2 counter in any way. It's hardware. So what's your LF clock source for a start, how accurate is that? Given your use of 327 you should be lagging about 1/4 second after 2 minutes. So how accurate is your 'about 2 minutes' and how accurate is your 'almost a second'? Because if it's really 4 minutes and it's really 1/2 second .. that's about to be expected.

    You should set up a bare board test of your clock source outputting to a GPIO using hardware, PPI whatever you have and measure with some kind of signal analyser. In fact you could fairly easily add the PPI GPIO toggle to your current implementation and count rollover times or something, that will give you a reasonable way of determining what the RTC is counting.

    You seem to have inordinate difficulties with something very simple, both using the RTC and the HF clock (I saw the last post). It really shouldn't be hard at all.

Children
  • It shouldn't be ;) though to be fair the PPI module is quite under documented for usage without GPIOTE. Its fairly straight forward for connect to GPIOs, but not for internal time keeping usage

  • don't really know what else you can say about PPI, you choose any EVENT register you like which you would check with if( NRF_XX->EVENT_YY != 0 ) and put that in the source and any TASK register you'd usually set with NRF_AA->TASK_BB=1 and put that in the destination. Then enable it.

    The occurrence of your EVENT will then trigger your TASK. It's as if you had your own little hardware thread going

    while(true)
    {
        if(NRF_XX->EVENT_YY)
        {
            NRF_XX->EVENT_YY=0;
            NRF_AA->TASK_BB = 1;
        }
    }
    

    in the background.

  • 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.

Related