Fastest system timer/clock
Posted: Sun Oct 09, 2022 3:04 am
I've written some asynchronous code (using the Arduino core) that relies on the number of microseconds that have passed to perform certain actions.
I am currently using esp_timer_get_time() to get the number of microseconds, but there appears to be a fair bit of overhead to that function: when I call it repeatedly in the loop, depending on my clock frequency, it takes anywhere from 10-30us just to return.
I'm hoping for something a little more granular - optimally something that takes <1us to return. I was hoping I could find the registers that the system clock updates every tick and just read the register holding the lower 32 bits (since I know there are fancy things that are going on to freeze-and-read to get all 64 bits in sync), then divide by clock speed (since it doesn't vary for my application).
For 240mhz, I show that 32 bits should hold ~17.9 seconds before overflow, which should be plenty for me. Unfortunately, I can't figure out where to access this register. I've tried some of the FRC registers that I dug around, but they didn't seem to be changing at all. Also looked at other TIM0 registers, but they weren't changing either. I read *something* about needing to prompt an update by writing a register, but I figured I'd ask here if anybody had more information.
I'm not dead set on reading a system clock register, I just need a way of asynchronously and accurately tracking time, ideally with 1us resolution (though anything better than 10us is an improvement).
Thanks!
I am currently using esp_timer_get_time() to get the number of microseconds, but there appears to be a fair bit of overhead to that function: when I call it repeatedly in the loop, depending on my clock frequency, it takes anywhere from 10-30us just to return.
I'm hoping for something a little more granular - optimally something that takes <1us to return. I was hoping I could find the registers that the system clock updates every tick and just read the register holding the lower 32 bits (since I know there are fancy things that are going on to freeze-and-read to get all 64 bits in sync), then divide by clock speed (since it doesn't vary for my application).
For 240mhz, I show that 32 bits should hold ~17.9 seconds before overflow, which should be plenty for me. Unfortunately, I can't figure out where to access this register. I've tried some of the FRC registers that I dug around, but they didn't seem to be changing at all. Also looked at other TIM0 registers, but they weren't changing either. I read *something* about needing to prompt an update by writing a register, but I figured I'd ask here if anybody had more information.
I'm not dead set on reading a system clock register, I just need a way of asynchronously and accurately tracking time, ideally with 1us resolution (though anything better than 10us is an improvement).
Thanks!