Timer in esp32
Posted: Mon Feb 27, 2017 11:39 am
by amalamal
Hi
Anyone have the sample cod for timer in esp32 which can can make an interrupt in every 1 micro second?
Thanks
Re: Timer in esp32
Posted: Mon Feb 27, 2017 1:14 pm
by ESP_igrr
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.