felixvanoost / Reflow-Oven-Controller

A reflow soldering oven controller based on an Arduino Uno with live temperature graph in Python.
6 stars 1 forks source link

ISR bloated #1

Open eda1-fiunam opened 1 year ago

eda1-fiunam commented 1 year ago

I've just discovered your project, congrats! It seems very interesting, although I don't know yet whether it works, but I guess so. The first thing I've noted is that you've placed a very intensive floating point math inside the ISR. Good programming practices say that one shouldn't bloat an ISR, but delegates the user code to a regular function. I'm working on a similar project but using Fuzzy logic and a 32-bit Cortex ARM microcontroller. I'm in the design phase, and when it's time to build the electronics I'll check your project out thoroughly (I have no doubts about its performance) because it's a gold mine. Greetings.

felixvanoost commented 1 year ago

Hey @eda1-fiunam, thanks for getting in touch! I'm glad to hear that you found the project interesting.

I wrote this code a long time ago as a student and would do things quite differently today. You're correct in saying that ISRs should be kept as short as possible to avoid scheduling issues when multiple tasks are operating. This isn't always an issue if the ISR is the only code being executed though, or if the background code that the ISR has higher priority over doesn't need to run at a fixed period (which is somewhat true of the state machine that's running in the loop() function here).

In terms of execution time, the arithmetic in the ISR is trivial on any modern microcontroller with an FPU. The slowest functions are probably Serial.print() and the 1D look-up pgm_read_word_near().

Good luck and happy hacking!

Felix