esp32 wrover devkit c - clock accuracy problems
Posted: Wed Apr 01, 2020 7:05 am
Hi, im trying to do some semi-accurate time measurements, using esp_timer_get_time function.
According to documentation esp_timer_get_time function returns time in microseconds. But when i'm doing some calculations (to be precise, counting AC mains pulses, or zero crossings of the AC sine wave), i get astonishing results. The frequency calculated can be 80 Hz, or 90Hz, depending on the CPU clock frequency setting in the menuconfig. The zero-crossing detection circuit is rather accurate, i tested it some time ago on arduino and got exact 100Hz [50Hz x 2], but now i feel like I'm going crazy. Dont have an oscilloscope or another ultimate way of checking the signal timing so it's mostly guessing.
So my questions:
- is there a good way to verify clock functions accuracy in ESP32, especially esp_timer_get_time
- what configuration options affect the frequencies / timing calculations done by esp time functions? Is it always pre-set correctly or are there timing differences between boards, different bus clock settings that you can get wrong? ARM-based boards have tons of clocks options and its a whole science to get this right, but esp32- i dont know.
According to documentation esp_timer_get_time function returns time in microseconds. But when i'm doing some calculations (to be precise, counting AC mains pulses, or zero crossings of the AC sine wave), i get astonishing results. The frequency calculated can be 80 Hz, or 90Hz, depending on the CPU clock frequency setting in the menuconfig. The zero-crossing detection circuit is rather accurate, i tested it some time ago on arduino and got exact 100Hz [50Hz x 2], but now i feel like I'm going crazy. Dont have an oscilloscope or another ultimate way of checking the signal timing so it's mostly guessing.
So my questions:
- is there a good way to verify clock functions accuracy in ESP32, especially esp_timer_get_time
- what configuration options affect the frequencies / timing calculations done by esp time functions? Is it always pre-set correctly or are there timing differences between boards, different bus clock settings that you can get wrong? ARM-based boards have tons of clocks options and its a whole science to get this right, but esp32- i dont know.