© Apress 2015

Michael Paluszek and Stephanie Thomas, MATLAB Recipes, 10.1007/978-1-4842-0559-4_8

8. Electric Motors

Michael Paluszek and Stephanie Thomas2

(1)Princeton, New Jersey, USA

(2)Princeton Junction, New Jersey, USA

Electronic supplementary material: The online version of this chapter (doi: 10.​1007/​978-1-4842-0559-4_​8) contains supplementary material, which is available to authorized users.

You will model a three-phase permanent magnet motor driven by a direct current (DC) power source. There are three coils on the stator and permanent magnets on the rotor. This type of motor is driven by a DC power source with six semiconductor switches that are connected to the three coils, known as the A, B and C coils. Two or more coils can be used to drive a brushless DC motor, but three coils are particularly easy to implement. This type of motor is used in most industrial applications today, including electric cars and robotics. It is sometimes called a brushless DC motor (BLDC) or a Permanent Magnet Synchronous Motor (PMSM) .

Pulsewidth modulation is used for the switching because it is efficient; the switches are off when not needed. Coding the model for the motor and the pulsewidth modulation is relatively straightforward. In the simulation, we demonstrate using two timesteps: one for the simulation to handle the pulsewidths and one for the outer control loop. The simulation script will have multiple control flags to allow for debugging this complex system.

8.1 Modeling a Three-Phase Brushless Permanent Magnet Motor

Problem

You want to model a three-phase permanent magnet synchronous motor in a form that is suitable for control system design. A conceptual drawing is shown in Figure 8-1. The motor has three stator windings and one permanent magnet on the rotor. The magnet has two poles or one pole pair. The coordinate axes are the a, b, and c on the stator; one axis out the center of each coil following the right-hand rule, and the (d,q) coordinates fixed to the magnet in the rotating frame. In motor applications, the axes represent currents or voltages, not positions like in mechanical engineering.

A335353_1_En_8_Fig1_HTML.gif
Figure 8-1. Motor diagram showing the three phase coils a, b, and c on the stator and the two pole magnet (N,S) on the rotor. The × means the current is going into the paper, the dot means it is coming out of the paper

Solution

The solution is to model a motor with three stator coils and permanent magnets on the rotor. You have to model the coil currents and the physical state of the rotor.

How It Works

Permanent-magnet synchronous motors use two or more windings in the stator and permanent magnets in the rotor. The rotor can have any even number of magnet poles. The phasing of the currents in the stator coils must be synchronized with the position of the rotor. Define the inductance matrix L 1:

$$ L=frac{1}{d}left[egin{array}{ccc}hfill 2{L}_{ss}-{L}_mhfill & hfill {L}_mhfill & hfill {L}_mhfill \ {}hfill {L}_mhfill & hfill 2{L}_{ss}-{L}_mhfill & hfill {L}_mhfill \ {}hfill {L}_mhfill & hfill {L}_mhfill & hfill 2{L}_{ss}-{L}_mhfill end{array}
ight] $$
(8.1)
where 
$$ d=2{L}_{ss}^2-{L}_{ss}{L}_m-{L}_m^2 $$
(8.2)

L m is the mutual inductance of the phase windings and L ss is the self-inductance. The phase current array, i, is

$$ i=left[egin{array}{l}{i}_ahfill \ {}{i}_bhfill \ {}{i}_chfill end{array}
ight] $$
(8.3)
where i a is the phase A stator winding current; i b is the phase B current; and so forth. The phase voltages, u, are

$$ u=left[egin{array}{l}{u}_ahfill \ {}{u}_bhfill \ {}{u}_chfill end{array}
ight] $$
(8.4)
where u a is the phase A stator winding voltage. The dynamical equations are

$$ left[egin{array}{l}dot{i}hfill \ {}{dot{omega}}_ehfill \ {}{dot{	heta}}_ehfill end{array}
ight]=left[egin{array}{rrr}hfill -{r}_sL& hfill 0& hfill 0\ {}hfill 0& hfill -frac{b}{J}& hfill 0\ {}hfill 0& hfill 1& hfill 0end{array}
ight]left[egin{array}{l}ihfill \ {}{omega}_ehfill \ {}{	heta}_ehfill end{array}
ight]+psi left[egin{array}{l}-L{omega}_ehfill \ {}frac{p^2{i}^T}{4J}hfill \ {}0 0 0hfill end{array}
ight]left[egin{array}{l} cos {	heta}_ehfill \ {} cos left({	heta}_e+frac{2pi }{3}
ight)hfill \ {} cos left({	heta}_e-frac{2pi }{3}
ight)hfill end{array}
ight]+left[egin{array}{c}hfill Lhfill \ {}hfill 0 0 0hfill \ {}hfill 0 0 0hfill end{array}
ight]u+left[egin{array}{l}0hfill \ {}frac{p}{2J}hfill \ {}0hfill end{array}
ight]{T}_L $$
(8.5)
where ω is the rotor angular rate and θ is the rotor angle; p is the number of rotor poles; b is the viscous damping coefficient; r s is the stator resistance; ψ is the magnet flux; T L is the load torque; and J is the rotor inertia. i and u are the phase winding three vectors that are shown and L is the 3 × 3 inductance matrix, also shown. Equation 8.5 is actually five equations in matrix form. The first three equations, for the current array i, are the electrical dynamics. The last two, for ωe and θ e , are the mechanical dynamics represented in electrical coordinates.

