You are on page 1of 6

ISSN 1674-8484

CN 11-5904/U

, 2014 , 5 2
J Automotive Safety and Energy, 2014, Vol. 5 No. 2

8/13
166 171

Design and implementation of FOC control algorithm for


PMSM motor based on Matlab/Simulink
Pawel Stojaczyk, Dawid Woroch, HONG BO, WEI Yintao*
State Key Laboratory of Automotive Safety and Energy, Tsinghua University, Beijing 100084, China

Abstract: PMSM (permanent magnet synchronous motor) drive systems has been having general used in
various industries needed high precision control due to a rapid development of microprocessors. The proper
system configuration is still complex and time consuming. To overcome such a limitation, this paper presents
a FOC (Field Oriented Control) algorithm for PMSM speed control algorithm performed in Matlab/Simulink by
using standard blocks only, which is realized in almost any DSP (Digital Signal Processing) processor by using
auto-coding tool in Matlab. STM32F4 microcontroller was employed. Simple Active Currents Reading Error
Compensator was introduced for appropriate feedback signals filtering. Precision of the signal was set to around
10 mA of current 10 Bit with an Analog-to-Digital Converter operated by three bidirectional 5-A Hall current
sensors. A PMSM sensored motor was tested in 0~2 000 r/min. The experimental step responses to desired
speeds show good dynamic and smooth performance of the entire system.
Key words: permanent magnetism synchronous motor (PMSM); field oriented control (FOC); Matlab/Simulink;
currents reading error compensator; autocoding

Matlab/Simulink PMSM
Pawel Stojaczyk [ ]Dawid Woroch *
100084

PMSM
PMSM PMSM
(FOC) MATLAB/Simulink Matlab
DSP STM32F4
3 5-A Hall 10 mA
10 Bit 0~2 000 r/min PMSM

(PMSM) (FOC) Matlab/Simulink; ;

TM 911.47 A DOI 10.3969/j.issn.1674-8484.2014.02.008

/ Received 2013-12-06
/ Supported by
(51275265, 51175286)
/ First author Pawel Stojaczyk (1988), male , Poland, bachelors degree. E-mail: pawel.stojaczyk@gmail.com
* / Corresponding author weiyt@tsinghua.edu.cn

Pawel Stojaczyk, et al: Design and implementation of FOC control algorithm for PMSM motor based on Matlab/Simulink

INTRODUCTION

167

control methods in the on-line working hardware environment.

Nowadays electric motors with permanent magnets placed on


the rotor are widely used in almost every high performance
applications [1]. This is due to the main advantages of these
motors: [2]
1. The highest energy efficiency of all known and used
types of electrical machines with comparable size and
working with the same electromechanical parameters
2. They are characterized by the highest attainable
factors: nominal and maximum torque to weight and
volume of the motor [3]
3. Possibility of achieving low torque ripple
4. High precision of the actuator
5. High rate of temporary overloading the torque
6. Opportunity to extraordinarily accurate speed and
position control
7. Good dynamic parameters (quick response)
These types of drives are commonly used in a variety of
different applications:

1 SYSTEM DESCRIPTION
The main algorithm of the controller is developed as a
Simulinks model using standard blocks only. The model is
converted into C language by Matlab Embedded Coder tool and
linked into the Keil Vision where all the remaining functions
are implemented, along with:
1) Controlling the internal peripherals of the
microcontroller like proper I/O pins configuration
2) Simultaneously three phase currents reading by
Analog to Digital Converter (ADC)
3) Time values for SVM (Space Vector Control)
algorithm calculations
4) Encoder supervision
5) Simple interface for the operator
6) Interaction with Simulinks model (inputs and outputs
signals)

6. Various types of industrial automatic systems

Presented method of Field Oriented Control (FOC) algorithm


implementation allows to easily adjust the same program in
almost any fast enough microcontroller with DSP functions or
FPGA (Field Programmable Gate Array) -based system. The
need of the C code writing is minimized to perform only one
loop with main peripherals control functions used in a given
system. That makes the structure much more universal for
various kinds of controllers and PMSM (Permanent Magnet
Synchronous Motor). What is more it allows for quick changes
of whole algorithm and easy testing of new kind of control
methods.

In this research a Code Generation Toolbox was employed


to export any model from Simulink toolbox based on blocks
into the C/C++ language. Thanks to that it can be easily
implemented in any embedded system. Nowadays highspeed microcontrollers with DSP (Digital Signal Processing)
instructions allow for easy building and realization of any

Two parts of the system illustrated in the Fig. 1 are combined


into the one and finally transferred into the microcontroller.
All the feedback data is collected by STM Studio software. It
is used for visualizing variables real-time values and allows to
debug the system. The entire motor drive structure contains a
motor, an inverter and a controller [4] as shown in Fig. 2.

1. Modern electric and hybrid vehicles


2. Modern elevators
3. CNC (Computerized Numerical Control) machinery
tools industry
4. Pumps
5. Robotics

C code for
perhipherials
control

M ATLAB
SIMULINK

KeiluVision c/c++

Compiled
code

