End Node Virtualization of PMSM FOC on MCSPTR2AK396 Motor Control Kit with S32K396

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

End Node Virtualization of PMSM FOC on MCSPTR2AK396 Motor Control Kit with S32K396

michalvidlak
NXP Employee
NXP Employee
4 0 2,801

WHAT IS PMSM FOC?

In the world of electric motor control, achieving high efficiency and precision is crucial, especially in applications such as electric vehicles, robotics, and industrial automation. This is where the FOC of PMSM comes into play. FOC, also known as vector control, allows for independent and precise control of motor torque and magnetic flux.

A PMSM is a type of synchronous motor where the rotor's magnetic field is generated by permanent magnets instead of windings. This design offers higher efficiency and better performance compared to other motor types. However, controlling a PMSM effectively requires sophisticated techniques due to its non-linear behavior and the need for precise synchronization between the stator and rotor fields.

The mathematical model of PMSM in rotational reference frame dq is very popular for FOC structures because controllable quantities such as current, and voltage, are DC values (see Fig. 1) In addition, it allows employing simple controllers to force the machine currents to the required states.

Picture15.png

  Fig. 1. Transformation from stationary to rotational reference frame

PARK & CLARKE TRANSFORMATIONS

In order to decompose currents into torque and flux producing components (id, iq), the position of the magnetizing flux has to be known. This requires knowledge of the accurate rotor position as being strictly fixed with magnetic flux. A transformation of the controllable motor quantities, such as current and voltage, from the stationary abc to the rotational reference system dq must be conducted.

Fig. 2 illustrates the fundamental structure of the vector control algorithm for PMSMs. To perform vector control, it is necessary to take the following four steps:

  • Measure the motor quantities (DC bus voltage and currents, rotor position/speed).

  • Transform measured currents iabc into the 2-phase orthogonal system αβ using a Clarke transformation (1). Second, transform the currents in αβ coordinates iαβ into the dq reference frame using a Park transformation (2).

iα = ia      iβ = ib1/3 - ic2/3      (1)

id = iα cos(θe) + iβ sin(θe)      iq = -iα sin(θe) + iβ cos(θe)      (2)

  • The stator current torque (iq) and flux (id) producing components are separately controlled in the dq rotating frame.

  • The outputs of the controllers' are the required dq voltages and they are transformed by an inverse Park transformation (3) back from the dq reference frame into the 2-phase orthogonal system αβ fixed with the stator. The other options are to transform αβ voltages directly to the abc reference frame by means of (4) or using a Space Vector Modulation (SVM) to generate 3-phase voltages with 3rd harmonics for improved DC bus voltage utilization.

uα = ud cos(θe) - uq sin(θe)       uβ = ud sin(θe) + uq cos(θe)      (3)

ua = uα       ub = -uα1/2 + uβ3/2      uc = -uα1/2 - uβ3/2      (4)

The Clarke/Park transformations and SVM discussed above are part of the NXP's Automotive Math and Motor Control Library (AMMCLib) set.

Picture17.png

 Fig. 2. FOC transformations

The MCSPTR2AK396 motor control kit handles a sensor based FOC control, where the position and speed are obtained by the position/velocity estimator executed by enhanced Time Processor Unit (eTPU). Position and speed are processed by the eTPU co-processor that runs independently on the system core.

WHY THE DIGITAL TWIN?

BL-ARE-DIGITAL-TWINS-BANNER

Designing a digital twin involves the abstraction of motor control algorithms and hardware into a virtual environment. Rather than relying solely on physical hardware, this approach leverages software simulations and virtual models to replicate motor behavior and control strategies. The virtual models are commonly implemented in the MCU while running in parallel with the real models. By decoupling the control algorithms from specific hardware platforms, virtualization enables seamless portability and adaptability across different environments.