The driver circuitry is shown in Figure 8-2. It has six semiconductor switches. In this model, they are considered ideal, meaning they can switch instantaneously at any frequency you desire. In practice, switches have a maximum switching speed and have some transient response. Note that the motor is Y connected, meaning that the ends of the three phase windings are tied together.

A335353_1_En_8_Fig2_HTML.gif
Figure 8-2. Motor three-phase driver circuitry. The semiconductor switches shown in the diagram are IGBT (integrated gate bipolar transistors). The pulsewidth modulation block, SVPWM, is discussed in Recipe 8-3

The right-hand-side code is shown next. The first output is the state derivative, as needed for integration. The second output is the electrical torque needed for the control. The first block of code defines the motor model data structure with the parameters needed by the dynamics equation. This structure can be retrieved by calling the function with no inputs. The remaining code implements equation 8.5. Note the suffix M used for ω and θ to reinforce that these are mechanical quantities; this distinguishes them from the electrical quantities, which are related by p/2, where p is the number of poles. Use of M and E subscripts is typical when writing software for motors.

%% RHSPMMACHINE Permanent magnet machine model in ABC coordinates .

% Assumes a 3 phase machine in a Y connection. The permanent magnet flux

% distribution is assumed sinusoidal .

%% Forms

% d = RHSPMMachine

% [xDot,tE] = RHSPMMachine ( ˜, x , d )

%

%% Inputs

% t (1,1) Time, unused

% x (5,1) The state vector [iA;iB;iC;omegaE;thetaE]

% d (.) Data structure

% . lM (1,1) Mutual inductance

% . psiM (1,1) Permanent magnet flux

% . lSS (1,1) Stator self inductance

% . rS (1,1) Stator resistance

% . p (1,1) Number of poles (1/2 pole pairs)

% . u (3,1) [uA;uB;uC]

% . tL (1,1) Load torque

% . bM (1,1) Viscous damping (Nm/rad/s)

% . j (1,1) Inertia

% . u (3,1) Phase voltages [uA;uB;uC]

%

%% Outputs

% x (5,1) The state vector derivative

% tE (1,1) Electrical torque

%

%% Reference

% Lyshevski, S. E., "Electromechanical Systems, Electric Machines, and

% Applied Mechatronics," CRC Press, 2000 .

function [xDot, tE] = RHSPMMachine( ˜, x, d )

if ( nargin == 0 )

xDot = struct ('lM',0.0009,'psiM',0.069, 'lSS',0.0011,'rS',0.5,'p',2,...

'bM',0.000015,'j',0.000017,'tL',0,'u',[0;0;0]);

return

end

% Pole pairs

pP = d.p/2;

% States

i = x(1:3);

omegaE = x(4);

thetaE = x(5);

% Inductance matrix

denom = 2*d.lSSˆ2 - d.lSS*d.lM - d.lMˆ2;

l2 = d.lM;

l1 = 2*d.lSS - l2;

l = [l1 l2 l2;l2 l1 l2;l2 l2 l1]/denom;

% Right hand side

tP3 = 2* pi /3;

c = cos (thetaE + [0;-tP3;tP3]);

iDot = l*(d.u - d.psiM*omegaE*c - d.rS*i);

tE = pPˆ2*d.psiM*i'*c;

omegaDot = (tE - d.bM*omegaE - pP*d.tL)/d.j;

xDot = [iDot;omegaDot;omegaE];

8.2 Controlling the Motor

Problem

You want to control the motor to produce a desired torque. Specifically, you need to compute the voltages to apply to the stator coils.

Solution

You will use field-oriented control (FOC) with a proportional integral controller to control the motor. FOC is a control method where the stator currents are transformed into two orthogonal components. One component defines the magnetic flux of the motor and the other defines the torque. The control voltages calculated are implemented using pulsewidth modulation of the semiconductor switches, as developed in the previous recipe.

How It Works

The motor controller is shown in Figure 8-3. This implements field-oriented control. FOC effectively turns the brushless three-phase motor into a commutated DC motor.

A335353_1_En_8_Fig3_HTML.gif
Figure 8-3. Motor controller. PI is proportional integral controller. PWM is pulsewidth modulation. There are two current sensors measuring ia and ib and one angle sensor measuring θ

There are three electrical frames of reference in this problem. The first is the (α,β,χ) frame, which is the frame of the three-phase stator shown in Figure 8-1. This is a time-varying frame. Next, you want to transform it into a two-axis time-varying frame, the (α,β) frame, and then into a two-axis time invariant frame, the (d,q) frame, which is also known as the direct and quadrature axis, and is fixed to the permanent magnet. In our frames, each axis is a current. With a Y connected motor, the sum of the currents is zero, so you only need to work with two currents, i a and i b .

