Timer groups documentation

Gardin
Posts: 31
Joined: Fri Dec 13, 2019 4:53 pm

Timer groups documentation

Postby Gardin » Mon Dec 30, 2019 7:38 pm

Hi all,

I'm currently working in a project that involves using a dimmer, and to do so I have to precisely count a time period after an external interrupt caused by the main voltage frequency, (60 Hz * 2) got trigered.
I'm currently using the TIMER_0 of the TIMER_GROUP_0, since I noticed that the High Resolution Timer is less precise, don't know why... And that is working fine.

But when I'm also connected to the wifi and the wifi fail, and so, has to automatically reconnect through an event group, the esp32 crashes, with the following message:
Guru Meditation Error: Core 0 panic'ed (Cache disabled but cached memory region accessed)
.

My guess is that other resources sharing the same Timer is causing the issue, and maybe putting the wifi task on another core can solve this...

But what I would like to know is which other resources use these timers? I've seen some people talking about timer priorities and levels which aparently can be set through the menuconfig... Where can I get some solid documentations about such things?

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

Re: Timer groups documentation

Postby ESP_igrr » Thu Jan 02, 2020 4:47 pm

This does not indicate there is a conflict with some other module using the same timer. In fact, Timer group timers are not used by other resources in ESP-IDF (such as Wi-Fi).

The issue may be related with the fact that you are designating an interrupt as being placed into IRAM, but then calling a function which is not in IRAM from the ISR.

Here is an explanation of IRAM attribute of the ISR: https://docs.espressif.com/projects/esp ... t-handlers and https://docs.espressif.com/projects/esp ... t-handlers.

The specific place in the code which causes the issue can be found using IDF monitor. It will decode the backtrace into code locations. More on this here: https://docs.espressif.com/projects/esp ... -backtrace
Same page contains a reference of various panic reasons, including the one you have encountered, "Cache disabled but cached memory region accessed": https://docs.espressif.com/projects/esp ... n-accessed

Gardin
Posts: 31
Joined: Fri Dec 13, 2019 4:53 pm

Re: Timer groups documentation

Postby Gardin » Thu Jan 02, 2020 5:10 pm

First of all, thanks to the fast reply!

Yesterday I figured it out, and as you said it's because I was calling functions that were not in hte IRAM... I was reloading the timer on every external interrupt, therefore trying to access functions that during the wifi reconnection was not in the iCache...

As I was suspecting there are smarter ways of achieving what I wanted, I found this topic https://github.com/espressif/arduino-esp32/issues/1069 about DelayMicroseconds (Arduino IDE) inside an ISR. Which have several explanation of the IRAM_ATTR and also a suggestion about pre configuring a Timer outside the ISR and just loading the value for the timer from the ISR...

But what about timer priorities and levels? Are there such things?

Another thing that I'm currently wondering if it's safe to use

Code: Select all

GPIO.out1_w1ts.data
and

Code: Select all

GPIO.out1_w1tc.data
to set and clear a GPIO state inside the ISR, should I oppened a separate question for this?

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

Re: Timer groups documentation

Postby ESP_igrr » Fri Jan 03, 2020 9:41 am

Yes, GPIO.outX_w1ts.data and GPIO.outX_w1tc.data are safe to use from an ISR.
But what about timer priorities and levels? Are there such things?
Interrupts can be assigned to one of a few levels (1, 2, 3). There are also high-level interrupts (levels 4 and above), but ISRs for these are typically written in assembly. For example, if you assign the interrupt to level 2, then it will preempt any other level 1 interrupt. Interrupt level can be configured as a flag when calling either esp_intr_alloc function, or timer_isr_register if you are using the timer driver. The definitions of different interrupt level flags can be found here: https://docs.espressif.com/projects/esp ... LAG_LEVEL1.

Gardin
Posts: 31
Joined: Fri Dec 13, 2019 4:53 pm

Re: Timer groups documentation

Postby Gardin » Sat Jan 04, 2020 4:12 pm

Got it!

Thanks a lot for your help!

Gardin.

Who is online

Users browsing this forum: Bing [Bot] and 129 guests