How to handle multiple interrupts of the same clock rate?

One of the first things any literature says about using interrupts is 'keep the code small'. I was wondering if there are rules of thumb regarding how much is too much to fit inside a callback function, and what to do when it is indeed too much.

My code has a callback function using the hardware timer that needs several if statements, writes to a digital pin, flips a boolean, and calculates a value after reading a value from a table in program memory. All of these separate items are timing-critical, and won't work outside of the callback function (I've checked).

at present, the code works. However, I'm about to add a lot more code and know that I'll have to deal with this sooner or later.

Can anyone recommend a method for handling timing-critical functions that are/may be too large to fit inside of one callback function?

Thanks in advance.

Interrupts are ALWAYS prioritized, so if by chance two or more occur at the identical time, the highest priority interrupt goes first, then the next, and so on...

1 Like

First effort should be to ‘set a flag’, test a state, or ‘increment a counter’ in the ISR.
Then RETURN.

Later when the rush is over, process any accumulated events in your main() loop.

That main might get interrupted again, but you know your real-time stuff is being handled properly.

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.