$$ 0={i}_a+{i}_b+{i}_c $$
(8.6)

The (d,q) to (α,β) transformation is known as the Forward Park transformation:

$$ left[egin{array}{r}hfill {u}_{alpha}\ {}hfill {u}_{eta}end{array}
ight]=left[egin{array}{rrr}hfill cos {	heta}_e& hfill - sin {	heta}_e& hfill \ {}hfill sin {	heta}_e& hfill cos {	heta}_e& hfill end{array}
ight]left[egin{array}{r}hfill {u}_d\ {}hfill {u}_qend{array}
ight] $$
(8.7)

This transforms from the stationary (d,q) frame to the rotating (α, β) frame. θ e is in electrical axes and equals 
$$ frac{1}{2}pkern0.1em {	heta}_M $$
where p is the number of magnet poles. The Forward Clarke transformationfor a Y connected motor is

$$ left[egin{array}{r}hfill {u}_{alpha}\ {}hfill {u}_{eta}end{array}
ight]=left[egin{array}{rrr}hfill 1& hfill 0& hfill \ {}hfill frac{1}{sqrt{3}}& hfill frac{2}{sqrt{3}}& hfill end{array}
ight]left[egin{array}{r}hfill {u}_a\ {}hfill {u}_bend{array}
ight] $$
(8.8)

These two transformations are implemented in the functions ClarkeTransformationMatrix and ParkTransformationMatrix. They allow you to go from the time-varying (α,β,χ) frame to the time-invariant, but rotating, (δ,θ) frame.

The equations for a general permanent magnet machine in the direct-quadrature frame are 
$$ {u}_q={r}_s{i}_q+{omega}_eleft({L}_d{i}_d+psi 
ight)+frac{d{L}_q{i}_q}{dt} $$
(8.9)

$$ {u}_d={r}_s{i}_d-{omega}_e{L}_q{i}_q+frac{dleft({L}_d{i}_d+psi 
ight)}{dt} $$
(8.10)
where u are the voltages and i are the currents; r s is the stator resistance; L q and L d are the d and q phase inductances; ω e is the electrical angular rate; and is the flux due to the permanent magnets. The electrical torque produced is

$$ {T}_e=frac{3}{2}pleft(left({L}_d{i}_d+psi 
ight){i}_q-{L}_q{i}_q{i}_d
ight) $$
(8.11)
where p is the number of pole pairs.

The torque equation is 
$$ {T}_e={T}_L+b{omega}_m+Jfrac{d{omega}_m}{dt} $$
(8.12)
where b is the mechanical damping coefficient, J is the inertia, and the relationship between mechanical and electrical angular rate is

$$ {omega}_e=p{omega}_m $$
(8.13)

In a magnet surface mount machine with coils in slots, L d = L q º L, and and the inductances are not functions of time. The equations simplify to

$$ {u}_q={r}_s{i}_q+{omega}_eL{i}_d+{omega}_epsi +Lfrac{d{i}_q}{dt} $$
(8.14)

$$ {u}_d={r}_s{i}_d-{omega}_eL{i}_q+Lfrac{d{i}_d}{dt} $$
(8.15)

You control direct current i d to zero. If i d is zero, control is linear in i q . The torque is now

$$ {T}_e=frac{3}{2}ppsi {i}_q $$
(8.16)

Thus the torque is a function of the quadrature current i q only. You can therefore control the electrical torque by controlling the quadrature current. The quadrature current is, in turn, controlled by the direct and quadrature phase voltages. The desired current i q s can now be computed from the torque setpoint T e s .

$$ {i}_q^s=frac{2}{3}{T}_e^s/left(ppsi 
ight) $$
(8.17)

You use a proportional integral controller to compute the (δ,θ) voltages. The proportional part of the control drives errors to zero. However, if there is a steady disturbance, there will be an offset. The integral part can drive an error due to such a steady disturbance to zero. A proportional integral controller is of the form

$$ u=Kleft(1+frac{1}{	au }{displaystyle int}
ight)y $$
(8.18)
where u is the control, y is the measurement, τ is the integrator time constant, and K is the forward (proportional) gain. The control u will be the phase voltages and the measurement y is the current error in the (δ,θ) frame.

$$ {u}_{left(d,q
ight)}=-{k}_Fleft({i}_{err}+frac{1}{	au }{displaystyle int};{i}_{err}
ight) $$
(8.19)
where 
$$ {left[egin{array}{c}hfill {i}_dhfill \ {}hfill {i}_qhfill end{array}
ight]}_{err}=left[egin{array}{c}hfill {i}_dhfill \ {}hfill {i}_qhfill end{array}
ight]-left[egin{array}{c}hfill 0hfill \ {}hfill {i}_q^shfill end{array}
ight] $$
(8.20)

