GRTC Periodic interval + nrfx

Hi,

I recently found out about the Periodic interval feature on GRTC CC[0] and it seems like it would be quite useful for my application. Most of my code so far uses the nrfx drivers. Looking at the nrfx: GRTC driver page it seems that there are no functions available for that feature, but I do see some in the HAL section. What would be the best way to use the CC[0] channel in my code? Also how can I make sure that the channel is free to use and do I need to somehow reserve it so it doesn't accidentally get used elsewhere?

Regarding my application, I would use the INTERVAL register to auto increment the CC[0] register, but also sometimes increment it manually using CCADD. Is there also a safe way to decrement it while ensuring that I don't get an auto increment in between my read, subtract and write?

Best regards,
Sašo Domadenik

  • I noticed that the SYSCOUNTER will drift with respect to a timer that runs from the HFCLK. Is there any way I can prevent this drift?

    This is correct. The GRTC is synchronised towards the low frequency clock. When not active, the time is based solely on the low frequency clock. When active, it will use the HFCLK to be able to generate one tick approximately every microsecond, but the GRTC is in that case calibrated towards the low frequency clock at every low frequency clock tick. In practice, since the HFCLK is 16 MHz but the GRTC generates ticks with a 1 MHz resolution, the GRTC will in practice generate one tick with an interval between 14 and 18 HFCLK ticks, depending on the low frequency clock. This is to stay synchronised with the low frequency clock.

    That said, if you have HFXO started and let the GRTC be in active mode for a long time, the timing from GRTC will still follow the low frequency clock and not HFXO.

  •  do you have any information about the use of CC[0] by the Bluetooth stack?

  • Thanks for the detailed explanation. In retrospect, it makes sense for the GRTC to be synchronized to the LFCLK since that is the one which is always running, the HFCLK isn't even synchronized to itself since it is stopped and started. Since asking this question I have kind of figured this out myself, though I was never quite sure if that's how it actually works so this was helpful.

Related