Hi
Anyone have the sample cod for timer in esp32 which can can make an interrupt in every 1 micro second?
Thanks
Timer in esp32
Re: Timer in esp32
There is an example showing hardware timer usage in examples/peripherals/timer_group directory of ESP-IDF.
However the requirement to make the timer run with 1 microsecond interval will likely be too strict. Typical time for the interrupt handler to execute (enter the ISR, dispatch C handler, return from the ISR) at 240 MHz is around 1 microsecond, so if you happen to run any code in the ISR which takes a non-trivial amount of time, you will not be able to run an ISR each microsecond.
If you need such resolution for a short amout of time, your best bet is to disable interrupts (i.e. a enter critical section) and do timing based on the CPU cycle counter. If you need this resolution for longer periods of time, and you need to do IO, take a look at RMT and I2S peripherals. They may provide the solution to your problem without the CPU overhead.
However the requirement to make the timer run with 1 microsecond interval will likely be too strict. Typical time for the interrupt handler to execute (enter the ISR, dispatch C handler, return from the ISR) at 240 MHz is around 1 microsecond, so if you happen to run any code in the ISR which takes a non-trivial amount of time, you will not be able to run an ISR each microsecond.
If you need such resolution for a short amout of time, your best bet is to disable interrupts (i.e. a enter critical section) and do timing based on the CPU cycle counter. If you need this resolution for longer periods of time, and you need to do IO, take a look at RMT and I2S peripherals. They may provide the solution to your problem without the CPU overhead.
Who is online
Users browsing this forum: No registered users and 140 guests