You now write a function, TorqueControl, that calculates the control voltages, u (α, β), given the current state x. The state vector is the same as Recipe 8-1; that is, current i in the (α,β,χ) frame plus the angle states θ and ω. You use the Park and Clarke transformations to compute the current in the (δ,θ) frame. You can then implement the proportional-integral controller with Euler integration. The function uses its data structure as memory—the updated structure d is passed back as an output. TorqueControl is shown next.

%% TORQUECONTROL Torque control of an AC machine

% Determines the quadrature current needed to produce a torque and uses a

% proportional integral controller to control the motor. We control the

% direct current to zero since we want to use just the magnet flux to react

% with the quadrature current. We could control the direct current to

% another value to implement field-weakening control but this would result

% in a nonlinear control system.

%% Forms

% d = TorqueControl

% [u, d, iAB] = TorqueControl( torqueSet, x, d )

%

%% Inputs

% torqueSet (1,1) Set point torque

% x (5,1) State [ia;ib;ic;omega;theta]

% d (.) Control data structure

% .kF (1,1) Forward gain

% .tauI (1,1) Integral time constant

% . iDQInt (2,1) Integral of current errors

% . dT (1,1) Time step

% . psiM (1,1) Magnetic flux

% . p (1,1) Number of magnet poles

%

%% Outputs

% u (2,1) Control voltage [alpha;beta]

% d (.) Control data structure

% iAB (2,1) Steady state currents [alpha;beta]

%

function [u, d, iAB] = TorqueControl( torqueSet, x, d )

% Default data structure

if ( nargin == 0 )

u = struct ('kF',0.003,'tauI',0.001, 'iDQInt',[0;0], 'dT', 0.01,...

'psiM',0.0690,'p',2);

return

end

% Clarke and Park transforms

thetaE = 0.5*d.p*x(5);

park = ParkTransformationMatrix( thetaE );

iPark = park';

clarke = ClarkeTransformationMatrix;

iDQ = iPark*clarke*x(1:2);

% Set point to produce the desired torque [iD;iQ]

iDQSet = [0;(2/3)*torqueSet/(d.psiM*d.p)];

% Error

iDQErr = iDQ - iDQSet;

% Integral term

d.iDQInt = d.iDQInt + d.dT*iDQErr;

% Control

uDQ = -d.kF*(iDQErr + d.iDQInt/d.tauI);

u = park*uDQ;

% Steady state currents

if ( nargout > 2 )

iAB = park*iDQSet;

end

8.3 PulseWidth Modulation of the Switches

Problem

In the previous recipe, you calculated the control voltages to apply to the stator. Now you want to take those control voltages as an input and drive the switches via pulsewidth modulation.

Solution

You will use space vector modulation to go from a rotating, two-dimensional (α, β) frame to the rotating three-dimensional (α,β,χ) stator frame, which is more computationally efficient than modulating in (α,β,χ) directly.

How It Works

You will use space vector modulation to drive the switches for pulsewidth modulation.2 This goes from (α, β) coordinates to switch states (α,β,χ). Each node of each phase is either connected to ground or to +u. These values are shown in Figure 8-4. The six spokes in the diagram, as well as the origin, correspond to the eight discrete switch states.

A335353_1_En_8_Fig4_HTML.gif
Figure 8-4. Space vector modulation in (α, β) coordinates. You determine which sector (in Roman numerals) you are in and then pick the appropriate vectors to apply so that they, on average, attain the desired voltage. The numbers in brackets are the normalized [α, β] voltages

Table 8-1 delineates each of these eight discrete switch states, the corresponding vector in the (α, β) coordinates, and the resulting voltages. Note that the O vectors are at the origin of the space vector modulation, while the U vectors are at 60-degree increments. The states are indexed from 0 to 7, with 0 being all open states and 7 being all closed.

Table 8-1. Space vector modulation. In the vector names, O means open and U means a voltage is applied, while the subscripts denote the angle in the α-β plane. The switch states are a, b, c, as shown in Figure 8-2, where 1 means a switch is closed and 0 means it is open

k

abc

Vector

u a / u

u b / u

u c / u

u ab / u

u bc / u

u ac / u

0

000

O000

0

0

0

0

0

0

1

110

U60

2/3

1/3

−1/3

1

0

−1

2

010

U120

1/3

1/3

−2/3

0

1

−1

3

011

U180

−1/3

2/3

−1/3

−1

1

0

4

001

U240

−2/3

1/3

1/3

−1

0

1

5

101

U300

−1/3

−1/3

2/3

0

−1

1

6

100

U360

1/3

−2/3

1/3

1

−1

0

7

111

O111

0

0

0

0

0

0

In order to produce the desired torque, you must use a combination of the vectors or switch states so that you achieve the desired voltage on average. You select the two vectors, O or U, bracketing the desired angle in the (α, β) plane; these are designated k and k + 1, where k refers to the number of the vector in Table 8-1. You must then calculate the amount of time to spend in each switch state, for each pulsewidth period. The durations of these two segments, T k and T k + 1, are found from this equation,

