Reliable GPTimer interrupts <50µs

vinci1989
Posts: 28
Joined: Mon Oct 08, 2018 6:07 pm

Reliable GPTimer interrupts <50µs

Postby vinci1989 » Sat Dec 17, 2022 8:46 pm

Is there a way to get reliable GPTimer interrupts in the ~50µs range which are not blocked by WiFi? I've a project which relies on accurate timings and I would prefer to handle those in an "per interrupt" fashion and not using the RMT peripheral or similar. However once WiFi is enabled and data is transmitted the interrupts can be blocked up to several milliseconds! So basically with the default settings of having WiFi on core0 you can kiss any realtime behavior goodbye...
blocking_wifi_core0.png
blocking_wifi_core0.png (46.65 KiB) Viewed 2397 times

Things get better when moving WiFi and TCP/IP to core1 by using:
CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1=y
CONFIG_LWIP_TCPIP_TASK_AFFINITY_CPU1=y

but the jitter is still insane... This is supposed to be a 50µs toggle...
50us_wifi_core1.png
50us_wifi_core1.png (35.86 KiB) Viewed 2397 times
Any suggestions how to drastically improve this?

A6ESPF
Posts: 28
Joined: Tue Dec 10, 2019 12:16 pm

Re: Reliable GPTimer interrupts <50µs

Postby A6ESPF » Sat Dec 17, 2022 10:28 pm

I'm not sure if this will help, but try disabling Wi-Fi power saving mode by calling esp_wifi_set_ps(WIFI_PS_NONE) before esp_wifi_start(). That has helped me before with interrupts on specific ESP32 pins.

vinci1989
Posts: 28
Joined: Mon Oct 08, 2018 6:07 pm

Re: Reliable GPTimer interrupts <50µs

Postby vinci1989 » Sun Dec 18, 2022 10:50 am

A6ESPF wrote:
Sat Dec 17, 2022 10:28 pm
I'm not sure if this will help, but try disabling Wi-Fi power saving mode by calling esp_wifi_set_ps(WIFI_PS_NONE) before esp_wifi_start(). That has helped me before with interrupts on specific ESP32 pins.
Thanks but sadly this didn't help.

This did though:
https://docs.espressif.com/projects/esp ... #iram-safe
By default, the GPTimer interrupt will be deferred when the cache is disabled because of writing or erasing the flash. Thus the alarm interrupt will not get executed in time, which is not expected in a real-time application.

There is a Kconfig option CONFIG_GPTIMER_ISR_IRAM_SAFE that will:
[*] Enable the interrupt being serviced even when the cache is disabled
[*] Place all functions that used by the ISR into IRAM 2
[*] Place driver object into DRAM (in case it is mapped to PSRAM by accident)

This will allow the interrupt to run while the cache is disabled, but will come at the cost of increased IRAM consumption.

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 117 guests