ISR behavior questions

Hello Everyone!

I was looking for a search button, but couldn't find it :-/

Just a few simple questions about how sketches handle interrupts.

Will an interrupt function be called during ANY function? As in, while my sketch is running its various functions outside of loop(), will the interrupt still be active?

When the conditions causing the interrupt end, will the sketch exit the interrupt function called by it immediately? Or, will it finish the function?

At the end of the function called by the interrupt, will the main loop() continue at the point where the interrupt happened, or start at the beginning?

Thank you!!

I was looking for a search button, but couldn't find it

It's up there, on the right, and is labelled "search"

It's up there, on the right, and is labelled "search"

oops! why would they hide it in that box next to the "search" button :wink:

I am not an expert but use interrupts quite a bit .. here is my input from usage - not manuals. If any of this is incorrect .. someone please chime in.

A very important point about interrupts. The code inside an interrupt routine should be very short. The rule as stated by other posters is "get it, do your code and get out". I usually just set variables in the interrupt routines and then use those variables in the loop. If you attempt to do too much in an interrupt your loop will slow or even stop all together.

Will an interrupt function be called during ANY function? As in, while my sketch is running its various functions outside of loop(), will the interrupt still be active?

An interrupt is priority .. so it will be called and the loop / other code will stop while running.

When the conditions causing the interrupt end, will the sketch exit the interrupt function called by it immediately? Or, will it finish the function?

The interrupt will end when the function ends. If the function is longer than the interrupt period .. your code will (or at least may) stop responding all together.

At the end of the function called by the interrupt, will the main loop() continue at the point where the interrupt happened, or start at the beginning?

Where it left off.

I know every one talks about keeping code in interrupt routines short, but it is possible and often practical to put ALL your code in interrupts.
To keep hardware and pin count cost down, my last few projects have used direct multiplexed led displays and push buttons for the user interface.
This necessarily means an interrupt driven system. With a period of 2mSec or so you have a nice stable display up to eight digits and nice simple de-bouncing of lots of switches. These instructions occupy only a tiny part of the available time period and one can pack a lot of code in the remaining time available.
You can also suspend your routine safely before an interrupt is due and continue the routine in subsequent interrupt period safe in the knowledge that it won't be interrupted at an unknown point; or you can run any amount of less critical stuff outside the interrupt code. ie when the interrupt code is finished and the system is awaiting the next interrupt. Of course then you cant predict where your code will be when the int takes place.

As a relative amateur, I have asked a few questions of the forum and have learnt much from this very valuable resource. I hope someone may take advantage from this point of view.

hmm, seems to be some different styles of using code. This is why I enjoy looking at other people's code- its sort of like hearing someone speak with an accent different than your own.

well for now, I'm still learning to talk!

well for now, I'm still learning to talk!

Now it's time to learn when to interrupt or not interrupt while talking is going on. ;D

That's probably a pretty poor software joke, no?

Lefty