$$ left[egin{array}{l}{T}_khfill \ {}{T}_{k+1}hfill end{array}
ight]=frac{sqrt{3}}{2}frac{T_s}{u_d}left[egin{array}{rr}hfill sin frac{kpi }{3}& hfill - cos frac{kpi }{3}\ {}hfill - sin frac{left(k-1
ight)pi }{3}& hfill cos frac{left(k-1
ight)pi }{3}end{array}
ight]left[egin{array}{r}hfill {u}_{alpha}\ {}hfill {u}_{eta}end{array}
ight] $$
(8.21)

The corresponding (a,b,c) switch patterns are each used for the calculated time, averaging to the designated voltage.

The time spent in each pattern, T k or T k + 1 is then split into two equal portions so that the total pulse pattern is symmetric. The zero time T 0, when no switching is required, is split evenly between the endpoints and the middle of the pulse T s − so that the time in the middle pattern (O 111) is twice the time in each end pattern (O 000). This results in a total of seven segments, depicted in Figure 8-5. The total middle time is designated T 7.

$$ {T}_0=frac{1}{4}left({T}_s-left({T}_k+{T}_{k+1}
ight)
ight) $$
(8.22)

A335353_1_En_8_Fig5_HTML.gif
Figure 8-5. Pulse Period Segments. Each pulse period Ts is divided into seven segments so that the two switching patterns, k and k + 1, are applied symmetrically

The implementation of the pulse segments is slightly different for the even and odd sectors in Figure 8-4. Both are symmetric about the midpoint of the pulse as described, but you reverse the implementation of patterns k and k + 1. This is shown for the resulting voltages u in the following equations. You use the first in even sectors and the second in odd sectors.

$$ left[egin{array}{lllllll}{u}_0hfill & {u}_khfill & {u}_{k+1}hfill & {u}_7hfill & {u}_{k+1}hfill & {u}_khfill & {u}_0hfill end{array}
ight] $$
(8.23)
and 
$$ left[egin{array}{lllllll}{u}_0hfill & {u}_{k+1}hfill & {u}_khfill & {u}_7hfill & {u}_khfill & {u}_{k+1}hfill & {u}_0hfill end{array}
ight] $$
(8.24)

Using the different patterns for odd and even vectors minimizes the number of commutations per cycle.

You determine the sector from the angle Θ formed by the commanded voltages u α and u β .

$$ varTheta =mathrm{atan}frac{u_{eta }}{u_{alpha }} $$
(8.25)

The pulsewidth modulation routine, SVPWM, does not actually compute an arctangent. Rather it looks at the unit u α and u β vectors and determines first their quadrant and then their sector without any need for trigonometric operations.

The first section of SVPWM implements the timing for the pulses. Just as in the previous recipe for the controller, the function uses its data structure as memory—the updated structure is passed back as an output. This is an alternative to persistent variables.

%% SVPWM Implement space vector pulsewidth modulation.

% Space vector pulsewidth modulation takes the alpha and beta voltage

% components and enables the switches on a 6 switch inverter to drive a

% 3 phase AC motor. The data structure serves as the function memory.

% Memory variables are marked.

%

% The modulation has seven pulse subperiods each pulse period. These

% are arrange symmetrically about the center of the pulse. A zero

% pulse is at the beginning, middle and end. The order of the active

% pulses (for the two active space vectors) is ordered differently for

% even and odd sectors in the alpha-beta plane. This minimizes switches.

%

% Type SVPWM for a demo using a sine wave input .

%

%% Forms

% d = SVPWM

% [s, d] = SVPWM( t, d )

%

%% Inputs

% t (1,1) Time

% d (.) Data structure

% . dT (1,1) Simulation time step (input)

% . tLast (1,1) Time of last pulse (memory)

% . tUpdate (1,1) Update period for new pulses (input)

% . u (2,1) Voltage vector [alpha;beta] (input) (V)

% . uM (1,1) Maximum voltage (parameter) (V)

% . tP (1,7) Time for each pulse segment (output)

% . sP (3,7) [a;b;c] for each pulse segment (output)

%

%% Outputs

% s (3,1) Switch states (1 or 0)

% d (.) Updated data structure

%

%% Reference

% Implementing Space Vector Modulation with the ADMCF32X, ANF32X-17,

% Analog Devices, January 2000.

%% See also

% SVPWM>Demo

function [s, d] = SVPWM( t, d )

% Default data structure

if ( nargin < 1 && nargout == 1 )

s = struct ( 'dT',1e-6,'tLast',-0.0001,'tUpdate',0.001,'u',[0;0],...

'uM',10,'tP', zeros (1,7),'sP', zeros (3,7));

return ;

end

% Run the demo

if ( nargin < 1 )

Demo;

return ;

end

% Update the pulsewidths at update time

if ( t >= d.tLast + d.tUpdate || t == 0 )

[d.sP, d.tP] = SVPW( d.u, d.tUpdate, d.uM );

d.tLast = t;

end

% Time since initialization of the pulse period

dT = t - d.tLast;

s = zeros (3,1);

for k = 1:7

if ( dT < d.tP(k) )

s = d.sP(:,k);

break ;

end

end

