FPGA Realization of Sensorless PMSM Speed Controller Based on Extended Kalman Filter

Based on extended Kalman filter (EKF), the design and FPGA implementation of a sensorless control intellectual property (IP) for permanent magnet synchronous motor (PMSM) drive are presented in this paper. Firstly, the mathematical model for PMSM is derived and the vector control is built up. Secondly, the rotor flux angle (FA) and rotor speed which are estimated by using EKF are described.These estimated values are feedbacked to the current loop for vector control and to the speed loop for speed control. Thirdly, the very-high-speed IC hardware description language (VHDL) is adopted to describe the behavior of the sensorless speed control IP which includes the circuits of space vector pulse width modulation (SVPWM), coordinate transformation, EKF, and PI controller. Finally, to evaluate the effectiveness and correctness of the proposed of system, a cosimulation work performed by Simulink and ModelSim is firstly conducted. Then, an experimental system by FPGA chip and motor driving board is set up to further validate the performance of the proposed EKF-based sensorless speed control IP.


Introduction
PMSM has been increasingly used in many automation control fields as actuators, due to its advantages of superior power density, high-performance motion control with fast speed, and better accuracy.However, conventional motor control needs a speed sensor or an optical encoder to measure the rotor speed and feedback it to the controller for ensuring the precision speed control.Such sensor presents some disadvantages such as drive cost, machine size, reliability, and noise immunity.In recent years, a sensorless control without position and speed sensors for PMSM drive become a popular research topic in the literature [1][2][3][4][5][6][7].Those sensorless control strategies have sliding mode observer (SMO), extended Kalman filter (EKF), reduced-order EKF, and so forth.The EKF is basically a full-order stochastic observer for the recursive optimum state estimation of a nonlinear dynamic system in real time by using signals that are in noisy environment [7].Comparing with SMO, EKF can directly estimate the angular speed and it has high convergence rate which can give a more rapid speed response [5].However, EKF requires heavy online 4 × 4 matrix computing; therefore, the complex computation becomes a challenge for a fixedpoint processor system.In realization, a fixed-point processor using digital signal processor (DSP) and field programmable gate array (FPGA) both can provide a good solution in this issue.Particularly, FPGA with programmable hardwired feature, fast computation ability, shorter design cycle, embedding processor, low power consumption, and higher density is better for the implementation of the digital system [8,9] than DSP.
Recently, a cosimulation work by Electronic Design Automation (EDA) Simulator Link has been gradually applied to verify the effectiveness of the Verilog and VHDL code in the motor drive system [10][11][12].The EDA Simulator Link [13] provides a cosimulation interface between MATLAB or Simulink and HDL simulators-ModelSim [14].Using it you can verify a VHDL, Verilog, or mixed-language implementation against your Simulink model or MATLAB algorithm [13].Therefore, EDA Simulator Link lets you use MATLAB code and Simulink models as a test bench that generates stimulus for an HDL simulation and analyzes the simulation's response [13].In this paper, a cosimulation by EDA Simulator Link is applied to sensorless speed control for PMSM drive.The PMSM, inverter, and speed command are performed in Simulink and the EKF algorithm; current vector controller and speed PI controller described by VHDL code are executed in ModelSim.After successful verification in simulation, an FPGA-based experimental system is established with configuration as in Figure 1 for realizing the proposed IP code again, and experiment results will validate the effectiveness of the sensorless speed control system of PMSM drive.

System Description of PMSM Drive and Sensorless Speed Control
The sensorless speed control block diagram for PMSM drive is shown in Figure 1.The modeling of PMSM, the EKF-based rotor flux angle (FA) and rotor speed estimation, and the PI controller are introduced as follows.

Mathematical Model of PMSM.
The mathematical model of a PMSM is described, in two-axis - synchronous rotating reference frame, as follows: where V  , V  are the  and  axes voltages;   ,   , are the  and  axes currents,   is the phase winding resistance;   ,   are the  and  axes inductance;   is the rotating speed of magnet flux; and   is the permanent magnet flux linkage.
The current loop control of PMSM drive in Figure 1 is based on a vector control approach.That is, if the   is forced to 0, the PMSM will be decoupled, and controlling a PMSM is like controlling a DC motor.After decoupling, the motor's torque is proportional to   : Considering the mechanical load, the overall dynamic equation of PMSM drive system is obtained by where   is the motor torque,   is pole pairs,   is torque constant,   is the inertial value,   is damping ratio,   is the external torque, and   is rotor speed.