There are some crucial advantages that push the digital twins ahead for future considerations:

  • Predictive Maintenance: Digital twins enable proactive maintenance by continuously monitoring and analyzing motor performance data. Early detection of potential issues allows for timely maintenance, reducing downtime and minimizing maintenance costs.
  • Improved Efficiency: Digital twins provide insights into motor behavior under various conditions, facilitating the optimization of control strategies for maximum efficiency. This leads to reduced energy consumption, cost savings, and environmental benefits.
  • Reduced Costs: By eliminating the need for physical prototypes, digital twins significantly reduce development costs. Additionally, predictive maintenance helps in preventing costly breakdowns, saving on maintenance expenses.
  • Time Savings: With digital twins, developers can accelerate the design iteration process, leading to faster development cycles and reduced time-to-market for motor control systems.
  • Optimized Performance: The use of digital twins enables engineers to fine-tune control algorithms and parameters with precision, leading to optimized motor performance and efficiency. Simulating different scenarios allows for performance improvements before deployment, ensuring optimal system operation.
  • Flexibility and Adaptability: Digital twins allow for easy adaptation of control algorithms to different hardware platforms and motor specifications, enhancing system flexibility and scalability. This adaptability extends to maintenance processes, where digital twins can be updated with new data and insights to improve predictive maintenance algorithms over time.

VIRTUAL MODEL OF PMSM

To design a digital twin of PMSM, equations 5 and 6 need to be employed, since they represent the voltage equations of the motor with differential terms. The voltage equations in rotational reference frame dq can be obtained by using Clarke (abc → αβ) and Park transform (αβ → dq).

ud = Rsid + Lddid/dt - ωeLqiq      (5)

uq = Rsiq + Lqdiq/dt + ωeLdid + ωeΨPM      (6)

where Rs is the stator resistance, id and iq are the dq currents, Ld and Lq are the dq inductances, ωe is the electrical angular velocity, and ΨPM is the permanent magnet flux linkage. Since the PMSM represents a dynamic system with transient effects, the differential terms cannot be neglected. On the other hand, these terms should be expressed from the dq voltage equations and integrated to obtain the dq currents equations (7) and (8):

id = 1/L∫(ud - Rsid + ωeLqiq)dt      (7)

iq = 1/L∫(uq - Rsiq - ωeLdidωeΨPM)dt      (8)

Another crucial part of the PMSM mathematical model is the relationship for the electromagnetic torque Te, which consists of two components. The first component is the synchronous torque Tsyn, independent of the d-axis current, and represents the interaction of the permanent magnet flux linkage and the q-axis current:

Tsyn = 3p/2(ΨPMiq)     (9)

The second component is the reluctance torque Trel, which is independent of the permanent magnet flux linkage and is created due to the influence of different inductances in the d- and q-axis:

Trel = 3p/2(Ld - Lq)idiq     (10)

The resulting equation of the PMSM electromagnetic torque Te is then defined as the sum of the synchronous and reluctance torque components:

Te = 3p/2[ΨPMiq + (Ld - Lq)idiq]      (11)

Both terms reflect an essential aspect of the torque production in the PMSM machine. For the digital twin, the electromagnetic torque Te represents a crucial variable. Its sublimation from the load torque TL, and viscous friction component B, the mechanical equation of PMSM is derived as:

Te - TL - m = Jdωm/dt      (12)

where ωm is the mechanical angular velocity, J is the moment of inertia, and B is the viscous friction coefficient. The mechanical angular velocity ωm needs to be expressed from the mechanical equation as follows:

ωm = 1/J ∫(Te - TL - m)dt       (13)

However, equations 7 and 8 include the electrical angular velocity ωe, which needs to be determined. There is a simple relationship between the mechanical and electrical angular velocity defined by the following equation:

ωe = m       (14)

The digital twin requires accurate electrical and mechanical parameters for proper operation. These parameters need to be determined precisely before the first application of digital twin. However, the parameters such as stator resistance Rs, dq axis inductances Ldq, back-EMF constant ke, and torque constant kt may slightly differ for each motor control kit due to the ambient temperature variations, manufacturing deviations, among other variables. NXP’s AMMCLib offers advanced motor control functions for electrical and mechanical parameters measurement. The function AMCLIB_EstimRL estimates the stator resistance Rs and dq inductances Ldq. The function AMCLIB_EstimBJ estimates the moment of inertia J, torque constant kt, and viscous friction coefficient B. The FOC current loop and FOC speed loop settings should follow the same configuration as for the real machine.

SOFTWARE IMPLEMENTATION OF VIRTUAL PMSM FOC