Fig. 1 Code and Algorithm Development

J Automotive Safety and Energy

168

USB

UDC

CAN

STM32F405

I d= 0

USART

Ud

RId

dq
n
Rn

2014, Vol. 5 No. 2

Uq

RIq

SVM
fault

U DC
n1
speed
calculation

Id

Iq

dq

abc

Ia
Ib
Ic

A/C
Converter

Ia
Ib
Ic

PMSM
speed

direction

encoder
Fig. 2 Block Diagram

loop. The PWM signals switching chart is shown in the Fig. 3.

STM32F4 microcontroller contains hardware advanced timers


dedicated for Space Vector Modulation (SVM) implementation
with so calleddead time generationwhich effectively
decreases C/C++ code size and CPU usage to minimum.
Six complementary PWM channels controlling motor phase
currents are supported by a forth channel (PWM4). The rising
edge of this signal triggers execution moments of the main control
TD

PWM 1

Simultaneously, phase currents readings occur, along with


speed estimation and a calculation of the control algorithm
generated by Simulink environment. Minimum vector hold
time of 6 s was chosen in this study to simulate the time
required to sample currents and calculate the new vector.

Duty
TD

TD

TD

PWM 2

PWM 3

TD

TD

PWM 4
TN

TS

TS

TS

TS

TN

TN

TS

TS

TS

TS

TN

TN

TS

TS

TS

TS

TN

phase A
phase B
phase C
6 s
4 s

Sampling start

Spaoe available for sampling


Sampling end

TD Dead Time; TN Time of noise; TS Time for current value sampling


Fig. 3 Triggering Currents Reading and Algorithm Loop Calculation

Pawel Stojaczyk, et al: Design and implementation of FOC control algorithm for PMSM motor based on Matlab/Simulink

169

three phase currents; estimated error; Ia fixed, Ib fixed, Ic fixed


corrected three phase currents.

First and last 1 s periods are required for current stabilization


caused by an implemented dead-time. A total result of currents
readings is improved by taking four samples of the current
during one SVM period cycle. The most extreme values are
omitted in calculating the average value from two others.

(1)

Where, = Ia+ Ib + Ic is estimated current error, Ia, Ib, Ic

Current sampling takes 4s and during that time four current


samples are measured per each phase instead of only one as
most systems do. That can effectively improve results quality
and cancel noise caused by plenty of conditions (temperature,
air pressure, outside electromagnetic noise created by motor
itself etc.). The implementation of current error compensation
is crucial as it decreases a torque ripple [5-7]. Thanks to that
better feedback data can be achieved what to some extent
improves final system working results (Fig. 4-5).

0.4
current a

current b

-0.2

current c

I/A

0.2

-0.4
0

0.3
t/s

0.2

0.1

0.5

0.4

0.6

Fig. 4 Three phase currents readings from a first sampling

I/A

0.4
0.2

current a

current b

-0.2

current c

-0.4
0

0.1

0.3

0.2

0.4

0.5

0.6

t/s
Fig. 5 The Same Three Phase Currents after Compensation by Formula (1) Shows More Smooth Reading

The presented method of simple current error compensation in


easy way improves the quality of current measurements and
does not give any delay to the control system. That decreases a
torque ripple and improves the efficiency of the whole system.
It also allows better and smoother current readings without a
complex observer implementation and does not require motor
parameters configuration.
Space Vector Pulse Width Modulation (SVPWM) is an
advanced technique used for variable frequency drive
applications. It utilizes DC bus voltage more effectively than
older SPWM method and generates less Total Harmonic
Distortion (THD) in the Three Phase Voltage Source Inverter [8].
t1 = m cos ( + v ),
6
t2 = m sin ,

(2)

Fig. 6 shows the visualization of vector position calculation.


Currents switching moments for three phases of the motor can
be observed in Fig. 7. Proper times are calculated by Equations
(2).

K1
K3
K5
t0
2

t1

t2

t0
2

t0
2

t2

t1

t0 = t - t1 - t2 .
Where t0 is the duration of the null vector [9].

Fig. 6 SVM Switching Pattern

t0
2

J Automotive Safety and Energy

170

them with separate PI controllers.

2 CONTROL ALGORITHM

Component id is desired to be permanently close to the zero


value. That is obtained by introduction of separate PI controller.

The main algorithm of the controller which is developed


in Simulink model is shown in Fig. 7. Presented functions
allow to transform motors stator three phase currents into
the corresponding current in synchronized revolving d-q
coordinates. This allows us to obtain the maximum possible
torque by maximizing iq which is responsible for torque and
minimizing id that is related to the flux. It is easy to regulate
0

desired_speed

+-

PID(z)
Discrete PID Controller2

Constant torque regulator incorporates iq component into the


third PI control loop that is designed to maintain the desired
speed. Output signal of torque-related PI controller is streamed
into the inverse Park transform, and then controls three-phase
sinusoidal voltages, allowing for the proper motor operation.
PID(z)

+-

ldref

2014, Vol. 5 No. 2

ud

Discrete PID Controller

ualpha

uq

PID(z)