Extended Kalman Filter (EKF).
For a motor stochastic nonlinear equation, it can be written in the following form: where (), (), and () are system state, system input, and system output, respectively.The () and () represent system noise and measurement noise which are zero-mean white Gaussian distribution with covariance () and (), respectively.Once a nominal solution to a motor nonlinear equation can be found in ( 4)-( 5), the linearized perturbation equation is where the Jacobian and output matrices are defined as follows: After discretization with sampling time   , (6) becomes where Φ(  ,  −1 , ( −1 )) is an exponential matrix and its computation can be simplified by Further, Therefore, the discrete model of ( 6)- (7) becomes where   =   and  −1 = ( − 1)  .
The EKF is an optimal estimator which searches the cost function  = ∑  =1 { x2 ()} at the least square sense.The x() is defined by x() = x() − (), which is the difference of estimation of state x() and system state ().The EKF algorithm is described by the following twostep recursive equations.Step 1 (prediction step).From (4) and using a simple rectangular integration, or from ( 12) The covariance is updated by Step 2 (innovation step).Consider The Kalman gain is calculated by Figure 2 shows the procedure of EKF with two step above, after measurement update, it will be changed to time update.

Design of the Sensorless PMSM Based on EKF.
The circuit equation of PMSM on the d-q rotating coordinate in (1) is reformulated as where   Δ =   =   .Transforming (20), the circuit equation of PMSM on the  −  fixed coordinate can be derived by the following equation: where   where 8) and ( 22), the Jacobian and output matrices can be obtained: Further, substituting (24) into (10), the exponential matrix is shown as follows: As the results, the EKF algorithm in ( 14)-( 19) can be carried out to estimate the state value.The initial values of   , , and  0 need to be chosen.Through the recursive calculation, the state value of x() = [ î (), î (), ω (), θ ()]  is estimated at each sampling period; then the rotor speed can be derived by Finally, a summary for the estimation of rotor FA and rotor speed based on EKF is presented as follows.

Design of Sensorless Speed Controller IP
Figure 3 illustrates the internal architecture of the proposed FPGA implementation of a sensorless speed control IP for PMSM drive system.The internal circuit comprises a Nios II embedded processor IP and an application IP.The Nios II processor is depicted to generate the speed command, collect the response data, and communicate with external device.All programs in Nios II processor are coded in the C language.The application IP includes mainly a circuit of an EKF-based rotor FA and rotor speed estimation, a speed PI controller, a circuit for current controllers and coordinate transformation (CCCT), a SVPWM circuit, and an ADC interface circuit.The sampling frequencies of the speed control loop and current control loop are designed with 2 kHz and 16 kHz, respectively.The frequency divider generates 50 Mhz (Clk) and 12.5 Mhz (Clk-step) clock to supply all circuits in Figure 3.The internal circuit of CCCT performs the function of two PI controllers, table look-up for sin/cos function, and the coordinate transformation for Clark, Park, inverse Park, and modified inverse Clarke.The detailed circuit design of CCCT, speed PI controller, ADC interface, and SVPWM generation in Figure 3 refers to [8].Herein, only the digital hardware circuit design of the EKF-based rotor FA and rotor speed estimation is described.To reduce the FPGA resource usage, a finite-state machine (FSM) is employed to model the EKF-based algorithm whose design procedure and mathematical formulation are presented in the previous section.The design result is shown in Figure 4 which uses one adder, one multiplier, one divider, two sin/cos lookup table, shifters, registers, and so forth and manipulates 131 steps machine to carry out the overall computation.The data type adopts 16-bit length with Q15 format and 2's complement operation.The multiplier, adder, and divider apply Altera LPM (Library Parameterized Modules) standard.In Figure 4, the steps  0 ∼   the present covariance matrix   and calculate the Kalman gain   ;  121 ∼  130 describe the present state tuning as well as executing the computation of rotor FA and rotor speed.According to (30), the computation of temporary covariance matrix  |−1 in Figure 4 is described in Figure 5. Further, according to (18), (33)-(34), and (36), the update of the present covariance matrix   and calculation the Kalman gain   in Figure 4 are illustrated in Figure 6.The operation of each step in Figure 4 is 80 ns (12.5 MHz) in FPGA; therefore a total of 131 steps need only 10.48 s operation times.The FPGA (Altera) resource usages of EKF-based rotor FA and rotor speed estimation in Figure 4 is 4,158 LEs (logic elements) and 2,890 RAM bits.Additionally, the FPGA resource usages of the circuits of CCCT, speed PI controller, ADC interface, and SVPWM in Figure 3 are 864 LEs and 24,576 RAM, 2,043 LEs and 0RAM bits, 136 LEs and 0RAM bits, and 1,221 LEs and 0RAM bits, respectively.