Fig. 3 presents a comprehensive block diagram illustrating the entire motor control architecture. This diagram is segmented into three principal components:

  1. Virtual Model of PMSM FOC: This section details the operations executed directly on the MCU pertinent to motor control. Notably, it encompasses the virtual PMSM FOC, which operates in parallel with the primary PMSM FOC that governs the actual motor.

    The inputs necessary for proper virtual PMSM FOC operation in the speed loop are highlighted within the figure: required electrical angular velocity ωe*, measured q-axis current iq, and precise motor parameters discussed in the previous section.
  2. Software Part: This intermediary layer ensures seamless integration between the software and hardware segments. It manages data flow, command execution, and real-time adjustments crucial for optimal motor performance.

  3. Hardware Part: This includes the Voltage Source Inverter (VSI) and the 3-phase PMSM equipped with a resolver. The three-phase PMSM serves as the terminal motor control node, directly interacting with the control system to execute precise motor operations.

Each of these components plays a vital role in the overall motor control system, ensuring efficient and accurate motor performance. The software part ensures sophisticated control algorithms are applied, the control interface facilitates effective communication, and the hardware part actualizes the motor control commands into real actions.

Picture2.png

  Fig. 3. Motor control architecture with virtual PMSM FOC

The example code below shows the implementation of the PMSM FOC digital twin in the dq reference frame using S32 Design Studio. The FOC current loop and the FOC speed loop are included by means of NXP’s AMMCLib library functions.

 

/* D-axis recurrent PI controller */
ptr->digitalTwin.CurrentLoop.pPIrAWD.fltCC1sc = D_CC1SC;
ptr->digitalTwin.CurrentLoop.pPIrAWD.fltCC2sc = D_CC2SC;
ptr->digitalTwin.CurrentLoop.pPIrAWD.fltLowerLimit = -CLOOP_LIMIT;
ptr->digitalTwin.CurrentLoop.pPIrAWD.fltUpperLimit = CLOOP_LIMIT;

/* Q-axis recurrent PI controller */
ptr->digitalTwin.CurrentLoop.pPIrAWQ.fltCC1sc = Q_CC1SC;
ptr->digitalTwin.CurrentLoop.pPIrAWQ.fltCC2sc = Q_CC2SC;
ptr->digitalTwin.CurrentLoop.pPIrAWQ.fltLowerLimit = -CLOOP_LIMIT;
ptr->digitalTwin.CurrentLoop.pPIrAWQ.fltUpperLimit = CLOOP_LIMIT;

/* Current loop settings */
ptr->digitalTwin.CurrentLoop.pIDQReq = &(ptr->digitalTwin.iDQReqInLoop);
ptr->digitalTwin.CurrentLoop.pIDQFbck = &(ptr->digitalTwin.iDQFbck);

/* Clear AMCLIB_CurrentLoop state variables */
AMCLIB_CurrentLoopInit_FLT(&(ptr->digitalTwin.CurrentLoop));

/* Speed parallel PI controller */
ptr->digitalTwin.FWSpeedLoop.pPIpAWQ.fltPropGain = SPEED_PI_PROP_GAIN;
ptr->digitalTwin.FWSpeedLoop.pPIpAWQ.fltIntegGain = SPEED_PI_INTEG_GAIN;
ptr->digitalTwin.FWSpeedLoop.pPIpAWQ.fltUpperLimit = SPEED_LOOP_HIGH_LIMIT;
ptr->digitalTwin.FWSpeedLoop.pPIpAWQ.fltLowerLimit = SPEED_LOOP_LOW_LIMIT;

/* Speed loop MA filter */
ptr->digitalTwin.FWSpeedLoop.pFilterW.fltLambda = POSPE_SPEED_FILTER_MA_LAMBDA;

/* Incremental ramp parameters */
ptr->digitalTwin.FWSpeedLoop.pRamp.fltRampUp = OL_SpeedRampInc;
ptr->digitalTwin.FWSpeedLoop.pRamp.fltRampDown = OL_SpeedRampInc;

/* Field weakening parallel PI controller */
ptr->digitalTwin.FWSpeedLoop.pPIpAWFW.fltPropGain = SPEED_PI_PROP_GAIN;
ptr->digitalTwin.FWSpeedLoop.pPIpAWFW.fltIntegGain = SPEED_PI_INTEG_GAIN;
ptr->digitalTwin.FWSpeedLoop.pPIpAWFW.fltUpperLimit = 0.0F;
ptr->digitalTwin.FWSpeedLoop.pPIpAWFW.fltLowerLimit = -FLOAT_PI_DIVBY_2;