The pulsewidth vectors are computed in the subfunction SVPW. You first compute the quadrant and then the sector without using any trigonometric functions. This is done using simple if/else statements and a switch statement. Note that the modulation index k is simply designated k, and k + 1 is designated kP1. You compute the times for the two space vectors that bound the sector. You then assemble the seven subperiods.

%%% SVPWM>SVPW Compute the space vector pulsewidths

% [sP, tP] = SVPW( u, tS, uD )

%

% Inputs:

% u (2,1) Voltage vector

% tS (1,1) Update period

% uD (1,1) Maximum voltage

%

% Outputs:

% sP (3,7) Switch patterns

% tP (1,7) Pulse times

function [sP, tP] = SVPW ( u, tS, uD )

% Make u easier to interpret

alpha = 1;

beta = 2;

% Determine the quadrant

if ( u(alpha) >= 0 )

if ( u(beta) > 0 )

q = 1;

else

q = 4;

end

else

if ( u(beta) > 0 )

q = 2;

else

q = 3;

end

end

sqr3 = sqrt (3);

% Find the sector. k1 and k2 define the edge vectors

switch q

case 1 % [+,+]

if ( u(beta) < sqr3*u(alpha) )

k = 1;

kP1 = 2;

oddS = 1;

else

k = 2;

kP1 = 3;

oddS = 0;

end

case 2 % [-,+]

if ( u(beta) < -sqr3*u(alpha) )

k = 3;

kP1 = 4;

oddS = 1;

else

k = 2;

kP1 = 3;

oddS = 0;

end

case 3 % [-,-]

if ( u(beta) < sqr3*u(alpha) )

k = 5;

kP1 = 6;

oddS = 1;

else

k = 4;

kP1 = 5;

oddS = 0;

end

case 4 % [+,-]

if ( u(beta) < -sqr3*u(alpha) )

k = 5;

kP1 = 6;

oddS = 1;

else

k = 6;

kP1 = 1;

oddS = 0;

end

end

% Switching sequence

piO3 = pi /3;

kPiO3 = k* pi /3;

kM1PiO3 = kPiO3-piO3;

% Space vector pulsewidths

t = 0.5*sqr3*(tS/uD)*[ sin (kPiO3) - cos (kPiO3);...

- sin (kM1PiO3) cos (kM1PiO3)]*u;

% Total zero vector time

t0 = tS - sum (t);

t = t/2;

% Different order for odd and even sectors

if ( oddS )

sS = [0 k kP1 7 kP1 k 0];

tPW = [t0/4 t(1) t(2) t0/2 t(2) t(1) t0/4];

else

sS = [0 kP1 k 7 k kP1 0];

tPW = [t0/4 t(2) t(1) t0/2 t(1) t(2) t0/4];

end

tP = [tPW(1) zeros (1,6)];

for k = 2:7

tP(k) = tP(k-1) + tPW(k);

end

% The switches corresponding to each voltage vector

% From 0 to 7

% a b c

s = [ 0 0 0;...

1 0 0;...

1 1 0;...

0 1 0;...

0 1 1;...

0 0 1;...

1 0 1;

1 1 1]';

sP = zeros (3,7);

for k = 1:7

sP(:,k) = s(:,sS(k)+1);

end

The built-in demo is fairly complex, so it is in a separate subfunction. You simply specify an example input, u, using trigonometric functions.

function Demo

%%% SVPWM>Demo Function demo

% Calls SVPWM with a sinusoidal input u .

% This demo will run through an array of times and create a plot of the

% resulting voltages .

d = SVPWM;

tEnd = 0.003;

n = tEnd/d.dT;

a = linspace (0, pi /4,n);

tP3 = 2* pi /3;

uABC = 0.5*[ cos (a); cos (a-tP3); cos (a+tP3)];

uAB = ClarkeTransformationMatrix*uABC(1:2,:); % a-b to alpha-beta

tSamp = 0;

t = 0;

tPP = 1;

x = zeros (4,n);

for k = 1:n

if ( t >= tSamp )

tSamp = tSamp + d.tUpdate;

tPP = ˜tPP;

end

d.u = uAB(:,k);

[s, d] = SVPWM( t, d );

t = t + d.dT;

x(:,k) = [SwitchToVoltage(s,d.uM);tPP];

end

[t,tL] = TimeLabel( (0:(n-1))*d.dT);

PlotSet(t,[uABC;x],'xlabel',tL,'plottitle','Voltages',...

'ylabel', {'u_a' 'u_b' 'u_c' 'u_{ap}' 'u_{bp}' 'u_{cp}' 'Pulse' } );

Figure 8-6 shows the state vector pulsewidth modulation from the built-in demo. There are three pulses in the plot, each 0.001 seconds long. Each pulse period has seven subperiods.

A335353_1_En_8_Fig6_HTML.gif
Figure 8-6. The desired voltage vector and the space vector modulation pulses and pulsewidth. The bottom plot shows the pulse periods. Note that the pulse sequences are symmetric within each pulse period

The function SwitchToVoltage converts switch states to voltages. It assumes instantaneous switching and no switch dynamics.

