-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Interrupts setuped with attachInterrupt
are very slow.
#21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I don't have access to my signal generator and scope today, so did a quick test by touching gpio2 with a ground wire. This generates a random signal on the input pin. At the moment I can't really think of a reason for the behaviour you see. But I need to check with a scope to be sure.
|
I get the same results if I touch the ground. That's really strange. Are there some periodically scheduled "background" tasks that could block the interrupt for a longer delay?
If you could check it, it would be cool. If it's working for you I know the error must be somewhere else. While browsing the code I noticed that most ESP8266 firmware set some special register settings when enabling interrupts: https://github.com/zazolabs/esp8266_easyintr/blob/master/easyintr.c#L110-L114 I can't find any docs about that, but I think the Arduino lib is missing this and this could lead to errors on other scenarios where the pin was set as an output some time before its used as an interrupt. |
There are other tasks running on the chip which deal with WiFi and TCP/IP processing. But these are tasks, not interrupt handlers, so they shouldn't be blocking GPIO interrupts.
While you're at it, could you please try this version of
and check if it breaks anything? |
does not break anything. Still same results like before. |
Some more quirks: Following try seems to be crash the module:
It seems to keep working with MAX_TIMINGS set to 64. |
I see you're calling Serial.print from the interrupt. Serial.print is interrupt-driven, so it is "fire and forget" most of the time, unless the TX buffer overflows. When it does, it blocks hard until it gets a TX_EMPTY interrupt, then it puts more data into the buffer. There's ets_printf which doesn't buffer and you can use it from interrupts. It may loose some characters though. |
@igrr Which header needs to be included to use the ets_printf function? |
@iMarvinS as my previous post in this topic says:
|
Problem solved. The voltage source was not strong enough. @igrr Thank you very much for this great project and your support. |
Something seems to be wrong with the way how interrupts are handled.
I'm trying to record pulses of length 250-2000 micros. Example sketch:
But this outputs something like:
I exprected numbers around 250-2000. It's stange that its almost all time a longer dealy and then a shorter. I double checked the wiring and the interrupts only occure with connected sensor.
I did the same using nodemcu (using
gpio.trig
) and got ver accurate timings.Any ideas what is going wrong here?
The text was updated successfully, but these errors were encountered: