FOC Runtime Analysis

Introduction

The operation to be performed during FOC analysis is the effect of the FOC set speed command on PWM production. Here, the series of events that occur when the FOC Set Speed and Get Speed commands are called within the Bus Cycle and the relationship of this series of events with MPWM signal generation will be explained.

Events during the Bus Cycle in the isochronous mode

Bus Cycle is the XCTRIGGER0 signal generated by the ProfiNet stack, defined in the GSDML file and the controller determines its period. Currently, the minimum Bus Cycle is set to 1 millisecond in the GSDML file and we use this value in our analysis.

Figure 1 depicts the events occurring during the Bus Cycle and their relationship with the FOC. As stated in the title, ProfiDrive works in isochronous mode, and in order to ensure this synchronicity, DPM IN and DPM OUT procedures are placed in the relevant timing positions. The P1 and P2 values in Figure 1 are the timing positions. Since the value of these positions is still in the research phase, they are shown as P1 and P2.

Normally, 2 timers are used to trigger the DPM IN and OUT procedures at the relevant timing references. However, the interrupt priorities of these timers are lower than the MPWM interrupt in order not to interfere with the motor control. MPWM generates IRQ every 80 microseconds and has significant processing time because it performs many floating-point calculations. This MPWM interrupt causes the DPM IN and DPM OUT procedures to have more processing time than necessary. In addition, the DPM IN procedure has a more critical importance since more mathematical operations are performed. Standard Telegram 3 is used in the analysis.

If we look at the DPM IN procedure in more detail, the data coming with the xChannelIoRead(…) function is received and handled with the Handle Telegram Input procedure. In other words, the operating mode and additional settings related to the STW1 control word are performed. Speed setpoint is set with NSOLL_B. Master sign-of-life is marked with the STW2 control word. Control operations related to the encoder are performed with the G1_STW control word. After the Handle Telegram Input procedure, the Process Inputs procedure is called. Synchronization status is checked with the check sign of life function. Then the ProfiDrive state machine is handled. After that, the last set NSOLL_B speed setpoint word is taken and the speed ramp value is calculated to be given as a parameter to the FOC Set Speed function.

If the DPM OUT procedure is examined in more detail, process outputs, handle telegram output procedures, and xChannelIoWrite function are processed respectively. In the process outputs procedure, the rotor’s current speed is read with the FOC Get Speed function and this value is written to the NIST_B actual speed word. In the following Handle Telegram Output procedure, NIST_B actual motor speed, ZSW1 status word, ZSW2 status word, and G1_ZSW encoder 1 status word values are read, respectively, in order to be written to DPM. Then, the actual values of G1_XIST encoder 1 and G1_XIST2 encoder 2 are calculated by reading the FOC motor encoder position and optional encoder values.

Figure 1 - Events occurring during the Bus Cycle and their relationship with the FOC.

 

When the FOC Set Speed function is called, the entered speed value is first checked and if it is greater than the maximum speed, it is limited to the maximum value. The requested speed setpoint and Iq vector direction are set. Then the Speed Control Process is performed. In the Speed Control Process, first, the current motor speed [RPM] is measured. Then, the vd and vq voltage vector values calculated by the torque PI controllers in the last MPWM event are taken and used to calculate the Field-Weakening PI controller’s setpoint value. After calculating the setpoint value of the field-weakening PI controller, the requested Id vector is calculated with this PI controller. Then, the Speed PI controller’s setpoint value is calculated and the maximum Iq current is limited to the maximum phase current. Afterwards, the speed PI controller calculates the requested Iq current vector. These requested Id and Iq current vectors calculated with the PI controllers are saved to be used in the next PWM events.

Behaviour of MPWM IRQ Event

To get more detailed information about FOC control, check out the FOC Block Diagram from the https://hilscher.atlassian.net/wiki/spaces/NETX/pages/648086615/FOC+Example+Structure+Guide#FOC-Block-Diagram. The MOSFETs of the Power Inverter connected to the PMSM motor are driven by the PWM signal. Motor phase voltages are produced with these PWM signals. In fact, the 3-phase sine wave required to control the motor is created by modulation.