/* Field weakening MA filter */
ptr->digitalTwin.FWSpeedLoop.pFilterFW.fltLambda = 1.0F;

/* FW Speed loop settings */
ptr->digitalTwin.FWSpeedLoop.pIQFbck = &(ptr->digitalTwin.iDQFbck.fltArg2);
ptr->digitalTwin.FWSpeedLoop.pUQLim = &(ptr->digitalTwin.CurrentLoop.pPIrAWQ.fltUpperLimit);
ptr->digitalTwin.FWSpeedLoop.pUQReq = &(ptr->digitalTwin.uDQReq.fltArg2);
ptr->digitalTwin.FWSpeedLoop.fltUmaxDivImax = MLIB_Div(U_DCB_MAX, I_MAX);

/* Clear AMCLIB_FWSpeedLoop state variables */
AMCLIB_FWSpeedLoopInit_FLT(&(ptr->digitalTwin.SpeedLoop));

/*FOC FW Speed loop for digital twin of PMSM */
AMCLIB_FWSpeedLoop_FLT(ptr->pospeControl.wRotElReq, ptr->digitalTwin.wRotEl, &(ptr->digitalTwin.iDQReqInLoop), &(ptr->digitalTwin.FWSpeedLoop));

/*FOC Current loop for digital twin of PMSM */
AMCLIB_CurrentLoop_FLT(ptr->digitalTwin.fltUdcb, &(ptr->digitalTwin.uDQReq), &(ptr->digitalTwin.CurrentLoop));

/* PMSM digital twin initialization */
ptr->digitalTwin.iDQFbck.fltArg1 = 0.0F;
ptr->digitalTwin.iDQFbck.fltArg2 = 0.0F;

ptr->digitalTwin.uDQReq.fltArg1 = ptr->uDQReq.fltArg1;
ptr->digitalTwin.uDQReq.fltArg2 = ptr->uDQReq.fltArg2;

ptr->digitalTwin.wRotEl = 0.0F;
ptr->digitalTwin.wRotMec = 0.0F;

ptr->digitalTwin.torque = 0.0F;
ptr->digitalTwin.torqueLoad = 0.0F;

/* PMSM digital twin parameters */
ptr->digitalTwin.R_S = 0.5F; // Stator resistance
ptr->digitalTwin.L_D = 0.00026F; // D axis inductance
ptr->digitalTwin.L_Q = 0.00036F; // Q axis inductance
ptr->digitalTwin.PSI_PM = 0.01F; // PM flux linkage
ptr->digitalTwin.K_T = 0.046F; // Torque constant
ptr->digitalTwin.J = 0.000022F; // Moment of inertia
ptr->digitalTwin.B = 0.0F; // Viscous friction coefficient
ptr->digitalTwin.T_S = 100e-6; // Sampling period

/* D axis current */
ptr->digitalTwin.iDQFbck.fltArg1 = MLIB_Add(ptr->digitalTwin.iDQFbck.fltArg1, MLIB_Mul(MLIB_Div(MLIB_Add(MLIB_Sub(ptr->uDQReq.fltArg1, MLIB_Mul(ptr->digitalTwin.R_S, ptr->digitalTwin.iDQFbck.fltArg1)), MLIB_Mul(MLIB_Mul(ptr->digitalTwin.wRotEl, ptr->digitalTwin.L_Q), ptr->digitalTwin.iDQFbck.fltArg2)), ptr->digitalTwin.L_D), ptr->digitalTwin.T_S));

/* Q axis current */
ptr->digitalTwin.iDQFbck.fltArg2 = MLIB_Add(ptr->digitalTwin.iDQFbck.fltArg2, MLIB_Mul(MLIB_Div(MLIB_Sub(MLIB_Sub(ptr->uDQReq.fltArg2, MLIB_Mul(ptr->digitalTwin.R_S, ptr->digitalTwin.iDQFbck.fltArg2)), MLIB_Mul(ptr->digitalTwin.wRotEl, MLIB_Add(ptr->digitalTwin.PSI_PM, MLIB_Mul(ptr->digitalTwin.L_D, ptr->digitalTwin.iDQFbck.fltArg1)))), ptr->digitalTwin.L_Q), ptr->digitalTwin.T_S));