%% SwitchToVoltage Switch state to voltage

% Converts the switch state for a six switch inverter to a, b and c

% voltages. The switches are numbered

%

% a b c

% a ' b ' c '

%

%% Form

% u = SwitchToVoltage( s, uDC )

%

%% Inputs

% s (3,1) Switches

% uDC (1,1) DC voltage

%

%% Outputs

% u (3,1) Three phase voltages [uA;uB;uC]

%

function u = SwitchToVoltage( s, uDC )

% Switch states [a;b;c]

sA = [1 1 0 0 0 1;...

0 1 1 1 0 0;...

0 0 0 1 1 1];

% Array of voltages

uA = [ 2 1 -1 -2 -1 1;...

-1 1 2 1 -1 -2;...

-1 -2 -1 1 2 1];

% Find the correct switch state

u = [0;0;0];

for k = 1:6

if ( sum (sA(:,k) - s) == 0 )

u = uA(:,k)*uDC/3;

break ;

end

end

8.4 Simulating the Controlled Motor

Problem

You want to simulate the motor with torque control using space vector modulation.

Solution

Write a script to simulate the motor with the controller. Include options for closed-loop control and balanced three-phase voltage inputs.

How It Works

The header for the script, PMMachineDemo, is shown in the following listing. The control flags bypassPWM and torqueControlOn are described, as well as the two periods implemented—one for the simulation and a longer period for the control.

%% Simulation of a permanent magnet AC motor

% Simulates a permanent magnet AC motor with torque control. The simulation has

% two options. The first is torqueControlOn. This turns torque control on and

% off. If it is off the phase voltages are a balanced three phase voltage set .

%

% bypassPWM allows you to feed the phase voltages directly to the motor

% bypassing the pulsewidth modulation switching function. This is useful for

% debugging your control system and other testing.

%

% There are two time constants for this simulation. One is the control period

% and the second is the simulation period. The latter is much shorter because it

% needs to simulate the pulsewidth modulation.

%

% For control testing the load torque and setpoint torque should be the same.

The body of the script follows. Three different data structures are initialized from their corresponding functions, as described in the previous recipes; that is, from SVPWM, TorqueControl, and RHSPMMachine. Note that we are only simulating the motor for a small fraction of a second, 0.05 seconds, and the timestep is just 1e-6 seconds. The controller timestep is set to 100 times the simulation timestep.

%% Initialize all data structures

dS = SVPWM;

dC = TorqueControl;

d = RHSPMMachine;

dC.psiM = d.psiM;

dC.p = d.p;

d.tL = 1.0; % Load torque (Nm)

%% User inputs

tEnd = 0.05; % sec

torqueControlOn = false;

bypassPWM = false;

torqueSet = 1.0; % Set point (Nm)

dC.dT = 100*dS.dT; % 100x larger than simulation dT

dS.uM = 1.0; % DC Voltage at the input to the switches

magUABC = 0.1; % Voltage for the balanced 3 phase voltages

if (torqueControlOn && bypassPWM)

error ('ThecontrolrequiresPWMtobeon.');

end

%% Run the simulation

nSim = ceil (tEnd/dS.dT);

xP = zeros (10,nSim);

x = zeros (5,1);

% We require two timers as the control period is larger than the simulation period

t = 0.0; % simulation timer

tC = 0.0; % control timer

for k = 1:nSim

% Electrical degrees

thetaE = x(5);

park = ParkTransformationMatrix( thetaE );

clarke = ClarkeTransformationMatrix;

% Compute the voltage control

if ( torqueControlOn && t >= tC )

tC = tC + dC.dT;

[dS.u, dC] = TorqueControl( torqueSet, x, dC );

elseif ( ˜torqueControlOn )

tP3 = 2* pi /3;

uABC = magUABC*dS.uM*[ cos (thetaE); cos (thetaE-tP3); cos (thetaE+tP3)];

if ( bypassPWM )

d.u = uABC;

elseif ( t >= tC )

tC = tC + dC.dT;

dS.u = park*clarke*uABC(1:2,:);

end

end

% Space Vector Pulsewidth Modulation

if ( ˜bypassPWM )

dS.u = park'*dS.u;

[s,dS] = SVPWM( t, dS );

d.u = SwitchToVoltage(s,dS.uM);

end

% Get the torque output for plotting

[˜,tE] = RHSPMMachine( 0, x, d );

xP(:,k) = [x;d.u;torqueSet;tE];

% Propagate one simulation step

x = RungeKutta( @RHSPMMachine, 0, x, dS.dT, d );

t = t + dS.dT;

end

%% Generate the time history plots

[t, tL] = TimeLabel( (0:(nSim-1))*dS.dT );

figure ('name','3PhaseCurrents');

plot (t, xP(1:3,:));

grid on;

ylabel ('Currents');

xlabel (tL);

legend ('i_a','i_b','i_c')

PlotSet( t, xP([4 10],:), 'xlabel', tL, 'ylabel', {'omega_e' 'T_e(Nm)'}, ...

'plottitle','Electrical', 'figuretitle','Electrical');

