Timer in esp32

amalamal
Posts: 23
Joined: Mon Dec 12, 2016 7:07 am

Timer in esp32

Postby amalamal » Mon Feb 27, 2017 11:39 am

Hi

Anyone have the sample cod for timer in esp32 which can can make an interrupt in every 1 micro second?


Thanks

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

Re: Timer in esp32

Postby ESP_igrr » Mon Feb 27, 2017 1:14 pm

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.

Who is online

Users browsing this forum: Baidu [Spider] and 38 guests