auto update of epoch time

Hi all,

I'am sending  epoch time from nrf_connect(mobile) to nrf52840dk only once,

then i need to update epoch time  continuosly with nanosecond frequency

how can i do it

Regards

Tushar

  • Hi Tushar,

    Which exact resolution do you need? If you really need close to nanosecond resolution, then you will have to use a timer which is based on the HF clock. This is only 16 MHz though, and there are no higher frequency clocks available. Also, this will force the HF clock always on, so your device will not be low power.

    If you don't need as high resolution and needs the device to be low power, then it makes more sense to use an RTC based approach. The RTC is 32.768 kHz and the accuracy will be identical to the accuracy of the 32.768 kHz crystal you use on your board.

    In the latter case, if using the nRF5 SDK, the simplest way to do this is to use the app_timer library which is almost always used, and change it slightly so that the you can use the get_now() function from outside (see this post). This will then give you an always increasing 64 bit timer value. With this, just compare that with the time you got when you synced with a mobile phone, and you will effectively have the epoch time. If using nRF Connect SDK, you already have support for epoch time.

    Einar

  • Hi Einar Thorsrud,

    i want to give an epoch time for example 1641464227  from my mobile to nrf52840dk

    then i want the epoch time to increment continuously with time sync

    Regards

    Tushar

  • Hi Tushar,

    Are you using nRF5 SDK or nRF Connect SDK?

    If using nRF5 SDK get the local time at the same time as you get the time from the phone, and calculate the offset. Use that offset subsequently.

    If using the nRF Connect DK you have all this done for you, so use the available time utilities I linked to in my previous post (for instance, use timeutil_sync_state_update() when you get the time from the phone).

  • Hi,

    timeutil_sync_state_update() i have used this api can u please tell me how to give input to this api

    Regards

    Tushar

  • Hi Tushar,

    I was too quick typing my answer previously. The timeutil_timegm() or timeutil_timegm64() is what you want. This gives you the current "time" and you offset it with the value you got from the same function when you got the actual time from the phone. (You won't get nanosecond resolution in any case, though.)

Related