Chat freely about anything...

User avatar
By Alex P
#24977 Hello,

I'm having trouble using any of the timers available to the ESP. I have tried the software timer described in the SDK documentation and the Ticker lib available for the Arduino IDE (which I assume uses the same functions) - both throw:

Code: Select allException (9):
epc1=0x401014ea epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000003 depc=0x00000000

ctx: sys
sp: 3ffffd90 end: 3fffffb0 offset: 01a0

>>>stack>>>
3fffff30:  00000001 00000000 402014c0 000000c8 
3fffff40:  3ffea080 40204718 3ffeb1b0 000135ec 
3fffff50:  3ffe864c 3ffe9e7c 3ffeb1b0 4020233d 
3fffff60:  3fff5148 00000000 00000000 3fff1c60 
3fffff70:  00000000 40211c3b 3ffec09c 3ffebd10 
3fffff80:  3fffdcb0 00000000 3fff4e78 40211c3b 
3fffff90:  40211c8e 3fffdab0 00000004 40201bad 
3fffffa0:  40000f49 40000f49 3fffdab0 40000f49 
<<<stack<<<

 ets Jan  8 2013,rst cause:4, boot mode:(1,2)

wdt reset


I have also tried multiple examples and short commands like prints to serial work fine, however functions that take longer to execute seem to trigger the hardware watchdog (is that what exception code 9 stands for?). What seems strange to me is that I have executed the exact same function in the main loop without any resets, so it seems logical to me that if it worked in main loop it should work in timed interrupts.

So I guess my question is if I am supposed to turn off the hardware wdt (is it even possible?) when executing the callback function, or is there something else I should be doing to run anything that takes more than 3ms to execute?

PS any information about the wdt would be appreciated
User avatar
By kolban
#24998 Howdy Alex,
Re: Exception code 9

It means "LoadStoreAlignmentCause". I did some study on exception handling and how to debug and wrote that up in my book of notes ... see:

http://neilkolban.com/tech/esp8266/

And search in the book for "Exception".

Neil
User avatar
By eriksl
#25226 I am fairly confident it's the same reasoning error that lots of people here make, because they're used to an mcu they have full control over and runs a single thread. The ex8266 isn't like that, your code must co-exist with code from the sdk and both need to run frequently to keep a.o. the wlan subsystem running.

So... Don't start a "main loop" from user_init, don't go doing all kinds of lengthy operations from an interrupt or timer callback. The watchdog will bark. Actually the watchdog is not your enemy. Some people go and try to defy or mislead the watchdog and learn it doesn't help. The watchdog is not the problem. Bad code is.

Rewrite your code so it never runs for an extended period of time. Do the preparations and "post" to your background task, which can finish the job. In the meantime the sdk code can run and do it's work. If the task is lengthy, break the loop, have the background task "post" to itself and continue the work when called again.

It's really just like an operating system with cooperative multitasking, where you can't hog the cpu as well. Think windows 3.1, it very much resembles that concept.