espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.51k stars 7.39k forks source link

Multiple Timers on ESP32 #1195

Closed kszere closed 5 years ago

kszere commented 6 years ago

Hardware:

Board: TTGO LORA SX1278 ESP32 0.96 OLED 16 Mt bytes (128 Mt bit) 433Mhz for arduino Core Installation/update date: 07/03/2018 IDE name: Atom + PlatformIO Upload Speed: 115200

Description:

Sketch:

https://github.com/pcbreflux/espressif/blob/master/esp32/arduino/sketchbook/ESP32_multitimer/ESP32_multitimer.ino

Guru Meditation Error: Core  0 panic'ed (Interrupt wdt timeout on CPU1)
Register dump:
PC      : 0x400852cd  PS      : 0x00060034  A0      : 0x800858bb  A1      : 0x3ffc0590
A2      : 0x3ffc10f8  A3      : 0x00000000  A4      : 0x00000005  A5      : 0x00000020
A6      : 0x00000020  A7      : 0x00000000  A8      : 0x0000cdcd  A9      : 0x0000cdcd
A10     : 0xb33fffff  A11     : 0x0000abab  A12     : 0x00060021  A13     : 0x00000001
A14     : 0x00060021  A15     : 0x3ffc6c78  SAR     : 0x0000001d  EXCCAUSE: 0x00000006
EXCVADDR: 0x00000000  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000

Backtrace: 0x400852cd:0x3ffc0590 0x400858b8:0x3ffc05b0 0x4008673f:0x3ffc05d0 0x40086491:0x3ffc05f0 0x4008167a:0x3ffc0600 0x400d59f7:0x00000000

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:812
load:0x40078000,len:0
load:0x40078000,len:11404
entry 0x40078a28
beegee-tokyo commented 6 years ago

Try the new Ticker library (nearly the same as on ESP8266). Ticker. Works fine for me with more than 4 timers/tickers.

atanisoft commented 6 years ago

I also use all four hardware timers without issues. If you need more timers the Ticker library referenced above is good for that. For my use case I don't know that Ticker is suitable, as part of each invocation of the timer the period changes based on external factors.

kszere commented 6 years ago

@beegee-tokyo Thanks for "Ticker". How use 4 HW Timers without crash? In my code, functions take something 2 sec and also something 10 sec. It crash my ESP.

sansillusion commented 6 years ago

From my understanding (I might be wrong), you should use the timers to set variables and act upon it in the main loop so the delay will be in main loop not timers functions.

atanisoft commented 6 years ago

With hardware timers you must do whatever tasks you want to do quickly, the shorter amount of time in the ISR the better. As @sansillusion suggests, setting variables or toggling a GPIO pin is about the max you should really be doing. In my case I am triggering the various hardware timers at ~58uS, ~116uS, ~98uS or 196uS. The time between ISR invocations depends on the data being converted to a digital signal on a pair of GPIO pins.

beegee-tokyo commented 6 years ago

@kszere what I do is

I made a kind of tutorial Using the multitasking capabilities of the ESP32 / FreeRTOS

modulab commented 6 years ago

Hello , is it possible to go any higher that 40mhz with the timer resolution? I need about 50 mhz to time an intrerupt.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 5 years ago

This stale issue has been automatically closed. Thank you for your contributions.