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

How can get current time in microsecond same as micros() function arduino

Hello Everyone,

I am working on nRF51 can any one tell me how can i get current time in microsecond? micros() return current microsecond time in arduino. I wants same functionality in nRF51.

Kindly, Any one help me.

Regards, Rajneesh

Parents
  • Micros() in Arduino will give you the number of microseconds since the Arduino board began running the current program.

    You can do this with TIMER1 or TIMER2:

    • At startup, initialize the timer at 1MHz (counting microseconds) and start it.
    • In the Micros() function, trigger the CAPTURE task and return the captured value.

    TIMER1 and TIMER2 on nRF51 are 16 bit timers, so you will overflow after 65.5ms (unlike the one in Arduino that will overflow after about 70 minutes (32 bit)). You can handle this by for example enabling interrupt and clear the timer (using shorts) on compare event. In the interrupt increment a variable that will be added in the micros function. The amount of time added will depend on the compare value that will trigger the interrupt/clear.

    Running the timer peripheral continuously will increase the current by a significant amount (about 500-600uA compared to sleep current). Therefore I would suggest using RTC instead. The problem with this is that the maximum resolution of the RTC is about 30.5us as it uses the 32KHz (actually 32768Hz) clock. If you are fine with this resolution you should use it. The app_timer module has functions for getting the current value of the RTC. The RTC is 24 bits, so with 30.5us resolution the RTC will overflow after 512 seconds.

    For more info see the Reference Manual TIMER and RTC chapters.

  • Any idea about primary osillator? how to configute? start and capture?

Reply Children
No Data
Related