WiFi interfering with esp_timer High Resolution Timer

plajjd
Posts: 54
Joined: Thu Jul 05, 2018 11:47 pm

WiFi interfering with esp_timer High Resolution Timer

Postby plajjd » Sat Dec 22, 2018 4:47 am

I have a control application that needs to run every 500 us (2 kHz). I am using esp_timer() at 500 us, to run the control code. (I send a semaphore to the Control Task each time the esp_timer interrupt fires.) . I have the Control Task pinned to Core 1.

I also am using ESP-NOW (WiFi) on Core 0.

My problem is that when I initialize WiFi (on Core 0), the esp_timer interrupt is affected. It "jitters" by 100 us or more. (more than 20% error)

=> It appears that using ESP-NOW WiFi causes my 2 kHz timer interrupt to not be accurate.

Questions:

Can I run esp_timer() on Core 1 ONLY, so that it is not affected by the WiFi task(s) on Core 0?

Is there a way to configure the esp_timer, or the WiFi, so that the esp_timer is able to accurately run at 2 Khz?

Thanks!

Phil.
Last edited by plajjd on Sat Dec 22, 2018 5:00 am, edited 1 time in total.

plajjd
Posts: 54
Joined: Thu Jul 05, 2018 11:47 pm

Re: WiFi interfering with esp_timer High Resolution Timer

Postby plajjd » Sat Dec 22, 2018 4:59 am

Also, it appears the ESP-NOW and/or WiFi libraries are running at a higher priority than the esp_timer task.

Is it possible to increase the priority of the esp_timer operation?

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

Re: WiFi interfering with esp_timer High Resolution Timer

Postby ESP_igrr » Sat Dec 22, 2018 6:10 am

Hi plajjd, at the moment there is no option to pin esp_timer task to CPU1, but you can move Wi-Fi task to CPU1 instead: https://docs.espressif.com/projects/esp ... sk-core-id

However, keep in mind that Wi-Fi driver also uses esp_timer for its own callbacks, which might need some time to execute. So the timing of your callbacks might be affected not only by the Wi-Fi task, but also by other timer callbacks. (To check whether this is the case you can use a tool such as SystemView to analyze task switching behavior.)

Another option is to use a separate timer interrupt, such as Timer Group timer interrupt, to trigger execution of your task.

plajjd
Posts: 54
Joined: Thu Jul 05, 2018 11:47 pm

Re: WiFi interfering with esp_timer High Resolution Timer

Postby plajjd » Sat Dec 22, 2018 10:07 pm

Thank you! Using Timer Group 0 works much better than using esp_timer().

Are there any other subsystems that may be using Timer Group 0 that I should be aware of?

Also - does Timer Group 0 run on Core 0, or Core 1?

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

Re: WiFi interfering with esp_timer High Resolution Timer

Postby ESP_igrr » Sun Dec 23, 2018 10:24 am

No, Timer Group 0 timers aren't used by IDF components (aside from the timer group driver).

Interrupt will be called on the core where it is registered (i.e. esp_intr_alloc or timer_driver_install is called).

Who is online

Users browsing this forum: No registered users and 108 guests