/* Torque equation */
ptr->digitalTwin.torque = MLIB_Mul(1.5F, MLIB_Mul(MOTOR_PP, MLIB_Add(MLIB_Mul(ptr->digitalTwin.PSI_PM, ptr->digitalTwin.iDQFbck.fltArg2), MLIB_Mul(MLIB_Mul(MLIB_Sub(ptr->digitalTwin.L_D, ptr->digitalTwin.L_Q), ptr->digitalTwin.iDQFbck.fltArg1),ptr->digitalTwin.iDQFbck.fltArg2))));

/* Load torque */
ptr->digitalTwin.torqueLoad = MLIB_Mul(ptr->digitalTwin.K_T, ptr->iDQFbck.fltArg2);

/* Mechanical equation */
ptr->digitalTwin.wRotMec = MLIB_Add(ptr->digitalTwin.wRotMec, MLIB_Mul(MLIB_Div(MLIB_Sub(ptr->digitalTwin.torque, MLIB_Sub(ptr->digitalTwin.torqueLoad, MLIB_Mul(ptr->digitalTwin.wRotMec, ptr->digitalTwin.B))), ptr->digitalTwin.J), ptr->digitalTwin.T_S));

/* Mechanical to electrical angular velocity */
ptr->digitalTwin.wRotEl = MLIB_Mul(ptr->digitalTwin.wRotMec, MOTOR_PP);

 

MCSPTR2AK396 MOTOR CONTROL DEMO

This section walks you through the digital twin and physical demo ran in the MCSPTR2AK396 3-Phase Motor Control Kit with S32K396 (see Fig. 4).

2024_05_17_S32K396_MCKit_007.jpeg

 Fig. 4. MCSPTR2AK396 3-Phase Motor Control Kit with S32K396

The S32K396 product series is a part of the S32K39/37/36 family for electrification applications. It further extends the highly scalable portfolio of Arm® Cortex®-M7 K3xx MCUs in the automotive industry. It features:

  • The Cortex-M7 core at a higher frequency.
  • Advanced motor control coprocessors.
  • An extended analog interfaces, including a high-resolution PWM.

S32K396 is developed to meet the next generation SiC traction inverter requirements and to enable high efficiency, low latency, and system-level BOM cost savings. Because of its versatile architecture, the S32K396 is also well suited to address a wide range of electric vehicle applications.

michalvidlak_0-1716462241084.png

Fig. 5. Microcontroller S32K396 with PCIE connection

The FreeMASTER Run-Time Debugging Tool is used to control the application and monitor variables during run time. It can be employed to watch and compare the variables between the real and virtual PMSM FOC. The Motor Control Application Tuning (MCAT) Tool is part of FreeMASTER and allows real-time control structure parameter tuning.

Fig. 6 shows the data extracted from the FreeMASTER tool. It shows the comparison between real and virtual PMSM FOC running in parallel as shown in Fig. 3. In t = 1 s the PMSM is started in the speed loop with the required speed of 1000 rpm. The load is provided to the PMSM from t = 6 s to t = 11 s. It shows the control performance under load conditions. The comparison reveals an accuracy of more than 95 % between a real and virtual model of PMSM FOC.

michalvidlak_3-1716556785993.pngmichalvidlak_4-1716556789874.png

michalvidlak_5-1716556792826.png

Fig. 6. Comparison between real and virtual PMSM FOC on MCSPTR2AK396 with S32K396

SUMMARY

FOC of PMSM offers precise and efficient management of motor torque and magnetic flux. By utilizing transformations such as Park and Clarke, FOC allows for the independent control of these critical parameters, enhancing performance in applications ranging from electric vehicles to industrial automation.

The integration of digital twins into motor control systems further enhances these capabilities. Digital twins, which create virtual replicas of the motor and its control algorithms, provide numerous advantages including predictive maintenance, improved efficiency, cost reduction, and faster development cycles. They allow for real-time monitoring and optimization of motor performance, leading to more reliable and adaptable motor control systems, as demonstrated on the MCSPTR2AK396 3-Phase Motor Control Kit with S32K396.

Overall, the digital twins represent a powerful approach to modern motor control, driving advancements in efficiency, performance, and flexibility while reducing costs and development time. This approach is poised to play a crucial role in the future of electric motor applications, from automotive to industrial sectors.