Because of the Thanksgiving holiday in the U.S., TI E2E™ design support forum responses may be delayed the week of November 23.

This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM263P4-Q1: can I use two ISRs for the FOC algorithm

Part Number: AM263P4-Q1

Hi,

Can I use two ISRs for the FOC control algorithm? One is for current control (ADC) ISR, and another one resolver ISR. If I use two ISRs, what are the issues will arise? Is it recommended to use two ISRs? Please give a proper explanation 54ca9abf-3f11-44e4-b1f3-9407e203eff0.png 

  • Hi Kodari,

    Yes, it is often recommended and widely used, especially in high-performance motor control.
    In a standard FOC implementation:
    • The ADC ISR (Current Loop): This is typically synchronized with the PWM cycle. It triggers when the ADC finishes converting the phase currents. This ISR performs the Clarke/Park transformations and the PI control of $I_d$ and $I_q$. High frequency and low latency are critical here to ensure stability.
    • The Resolver/Position ISR (Speed/Position Loop): This handles the resolver signal processing (e.0.g., RDC - Resolver-to-Digital Conversion) and the outer speed/position loops. This loop can often run at a lower frequency than the current loop.
    If you implement two ISRs, you must manage the following technical challenges:

    A. Latency and Jitter (The Biggest Issue)

    If the Resolver ISR is high-priority and runs at the same time as the ADC ISR, it can "preempt" (interrupt) the ADC ISR.
    • The Risk: If the ADC ISR is delayed, your current control calculation will be based on "old" data or will finish too late for the next PWM cycle. This introduces phase lag and jitter, which can lead to current ripples, audible noise, or even instability in the motor.
    • The Fix: Ensure the ADC (Current Loop) ISR has a higher priority than the Resolver/Speed loop ISR.

    B. Data Consistency (Race Conditions)

    The two ISRs will likely share variables (e.g., the rotor angle $\theta$ calculated from the resolver is needed by the ADC ISR for Park transformations; the $I_q$ and $I_d$ currents from the ADC ISR are needed by the speed loop).
    • The Risk: If the ADC ISR reads a 32-bit angle variable while the Resolver ISR is halfway through writing to it, the ADC ISR might read a "corrupted" value (half old, half new).
    • The Fix: Use atomic operations, double-buffering, or briefly disable interrupts when updating shared multi-word variables to ensure data integrity.

    C. Computational Load (CPU Overhead)

    Running multiple high-frequency ISRs increases the context-switching overhead of the CPU.
    • The Risk: If both ISRs are too frequent, the CPU may spend more time "switching" between tasks than actually calculating the FOC algorithm, leading to "CPU starvation."
    • The Fix: Optimize the code and ensure the outer loop (Resolver/Speed) runs at a frequency significantly lower than the inner loop (ADC/Current).