Accurate timing with ESP32

kfine100
Posts: 2
Joined: Wed May 20, 2020 7:00 am

Accurate timing with ESP32

Postby kfine100 » Wed May 20, 2020 7:21 am

I am trying to do accurate timing using the ESP32 64 bit counter which use the 80 MHz APB clock. I need accuracies of 1 ppm or better. If I use an external 40 MHz crystal with 1 ppm accuracy will the APB clock now have 1 ppm accuracy? Is the APB clock derived directly from the external 40 MHz crystal?

Thanks for any help.

ESP_igrr
Posts: 1654
Joined: Tue Dec 01, 2015 8:37 am

Re: Accurate timing with ESP32

Postby ESP_igrr » Wed May 20, 2020 9:44 am

Hi kfine100,

The APB clock is derived from the PLL, which may add some jitter but has the same long-term accuracy as the underlying XTAL clock source. So the answer will depend on what kind of timing you are trying to do, exactly. Are you measuring time intervals, and are these intervals long or short? Or are you trying to generate output with specific timing?

For short time intervals (less than 1 second), you may also need to account for the software latency when working with the timer registers. If your use case is related to timing relative to external signals, using the RMT or PCNT peripherals may give you better accuracy.

kfine100
Posts: 2
Joined: Wed May 20, 2020 7:00 am

Re: Accurate timing with ESP32

Postby kfine100 » Thu May 21, 2020 4:23 pm

Hi igrr

Thanks for your response.

Just to make sure I understand, could you confirm that when you say "underlying XTAL clock source" this means the 40 MHz external XTAL?

I understand the issue with the PLL. I believe this will add maximum jitter around the range of 1 x 40 MHz period, or 25 ns. If you think it is more, let me know.

What I am doing is measuring external intervals that last about a second, and I would like to do that to +/-1 us. Thus the 1 PPM requirement.

I did some measurements on the interrupt software delay and found 3.42 +/- 0.13 us. Since I am taking differences the constant term is not important, and the 130 ns is acceptable.

If you see any problem with my logic let me know. Otherwise, if the answer to my first question is yes, it looks like this is a good solution.

All the best, Kevin

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Swagger and 23 guests