We will model a three-phase permanent magnet motor driven by a direct current (DC) power source. This has 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 many 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 will demonstrate using two time steps, 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.
9.1 Modeling a Three-Phase Brushless Permanent Magnet Motor
Problem
Solution
The solution is to model a motor with three stator coils and permanent magnets on the rotor. We have to model the coil currents and the physical state of the rotor.
How It Works
The right-hand-side code is shown in the following. 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 our dynamics equation. This structure can be retrieved by calling the function with no inputs. The remaining code implements Equation 9.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. The use of M and E subscripts is typical when writing software for motors.
The function returns a default data structure if no input arguments are passed to it. This is a convenient way for the designer of the code to give users a working starting point for the model. This way, the user only has to change parameters that are different from the default. It lets the user get up and running quickly.
The electrical torque is a second output argument. It is not used during numerical integration but is helpful when debugging the function. It is useful to output quantities that a user might want to plot too. MATLAB is helpful in allowing multiple outputs for a function.
9.2 Controlling the Motor
Problem
We want to control the motor to produce a desired torque. Specifically, we need to compute the voltages to apply to the stator coils.
Solution
We will use field-oriented control with a proportional-integral controller to control the motor. Field-oriented control 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 we calculate will be implemented using pulsewidth modulation of the semiconductor switches as developed in the previous recipe. Torque control is only one type of motor control. Speed control is often the goal. Robots often have position control as the goal. One could use torque control as an inner loop for either a speed controller or position controller.
How It Works
The motor controller is shown in Figure 9.1. This implements field-oriented control (FOC). FOC effectively turns the brushless three-phase motor into a commutated DC motor.
These two transformations are implemented in the functions ClarkeTransformation Matrix and ParkTransformationMatrix. They allow us to go from the time-varying (a,b,c) frame to the time-invariant, but rotating, (d,q) frame.
We now write a function, TorqueControl, that calculates the control voltages u (α,β) given the current state x. The state vector is the same as Recipe 9.1, that is, current i in the (a,b,c) frame plus the angle states θ and ω. We use the Park and Clarke transformations to compute the current in the (d,q) frame. We 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 as follows. This function will return a default data structure if no inputs are passed into the function.
9.3 Pulsewidth Modulation of the Switches
Problem
In the previous recipe, we calculate the control voltages to apply to the stator. Now we want to take those control voltages as an input and drive the switches via pulsewidth modulation.
Solution
We will use the Space Vector Modulation to go from a rotating two-dimensional (α,β) frame to the rotating three-dimensional (a,b,c) stator frame, which is more computationally efficient than modulating in (a,b,c) directly.
How It Works
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 9.3, 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 |
The corresponding (a,b,c) switch patterns are each used for the calculated time, averaging to the designated voltage.
Using the different patterns for odd and even vectors minimizes the number of commutations per cycle.
The pulsewidth modulation routine, SVPWM, does not actually perform 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.
The pulsewidth vectors are computed in the subfunction SVPW. We 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. We then compute the times for the two space vectors that bound the sector. We then assemble the seven subperiods.
The built-in demo is fairly complex so it is in a separate subfunction. We simply specify an example input u using trigonometric functions.
The function SwitchToVoltage converts switch states to voltages. It assumes instantaneous switching and no switch dynamics.
9.4 Simulating the Controlled Motor
Problem
We want to simulate the motor with torque control using Space Vector Modulation.
Solution
Write a script to simulate the motor with the controller. We 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.
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 time step is just 1e-6 seconds. The controller time step is set to 100 times the simulation time step.
The code which adds the shading uses fill with transparency via the alpha parameter. In this case, we 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 we reorder the axes children as the last step, to keep the shading from obscuring the plot lines.
9.5 Summary
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 three-phase electrical machine |
SVPWM | Implements Space Vector Pulsewidth Modulation |
SwitchToVoltage | Converts switch states to voltages |
TorqueControl | Proportional-integral torque controller |