Skip to main content
added 3 characters in body
Source Link
ocrdu
  • 1.8k
  • 3
  • 11
  • 24

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.

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 actually make things slower:

  • something will have to keep track of the counter to generate an interrupt, and this something takes time;
  • interrupts have overhead;
  • on single-thread MCUs, interrupts stop 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.

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 probably make things slower:

  • something will have to keep track of the counter to generate an interrupt, and this "something" takes 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.

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.

added 3 characters in body
Source Link
ocrdu
  • 1.8k
  • 3
  • 11
  • 24

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 actually make things slower:

  • something will have to keep track of the counter to generate an interrupt, and this something takes time;
  • interrupts have overhead;
  • on single-thread MCUs, interrupts stop 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.

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 actually make things slower:

  • something will have to keep track of the counter to generate an interrupt, and this something takes time;
  • interrupts have overhead;
  • 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.

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 actually make things slower:

  • something will have to keep track of the counter to generate an interrupt, and this something takes time;
  • interrupts have overhead;
  • on single-thread MCUs, interrupts stop 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.

added 3 characters in body
Source Link
ocrdu
  • 1.8k
  • 3
  • 11
  • 24

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 actually make things slower:

  • something will have to keep track of the counter to generate an interrupt;interrupt, and this something takes time;
  • interrupts have overhead;
  • 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.

Using an interrupt to implement something simple like if (!amp) amp = 10; will actually make things slower:

  • something will have to keep track of the counter to generate an interrupt;
  • interrupts have overhead;
  • 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. 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.

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 actually make things slower:

  • something will have to keep track of the counter to generate an interrupt, and this something takes time;
  • interrupts have overhead;
  • 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.

added 3 characters in body
Source Link
ocrdu
  • 1.8k
  • 3
  • 11
  • 24
Loading
Source Link
ocrdu
  • 1.8k
  • 3
  • 11
  • 24
Loading