ubeta
theta

Discrete PID Controller1

lpark

+-

2
actual_speed

theta

ld

lalpha
lq

lbeta
Park

PWM1

1
pwm1

PWM2

2
pwm2

Ualfa

Ubeta

3
pwm3

PWM3

SVPWM

electric_angle
1

lalfa
lbeta

la
lb
lc

Clark

la
3

lc

lb
4

Fig. 7 Simulink Block Diagram of the Proposed FOC Scheme

By measuring the motor phase currents, current components


can be determined in d and q axis, the coordinate system
associated with angular rotor position. For better visualization
and easier calculation Park, Clark and inverse Park transforms
are used [10] :
Clark transform:
(3)
Where ia, ib and ic are measured currents of three motor phases
Park transform:

Fig. 8 Pmsm Motor with Small Scale Controller

(4)
Park inverse transform:
(5)
PMSM motor which was tested has parameters as follows:
Ld = L q = 0.59 mH, R = 2.5 , p (number of pole pairs) = 4 and
supplied with encoder with 2 500 pulses per revolution. The
switching frequency was set to 20 kHz. Experiments were done
by using especially prepared for this experiment controller
presented on the Figures 8 and 9, shows the whole laboratory
where all tests were performed.

Fig. 9 The Laboratory where PMSM Motor was


Tested by Using the Proposed Method

Pawel Stojaczyk, et al: Design and implementation of FOC control algorithm for PMSM motor based on Matlab/Simulink

EXPERIMENT RESULT

4 CONCLUSIONS

As seen in Fig. 10, the speed achieves the desired value


(respectively: 500, 1 000 and 2 000 r/min) in less than 10 ms.
800

n / (rmin-1)

600

400

200

Speed responded
0

-200

10

20
(a)

1 500

t / ms

30

40

50

n = 500 r/min

n / (rmin-1)

1 000

500
Speed desired
Speed responded
0

-500

10
(b)

2 500

t / ms

20

30

n = 1 000 r/min

n / (rmin-1)

2 000
1 500
Speed desired
1 000

Speed responded

500
0
-500

10

20

(c)

t / ms

30

40

n = 2 000 r/min

Fig. 10 Step Response for Difference Speeds

Based on the proposed algorithm implemented in Matlab/


Simulink the proper operation of Permanent Magnet
Synchronous motor is reached. The experiments show smooth
and dynamic characteristics. Matlab/Simulink auto-coding tool
allows for quick and fast algorithm development and minimize
the effort maintained with tedious and time consuming C/C++
or VHDL code writing. The system is fully prepared for work,
testing and implementing the new control methods in simple
and usually more intuitive for human system.

REFERNCES / ( )

Speed desired

171

50

[1] Bodora A, Domoracki A, Biskup T. 20 kW brushless


AC motor (PMSM) drive system research [J]. Zeszyty
Problemowe: Maszyny Elektryczne, 2005, 71: 113-117.in
Polish language
[2] Frederiksen A N. Sensorless vector control techniques for
ultra-efficient motor control, 2010, analog devices [Z/OL].
(2012-07-04). http://www.analog.com/static/importedfiles/white_papers/ADI_Blackfin_BF50x_Sensorless_
Vector_Control_Paper_12_18_09_FINAL.pdf.
[3] Enrique L. Arroyo C. Modeling and simulation of
permanent magnet synchronous motor drive system [D].
Puerto Rico:University of Puerto Rico, Mayaguez campus,
2006.
[4] XU Dianguo, GAO Yang, et al. A simple and robust speed
control scheme of permanent magnet synchronous motor
[J]. J Control Theory Appl, 2004, 2: 165-168.
[5] ZENG Qingrong, CHANG Liuchen. An advanced
SVPWM-based predictive current controller for threephase inverters in distributed generation systems [J].
IEEE Trans Indu Elect, 2008, 55(3): 1235-1246.
[6] Kumar K V, Michael P A, John J P, et al. Simulation and
comparison of SPWM and SVPWM control for three
phase inverter R [J], ARPN J Eng and Appl Sci, 2010,
5(7): 61-74.
[7] Kazmierkowski M P, Malesani L. Current control
techniques for three-phase voltage-source PWM
converters: A Survey [J]. IEEE Trans on Indu
Electronics, 1998, 45(5): 691-703.
[8] ZENG Q, CHANG L, SONG P. SVPWM-based current
controller with grid harmonic compensation for threephase grid-connected VSI [C]// 35th Annu IEEE Power
Electronics Specialists Conf, Aachen, Germany, 2004:
2494-2500.
[9] Paturca S V, Covrig M, Melcescu L. Direct torque control
of permanent magnet synchronous motor (PMSM): An
approach by using space vector modulation (SVM) [C]//
Intl Conf Electric Power Syst, High Volt, Elec Mach,
Tenerife, Spain, 2006: 111-116.
[10] LIU Tingting, TAN Yu, WU Gang, et al. Simulation of
PMSM vector control system based on Matlab/Simulink
[C]// Int'l Conf Meas Tech and Mech Automation, 2009:
343-346.

You might also like