thisTitle = 'PhaseVoltages';

if ˜bypassPWM

thisTitle = [thisTitle '-PWM'];

end

PlotSet( t, xP(6:8,:), 'xlabel', tL, 'ylabel', {'u_a' 'u_b' 'u_c'}, ...

'plottitle',thisTitle, 'figuretitle',thisTitle);

thisTitle = 'Torque/Speed';

if ˜bypassPWM

thisTitle = [thisTitle '-PWM'];

end

Turn off torque control to test the motor simulation, with the results shown in Figure 8-7. The two plots show the torque speed curves. The first is with direct three-phase excitation; that is, bypassing the pulsewidth modulation, by setting bypassPWM to false. Directly controlling the phase voltages this way, while creating the smoothest response, would require linear amplifiers, which are less efficient than switches. This would make the motor much less efficient overall and would generate unwanted heat. The second plot is with space vector pulsewidth modulation. The plots are nearly identical, indicating that the pulsewidth modulation is working.

A335353_1_En_8_Fig7_HTML.gif
Figure 8-7. Torque speed curves for a balanced three-phase voltage excitation and a load torque of 1.0 Nm. The left figure shows the curve for direct three-phase input and the right shows the curve for the space vector pulsewidth modulation input. They are nearly identical

Now turn on torque control, via the torqueControlOn flag, and get the results shown in Figure 8-8. The overshoot is typical for torque control. Note that the load torque is set equal to the torque set point of 1 Nm. There is limit cycling near the endpoint.

A335353_1_En_8_Fig8_HTML.gif
Figure 8-8. PI torque control of the motor

The pulsewidths and resulting coil currents are shown in Figure 8-9. A zoomed view of the end of the pulsewidth plot with shading added to alternate pulsewidths is in Figure 8-10. This makes it easier to see the segments of the pulsewidths and verify that they are symmetric.

A335353_1_En_8_Fig9_HTML.gif
Figure 8-9. Voltage pulsewidths and resulting currents for PI torque control
A335353_1_En_8_Fig10_HTML.gif
Figure 8-10. Pulsewidths with shading

The code that adds the shading uses fill with transparency via the alpha parameter. In this case, you hard-code the function to show the last five pulsewidths, but this could be generalized to a time window or to shade the entire plot.

We did take the time to add an input for the pulsewidth length, so that this could be changed in the main script and the function would still work. Note that the axes children were reordered as the last step to keep the shading from obscuring the plot lines.

%% ADDFILLTOPWM Add shading to the motor pulsewidth plot

% Adds gray shading to alternate pulsewidths for the last 5 pulses of the

% plot. The pulsewidth plot should be the current axes.

%

%% Form

% AddFillToPWM( dT )

%

%% Input

% dT (1,1) Pulsewidth

%% Output

% None.

function AddFillToPWM( dT )

if nargin == 0

dT = 0.001;

end

hAxes = get ( gcf ,'children');

nAxes = length (hAxes);

for j = 1:nAxes

if strcmp (hAxes(j). type ,'axes')

axes (hAxes(j));

AddFillToAxes;

end

end

function AddFillToAxes

hold on;

y = axis ;

xMin = y(2) - 5*dT;

xMax = y(2);

axis ([xMin xMax y(3:4)])

x0 = xMin;

yMin = y(3) + 0.01*(y(4)-y(3));

yMax = y(4) - 0.01*(y(4)-y(3));

for k = [2 4]

xMinK = x0 + (k-1)*dT;

xMaxK = x0 + k*dT;

fill ([xMinK xMaxK xMaxK xMinK],...

[yMin,yMin,yMax,yMax],...

[0.8 0.8 0.8],'edgecolor','none','facealpha',0.5);

end

babes = get ( gca ,'children');

set ( gca ,'children',[babes( end ); babes(1: end -1)])

hold off;

end

end

Summary

This chapter demonstrated how to write the dynamics and implement a field-oriented control law for a three-phase motor. A proportional-integral controller with space vector pulsewidth modulation was used to drive the six switches. This produces a low-cost controller for a motor. Table 8-2 lists the code developed in the chapter.

Table 8-2. Chapter Code Listing

File

Description

AddFillToPWM

Add shading to the motor pulsewidth plot.

ClarkeTransformationMatrix

Clarke transformation matrix.

ParkTransformationMatrix

Park transformation matrix.

PMMachineDemo

Permanent magnet motor demonstration.

RHSPMMachine

Right-hand-side of a permanent magnet brushless 3-phase electrical machine.

SVPWM

Implements space vector pulsewidth modulation.

SwitchToVoltage

Converts switch states to voltages.

TorqueControl

Proportional integral torque controller.

Footnotes

1 Lyshevski, S. E. Electromechanical Systems, Electric Machines, and Applied Mechatronics, CRC Press, 2000, pp. 589–627.

2 Analog Devices, “Implementing Space Vector Modulation with the ADMCF32X,” ANF32X-17, January 2000.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset