Search code examples
embeddedreal-timeinterruptadc

Where to put calculations? Inside interrupt handler or main loop? (embedded realtime application)


I'm developing an embedded application for motor control and I have doubts on what to to with some calculations that transform ADC numeric values into signed physical values (Amps).

Should I make the calculations in the interrupt handler or should I just use the handler to set a global flag and make the calculations in the main loop when the flag has been set?

Thank you in advance.


Solution

  • There is no one-size-fits-all answer for this. It depends upon your timing requirements, existing interrupt load, etc.

    If it's a fairly simple multiply or something, then I would just do it in the interrupt and move on.

    Just make sure you know what you are doing and do not spend more time in your interrupt than you should.