Simple if
statements are very fast and won't affect performance much even when used in every looping of the loop.
Using an interrupt to implement something simple like if (!amp) amp = 10;
will actuallyprobably make things slower:
- something will have to keep track of the counter to generate an interrupt, and this something"something" takes time;MCU time, unless it is a peripheral;
- interrupts have overhead;
- on single-thread MCUs, interrupts stop regular code execution until they are done;
amp = 10;
will still have to be executed, in the regular code, or, if you must, in the interrupt.
A single, simple if
statement is done in less clock cycles than an interrupt plus whatever generates the interrupt.
You would gain more by getting rid of the function call to reset()
, but the compiler probably does that for you.
Also, I wouldn't know how to replace a regular if
with an interrupt, unless the counter is kept by a (timer) peripheral.