Page 1 of 1

Where can I find the documentation for esp_timer_get_time()?

Posted: Sat Mar 02, 2019 10:52 pm
by akashdeepsingh
Hi,

I am looking to get time with nanoseconds precision. I know the function esp_timer_get_time() gives time in microseconds. I was hoping that I can modify it. Where can I find the source code/documentation to how it works.?

Thanks

Re: Where can I find the documentation for esp_timer_get_time()?

Posted: Sun Mar 03, 2019 1:13 am
by ESP_igrr
The source code along with some inline comments is here: https://github.com/espressif/esp-idf/bl ... er_esp32.c

esp_timer_impl_get_time in this file is the actual implementation of esp_timer_get_time.

Although if you only need to get current time in nanoseconds, and supporting DFS is not a concern, an implementation based on one of the Timer Group timers will be way more straightforward. This is because timer group timers are 64 bit, so you can ignore the issue of overflows (for 7.5 thousand years, at least).
That implementation is going to be, basically: start the timer with a prescaler of 1, and when you need to know the value of time in nanoseconds, read the counter and multiply by 12.5ns.

Re: Where can I find the documentation for esp_timer_get_time()?

Posted: Sun Mar 03, 2019 5:38 am
by akashdeepsingh
That implementation is going to be, basically: start the timer with a prescaler of 1, and when you need to know the value of time in nanoseconds, read the counter and multiply by 12.5ns.
Thanks, any do you have a sample on Github for this?