When performing Closed-Loop FOC control, the duty cycle of the next PWM signal should ideally be calculated in each iteration to produce the modulated voltage mentioned above. However, since the priority of the MPWM IRQ event is higher than other IRQs, this will create a starvation situation for them. To overcome this situation, the MPWM IRQ event is triggered once every 2 PWM periods (An attempt was made to reduce the MPWM IRQ event frequency by more than 2 times and a problem occurred in the motor control).

Figure 3 depicts the events occurring during the MPWM IRQ event. The MPWM IRQ event first initiates the ADC conversion of current and voltage values to be used in vector calculations and transformations. Then the Gate Driver Cyclic Process procedure is handled. During this cyclic process, detailed control of the Gate Driver such as initialization, calibration, and fault handling is performed. Then, the Foc Current Vector Control (closed-loop control) is processed (Open-loop control while calibrating and other situations will not be examined here due to the harsh processing conditions).

During closed-loop vector control, the actual calculated theta (Θ) position of the rotor is first estimated. The sin and cos values of this estimated theta position are calculated. Then, the motor phase currents measured and calculated by the ADC are obtained.

First of all, the Clarke transformation is performed using the calculated phase currents. The Clarke transform converts the time domain components of a three-phase system (in abc frame) to two components in an orthogonal stationary frame (αβ) (It is shown in figures 3, 4, and 6). Then, the Park transform is applied using the phase currents converted by the Clark transform and the calculated sin-cos values. The Park transform converts the two components in the αβ frame to an orthogonal rotating reference frame (dq). Implementing these two transforms in a consecutive manner simplifies computations by converting AC current and voltage waveform into DC signals (It is shown in Figures 5 and 6).

 

After the transformations are applied, vector voltages vd and vq are obtained using torque PI controls. The reason why a voltage vector is obtained as a result of the conversion is that the power inverter MOSFETs are driven by voltage. Then DC Bus Ripple Filtration is applied on vd and vq vectors. The reason for this is to eliminate the Back EMF induced into the DC Bus voltage during motor rotation (especially evident at high speeds).

Then, a 3-phase sinus UVW signal is created again with Inverse Park and Inverse Clarke transformations. After all this vector control, Space-Vector Modulation transformations are made to create this sine signal produced by the power inverter, and this modulation produces a modulated PWM signal for 3-phase.

Ideal MPWM IRQ Event synchronization

Normally, MPWM IRQ Event and Bus cycle are processed in different time domains. In order for the MPWM IRQ event to perform its function deterministically, it must be synchronized with the falling edge of the FOC Set Speed in the most ideal conditions. Because the FOC Set Speed function calculates the requested id and iq vectors that will be processed when the MPWM IRQ occurs.

When synchronization is off, it is not possible to know exactly at what moment the MPWM IRQ event will intersect with the FOC Set Speed function. Therefore, the calculated requested id and iq vectors, in the worst-case scenario, occur after the period of an MPWM event.

In fact, the FOC Set Speed function is performed indirectly by the XCTRIGGER IRQ and jitter may occur due to delays during ProfiNet communication. The execution of the given command by the motor-driven indirectly by ProfiDrive may deviate as much as the MPWM IRQ Event period. We would thus violate the isochronous mode. Since the motor cannot execute the given command so quickly, it is impossible to detect it mechanically.


Real MPWM IRQ Event synchronization

Synchronizing the MPWM IRQ event with the FOC Set Speed’s falling edge will use extra CPU resources. Therefore, by making a compromise in the synchronisation and will be synchronised with the falling edge of the XCTRIGGER. Because a specialized hardware register has been designed for this purpose in the MPWM peripheral. It will indirectly perform the same operation in the synchronization that already takes place with XCTRIGGER (As required by Nyquist's theorem, the MPWM frequency is at least twice the bus cycle frequency).

MPWM synchronization is achieved by dynamically tuning the PWM frequency (adjusting the PWM period length to slowly to compensate for the clock drift). However, since we have a PI controller during the MPWM event, changing the PWM period means changing the sampling rate of our PI controller. This causes fatal instability in motor operation. To make the synchronization work properly:

  1. Dynamically compensate the PI controller’s Ki coefficient - Tested and not needed while slowly compensating for the MPWM period

  2. Adjust the PWM period slowly