Simulink/ModelSim Cosimulation and Its Simulation Results
The Simulink/ModelSim cosimulation architecture for sensorless PMSM speed control system is shown in Figure 7.
The SimPowerSystem-Blockset in the Simulink executes the PMSM and the IGBT-based inverter.The EDA simulator link for ModelSim executes the cosimulation using VHDL code little overshoot and 25 ms rising time.It also shows that the estimated rotor speed can track actual rotor speed well.Figure 8(b) shows a successful vector control because   is controlled to zero. Figure 8(c) shows that the estimated rotor FA can fast track the actual rotor FA even in the inverse speed command condition.Further, another simulation case while the PMSM running at wide-range high speed (from 0 rpm → 1000 rpm → 2000 rpm → 1000 rpm → −1000 pm → −2000 rpm) and inverse speed (from 1000 rpm to −1000 rpm) condition is tested, and its simulation results are shown in Figure 9.It presents that not only at speed tracking but also at rotor FA tracking, the estimated value adopted by EKF method can give a good follow to the real rotor value.However, except in the initial condition, the actual rotor speed gives a fast step response by 18 ms rising time, near 0 mm steady-state value, and maximum 17.5% overshoot.

Experimental System and Results
After confirming the correctness of the proposed EKF-based sensorless control IP by simulation, the VHDL codes are directly applied to the experimental FPGA-based sensorless PMSM drive system.The block diagram and real experimental system are depicted in Figure 10.The main devices include a PMSM, a DE2 board with Altera CycloneII FPGA, a motor driver, and a power supplier.The parameters of the PMSM are   = 0.63 Ω,  = 2.77 mH, and 4 pole pairs.The input voltage, continuous current, rating torque, rating speed, and continuous power of the PMSM are 220 V, 12 A, 2.3 Nm, 3000 rpm, and 750 W, respectively.The Altera CycloneII EP2C35 chip adopted in the design possesses 33,216 LEs, maximum 475 available I/O pins, 483,840 RAM, and 35 embedded multipliers.The chip can be embedded with a Nios II multicore processor that is equipped with several 32-bit CPU, flexibility of core size, 1 to 16 Mbytes of flash memory in the available memory chip, 1 Mbyte SRAM, 16 M byte SDRAM, and 4 Gbytes memory outside of the chip.In implementation, except the VHDL codes of CCCT, EKF, and PI controller, the VHDL code of ADC interface circuit should be added and integrated and then downloaded into FPGA.
The PI gains of speed control loop in experiment are designed with  = 0.512 and  = 0.021.In the experimental case, PMSM running at low speed (200 rpm) and inverse speed (from 200 rpm to −200 rpm or vice versa) condition are firstly considered, and its experiment results regarding the speed step response as well as the actual rotor FA and the estimated rotor FA are shown in Figure 11. Figure 11(a) shows that the motor speed gives a good dynamic response performance with a little oscillation and overshoot and it has 15 ms rising time.Figure 11(b) shows that the estimated FA can fast track the actual rotor FA even in the inverse speed command condition.Further, another experimental case while the PMSM running at medium speed (from 0 rpm → 300 rpm → 600 rpm → 900 rpm → 600 rpm → 900 rpm) condition is evaluated, and its experiment results are shown in Figure 12.The Figure 12(a) presents a fast speed tracking with 15 ms rising time and no occurrence of overshoot condition.Figure 12(b) shows a successful vector control due to the   being controlled to zero.Therefore, from the simulation results in Figures 8 and 9 and the experimental results in Figures 11 and 12, it is demonstrated that the EKFbased estimation algorithm used in sensorless PMSM drive and the behavior description by using VHDL are effective and correct.

Conclusions
This study has presented a sensorless PMSM drive based on EKF and successfully demonstrated its performance through cosimulation by using Simulink/ModelSim and implementation by using FPGA.In realization aspect, the VHDL is used to describe the behavior of EKF algorithm, and FSM is used to reduce the FPGA resource usage; therefore, it only needs 4,158 LEs and 2,890 RAM bits.In computational power aspect, the operation time to complete the computation of EKF algorithm is only 10.48 s, which is less than the 62.5 s (16 KHz) sampling time in current control loop.In simulated and experimental results, it shows that the use of EKF in sensorless PMSM drive can accurately estimate the rotor FA and rotor speed, and it can give a good step response performance in case of low speed control, inverse speed control, and high speed control as well.

Figure 2 :
Figure 2: Demonstration of the EKF operation.

Figure 3 :
Figure 3: Internal architecture of a sensorless speed control IP in FPGA.

Figure 4 :
Figure 4: State diagram of FSM for describing the EKF-based algorithm.

Figure 5 :
Figure 5: State diagram of FSM for prediction of covariance matrix  |−1 .

Figure 6 :Step 7 .
Figure 6: State diagram of FSM for (a) the calculation of matrix   and (b) the update of covariance matrix   .

Figure 10 :Figure 11 :Figure 12 :
Figure 10: Experimental system (a) with block diagram and (b) in real system.