UPTEC F 14051 Examensarbete 30 hp November 2014

Design and implementation of a servo system by Sensor Field Oriented Control of a BLDC motor

Per Eriksson Abstract Design and implementation of a servo system by Sensor Field Oriented Control of a BLDC motor Per Eriksson

Teknisk- naturvetenskaplig fakultet UTH-enheten A servo system intended to steer antennas on board ships is designed, built and tested. It uses a Brushless (BLDC) motor with an encoder to keep Besöksadress: track of its position, and Field Oriented Control (FOC) implemented on Toshibas Ångströmlaboratoriet Lägerhyddsvägen 1 microprocessor TMPM373 in order to control the current flowing to the motor. The Hus 4, Plan 0 servo system will be connected in cascade to another already existing servo system and controlled with two input signals. The first signal determines if the antenna axis Postadress: should rotate clockwise or counter clockwise. The second signal is a stream of pulses, Box 536 751 21 Uppsala where each pulse means that the motor should move one encoder point.

Telefon: A printed circuit board is designed and built to complete these tasks. A proportional 018 – 471 30 03 -integral regulator is used to control the position of the motor, using the position

Telefax: error as the controller input. The servo system is tested. The performance of the 018 – 471 30 00 resulting servo system is sufficient to satisfy the required position error limit of 0.5 degrees. In order to reduce the periodic disturbances presented in the system in Hemsida: experiments, Iterative Learning Control (ILC) is implemented. It is shown that using http://www.teknat.uu.se/student ILC further decreases the position error.

Handledare: Sven-Åke Eriksson Ämnesgranskare: Ping Wu Examinator: Tomas Nyberg ISSN: 1401-5757, UPTEC F14 051 Sammanfattning

Ett servosystem tänkt att användas för att rikta antenner ombord på båtar är designat, byggt och testat. Det använder en borstlös likströmsmotor (BLDC) med en encoder som håller reda på dess position, och Field Oriented Control (FOC) implementerad på Toshibas mikroprocessor TMPM373 för att kontrollera strömmen som går in i motorn. Servosystemet kaskadkopplas tillsammans med ett annat redan existe- rande servosystem och styrs med hjälp av två signaler. Den första signalen bestämmer om antennaxeln ska svänga medsol eller motsol. Den andra signalen är en ström av pulser, där varje puls betyder att motor ska ytta sig ett encodersteg. Ett kretskort med all nödvändig hårdvara för detta är designat och byggt. För att styra positionen av motorn används en proportionell-integrerande regulator där styrsignalen är positionsfelet. Servosystemet testas och resultatet är ett servosystem vars positionsfel nästan alltid håller sig under kravet på 0.5 graders fel. För att minska de periodiska störningarna i positionsfelet som visat sig i systemet under experimenten så implementeras algoritmen Iterative Learning Control, som visar sig minska positionsfelet ytterligare.

1 Contents

1 Introduction 4 1.1 Background ...... 4 1.2 Purposes and goals ...... 5 1.3 Methodology ...... 5 1.4 Thesis outline ...... 5

2 Working principles and theories 7 2.1 Servo systems ...... 7 2.2 Brushless Direct Current Motor ...... 8 2.3 Field Oriented Control (FOC) ...... 10 2.4 Encoder ...... 12 2.5 Space Vector Pulse Width Modulation ...... 12 2.5.1 The three-phase inverter ...... 12 2.5.2 Space Vector Pulse Width Modulation ...... 13 2.6 Current Measurement ...... 15 2.7 ripples ...... 16 2.8 Controllers ...... 17 2.8.1 PI controller ...... 17 2.8.2 Iterative learning control (ILC) ...... 17

3 Implementation 18 3.1 Project Specications ...... 18 3.2 Motor Specications ...... 18 3.3 Pulse-width modulation ...... 18 3.4 Computer Communication ...... 19 3.5 Current Measurement ...... 19 3.6 First design ...... 21 3.7 Second design ...... 21 3.8 Programming ...... 23 3.8.1 Main method ...... 23 3.8.2 Vector Engine ...... 25 3.8.3 Key press detection loop ...... 26 3.8.4 Field Oriented Control loop ...... 26

4 Experiments 29 4.1 Setup ...... 29 4.2 Testing the rst design ...... 29 4.3 Testing the second design ...... 31 4.3.1 Determination of current PI controller settings ...... 31 4.3.2 Determination of speed PI controller settings ...... 32 4.3.3 Iterative Learning Control in order to reduce periodic disturbances ...... 33

2 5 Results and Discussion 36 5.1 Dead-time aecting the performance ...... 36

6 Conclusions and suggestions for future work 38 6.1 Conclusions ...... 38 6.2 Suggestions for future work ...... 38

3 Chapter 1

Introduction

1.1 Background

Research Electronics is a company that delivers electronics tailored to customer requirements. These include control and regulation devices that require high speed and precision, or measuring equipment used in extreme environments. The company has developed a two-way satellite communication system in order to provide broadband for ships out in the sea. The motion of the ships' decks makes this quite a dicult task, and most existing antenna system solutions are driven from the center of rotation of the antenna dish. The solution presented by Research Electronics is not following this norm, and the servo motors are instead placed as far as possible from the center of rotation. This improves the pointing accuracy but requires the servo system to be able to achieve a very low positioning error. There are solutions available today on the market, that are able to meet the requirements. Unfortunately they are quite expensive and often comes with extra features not needed for this purpose, such as various lter types used to modify the behaivour of the system and analog inputs to control the speed and torque. As an example, the hardware required for KVHs 4 Mbps maritime broadband solution TracPhone V11 costs 75000 USD. Therefore, Research Electronics has decided to build this system itself. This could reduce the cost of the servo system by 90% or more by using cheap but ecient components and creating the control systems. The servo system that the present thesis project is concerned with is schematically shown in Figure 1.1. The system consists of two servo systems connected in cascade in a closed loop. Both systems have a similar setup, with encoders that keep track of positions. The inner encoder is connected directly to the motor while the outer encoder is connected to the antenna axis. For a satellite dish control system, each cascaded servo system needs to be connected to an antenna axis. A basic component in any servo system is a variable speed drive, which consists of a motor and a controller. of AC motors was rst developed by K. Hasse and F. Blaschke in the early 1970s. Vector control is a variable speed drive control system where the currents of three-phase AC motors are identied as two orthogonal components which can be visualized as a vector. Two dierent branches of vector control emerged during the 1980s, Field-Oriented Control (FOC) and (DTC). In DTC the speed is controlled by estimating the magnetic ux and torque of the motor based on the measured voltage and current. The drawbacks of DTC are that it is dicult to use at low speeds, and produces high torque and current ripples [1]. You also need a very good current sensor if DTC is to be used in a high performance application, which increases the cost of the required hardware. FOC can be used in many dierent ways. It is possible to implement FOC using either synchronous (brushless) or induction (brushed) motors. In both of these cases, you can also make the choice of using sensors or not. Sensorless control requires derivation of speed by measured stator voltage and currents. In this project a brushless DC motor and sensor FOC are used.

4 Figure 1.1: The complete servo system, in which the inner servo system for controlling the motor (inside the dashed rectangle) is the focus of this project.

1.2 Purposes and goals

The purpose of this project is to develop a servo system, which is the inner part of the bigger system shown in Figure 1.1. The maximum position error of the servo system in this project needs to be at most 0.5 degrees, and the system operates at up to ve revolutions per second. The goal of this thesis project is to develop a prototype of such a servo system, which can be further developed into a nal system that can be used in the above mentioned communication system to control the antenna rotation with the requirements fullled.

1.3 Methodology

The components used in this project were carefully chosen based on the requirements. The microprocessor TMPM373 from Toshiba was chosen because it has specic on-chip hardware designed for the purpose of Field Oriented Control. A BLDC motor was chosen because of it's high power to weigth and torque to current ratios. Sensor FOC was chosen above sensorless FOC because of the unreliability of sensorless FOC at low speeds if you do not use expensive and heavy current measurement components. The goal when designing the printed circuit board was to reduce electromagnetic interference and current uctuations as much as possible. This was done by creating return paths for the currents used in the motor in a satisfactory way, by linking the upper and lower layers of the board with multiple holes. Several capacitors were also placed on the board with the sole reason of acting as buers for the spiky current consumption of integrated circuits. Finally, separate channels provided current to the CPU, the integrated circuits and the motor current so that any disturbances in one part would not disturb the other parts. The servo system is built upon a brushless direct current motor with an encoder that keeps track of the rotor position with a resolution of 8192 points per revolution. The motor current is controlled by an algorithm called Field Oriented Control, which is implemented on Toshibas TMPM373 microprocessor that has specic on-chip hardware designed for the purpose of Field Oriented Control. All tests and experiments were conducted using the components that will be used in the complete servo system, so the results are relevant to a real world application.

1.4 Thesis outline

This thesis is divided into six chapters. Chapter one gives a brief introduction and overview of the project. Chapter two provides the necessary theoretical background to understand how the servo system works. Chapter three describes how the project is implemented both physically and digitally. Chapter

5 four describes the experiments conducted on the servo system and how the dierent controlled settings were obtained. Chapter ve presents the results and the discussion. Chapter six summarizes the main conclusions and presents some ideas for future work.

6 Chapter 2

Working principles and theories

2.1 Servo systems

A servo system is a system made for the automatic control of motion by means of feedback. A servo loop generally refers to the feedback control of a single variable, often position, speed or acceleration. The purpose of a servo system is generally one or more of the following objectives: (1) precise control of motion without any human interaction; (2) precise control of motion even with mechanical load variations, power supply uctuations or changes in the environment; (3) be able to control a high power load from a low power reference signal. An example of a general system can be described as in Figure 2.1. The application software (or some other input device) sends a reference position to the motion controller, which utilizes this signal and the feedback position to create an input voltage to the amplier. The amplier transforms this voltage into a current for the actuator. The position of the output motion can then be measured and sent back to the motion controller via a feedback device of some sort. This is a simple servo loop. More complex servo systems may have several servo loops connected in cascade or in some other connection. Let's look at the dierent components in a little bit more detail. A motion controller is commonly implemented using digital computers, but can also be implemented using only analog components. It is the unit which receives the feedback from the feedback device and calculates the input to the amplier. A motion controller can be everything from a simple PI-regulator to an advanced digital device with movement prediction, synchronisation with other parts of the system or other high level features. A ampliers job is to translate the low energy reference signal from the controller into a high energy power signal for the motor. Generally this is a device with some kind of pulse-width modulation circuit which is controlled by the reference signal. The ampliers nowadays often have protective circuits such as thermal shutdown circuits, undervoltage and overvoltage protection circuits. An actuator is a type of motor responsible for moving or controlling a system. They can be single, two or three phase motors. The motor can be an or permanent motor, with DC or AC. There are many dierent types of electrical motors out there and most of them can be used in a motion control system. The term is dened as a motor that provides the power for a . The mechanical connection can be something like a shaft, a chain, a gearbox, cogwheels or some other connection between the motor and the target. The feedback device is used to ensure that the target reaches the commanded position or velocity. This will typically be an position encoder and/or a current measurement sensor like a hall sensor.

7 Figure 2.1: A general motion control system.

2.2 Brushless Direct Current Motor

Brushless direct current (BLDC) motors are a type of permanent magnet (PMSM). The rotor in a BLDC motor consists of a permanent magnet with a varying amounts of pole pairs. These poles are alternating south and north evenly across the rotor, which is usually circular. Furthermore, a BLDC motor also consists of windings which are evenly spread around the stator as shown in gure 2.2. In a BLDC motor a magnetic eld is created when current is owing through the windings in the stator. If these currents are manipulated in a correct way this magnetic eld will rotate. The static magnetic eld of the rotor will rotate at the same speed as the magnetic eld of the stator, causing the rotor to move. An example of how the magnetic eld in the windings can change is shown in gure 2.3. BLDC motors do not experience the slip commonly seen in induction motors when the load on the rotor is increased. Instead, the rotor in a BLDC will either rotate in perfect synchronisation with the magnetic eld or not at all.

Figure 2.2: The interior of a BLDC motor. A,B and C mark the three windings.

The brushless synchronous motor has been very popular over the past years due to some big ad- vantages compared to brushed DC motors, for instance, high torque to current ratio, higher eciency, noiseless operation, better robustness and large power to weight ratios[2]. The motor equations can be viewed from the phase reference frame with individual currents and voltages for each phase. Another way to look at it is to look at the motor equations from the rotor reference frame. In this reference frame, two perpendicular axes called the direct (d-axis) and quadrature (q-axis) exists, as illustrated in Figure 2.4. The motor model in the rotor reference (d − q) frame is

8 Figure 2.3: An inverter or a three-phase power supply provides a rotating magnetic eld inside a motor. expressed in the following manner [3][4],

Figure 2.4: A vector representation of (a) the three phase currents(iA,iB and iC ), their vector sum is as well as (b) the direct and quadrature axis.

V (t) R + pL ω L  i (t)  0  d = a d e q d + (2.1) Vq(t) −ωeLd Ra + pLq iq(t) Keωe(t) 3 T (t) = P (ψ i (t) + (L − L )i (t)i (t)) (2.2) e 2 F q d q d q J B T (t) = pω (t) + m ω + T (2.3) e P e P e L where

Vd(t),Vq(t) d-axis and q-axis stator voltages; id(t), iq(t) d-axis and q-axis stator currents;

9 Ld,Lq d-axis and q-axis stator inductances; La phase inductance; Ra stator winding resistance; J moment of inertia; p dierential operator ( d ); dt P number of poles in the motor;

ωe electric speed; ψF rotor permanent magnetic ux linkage; Ke back EMF constant; Te(t) generated electromagnetic torque; TL load torque; Bm Damping coecient (assumed to be zero from now on);

By ignoring the mutual inductance between the phase windings and assuming symmetry in the

inductances, Lq = Ld = La[5]. By assuming that control is good enough to keep id = 0 Equation (2.1), (2.2) and (2.3) can be simplied to,

di (t) V (t) = L q + R i (t) + K ω (t) (2.4) q a dt a q e e J dω (t) K i (t) − T = e (2.5) t q L P dt where is the torque constant dened as 3 . To facilitate the analysis, let be zero. Performing Kt 2 P ψF TL Laplace transforms on Equation (2.4) and (2.5) leads to the from Vq(s) to iq(s),

iq(s) s/La (2.6) Gm(s) = = 2 Vq(s) s + (Ra/La)s + KtPKe/(JLa)

To control the speed of the motor another transfer function from Vq to ωe can be found from the same equations and given as follows:

ω (s) K G (s) = e = t (2.7) ω V (s) 2 J J q s L P + R P s + KeKt This leads to a control system with two control loops, an inner loop and an outer loop, which is shown in Figure 2.5. The boxes labelled PI are PI controllers, which are explained in Section 2.8.1. In order to create good stability the inner loop has to be much faster than the outer loop, ideally reaching a steady state before each new input from the outer loop.

2.3 Field Oriented Control (FOC)

The current owing in each of the windings creates a magnetic eld. The magnitude and direction of this magnetic eld can theoretically be perfectly controlled by the currents in the windings. In Figure 2.4 (a)

a vector representation of the three phases, their respective current and the resulting sum of currents is can be seen. Torque in the motor is produced by the attraction and repulsion between the magnetic eld

of the rotor and the magnetic eld the current is produces. This means that if the vector is is placed in the same direction as the magnetic eld of the rotor, no torque is produced. The elds still interact to produce a force, but the force is in line with the axis of rotation of the motor, pushing towards the

motor bearings. If is is aligned orthogonal to the magnetic eld of the rotor, all of the force produced in the interaction between the two magnetic elds can be utilized as torque, producing a maximum torque for that current[6].

The purpose of Field Oriented Control (FOC) is to control this current vector is to produce the wanted speed and torque and minimize current consumption. In order to do this easily, the current vector is is transformed from its original three-phase speed and time dependant system into a two-coordinate

10 Figure 2.5: A block diagram for the control loops.

Figure 2.6: A block diagram for eld oriented control of an AC-motor.

(direct and quadrature) time invariant system with use of the Clarke and Park transformations[7]. This two-coordinate (d and q) system is xed to the rotating rotor as seen in Figure 2.4 (b). A owchart of the FOC process is shown in Figure 2.6. The process starts by measuring the currents

owing in each of the phases in the AC motor. In order to nd the direct and quadrature currents id and iq the Clarke and Park transformations are used. The Clarke transformation converts the ia, ib and ic into the ctional iα and iβ by Equation (2.8), ( i = i α a (2.8) i = √1 (i − i ) β 3 b c

and by utilizing the Park transformation id and iq are found according to Equation (2.9), where θ is the electrical position of the rotor,

 id = iα cos(θ) + iβ sin(θ) (2.9) iq = iβ cos(θ) − iα sin(θ)

The next step is to compare id and iq to the reference values dened by the user to generate the error signals for the PI controller. Generally for a BLDC motor, id,ref is set to zero. For permanent magnet synchronous motors a negative id,ref is sometimes used in a process called Field Weakening in order to achieve higher than rated rotation speeds [8]. The output from the PI controller are the two voltages

11 Vd and Vq. After being transformed by the inverse Park transformation Vα and Vβ are found. These voltages are used in the Space Vector Pulse Width Modulation process to produce the proper duty cycles for the three-phase inverter. For more information about this particular step, read Section 2.5. It should be noted that knowledge of the rotor position is vital to FOC. Numerous research has been done on the subject of sensor-less FOC where the rotor position is estimated from the back-EMF from the motor, for example JR Meveys very extensive master thesis report [9]. In this project however, an incremental rotary encoder is used to keep track of the rotor position.

2.4 Encoder

An encoder is an electrical and mechanical device which converts the angular position of an axis or similar objects to an digital or analogue code. There are two main types of rotary encoders, incremental or absolute. An absolute rotary encoder keeps track of its position even when there is no power connected to the system. An records changes in position but doesn't know where it is directly on power-up. In this project an incremental encoder was used. In Figure 2.7 the output from an incremental encoder can be seen when the motor is rotating clockwise as well as counter-clockwise. An incremental encoder has three outputs; A,B and Z. The direction of rotation can be found from detecting which of the A or B pulses arrives rst, or in other words the phase dierence between the A and B pulse. The Z pin pulse occurs when the encoder reaches a specic angular position. This can be used to nd the absolute position of an incremental encoder.

Figure 2.7: Output from an incremental encoder when the motor is rotating in dierent directions

2.5 Space Vector Pulse Width Modulation

2.5.1 The three-phase inverter The purpose of a is to change direct current into and a typical three-

phase power inverter is shown in Figure 2.8. In this gure VDC is the continuous inverter input voltage and A,B & C are the three phases of the motor. Number 1-6 represents six switches which are controlled by the inverter. In order to avoid a short circuit situation, the upper and lower switches of the same inverter leg (for example switch 1 and 2) should never be on at the same time. However, at least one switch in each leg should always be on[10]. Since a three-phase inverter has three legs, this creates a situation where the output from the inverter can be one of eight dierent states at any given time. These states can be seen in Figure 2.9 and are

12 Figure 2.8: A three-phase inverter, motor, and a DC link shunt resistor.

represented by the space vectors V0 to V7.[10] In order to create a smooth sinusoidal curve inside the motor, fast switching between these eight states are required. At the same time, it is necessary to arrange the switching sequence in such a way that the switching from one state to the next is done by switching only one inverter leg in order to minimize harmonics. The Space Vector pulse width modulation technique is a good choice for this task[11].

Figure 2.9: A table of the dierent space vectors used in SVPWM.

2.5.2 Space Vector Pulse Width Modulation Space Vector Pulse Width Modulation (SVM) is one of many dierent methods to generate pulse width modulation (PWM) outputs. Compared to the commonly used sinusoidal pulse width modulation, SVM generates lower current harmonics and a higher maximal modulation index[11][12]. The role of SVM is to control the rapid switching between the eight dierent states, shown in Fig- ure 2.9. When a switching state for a given inverter leg is 1, that means that the upper switch in that leg is on and the lower switch is o. When a switching state is 0, that means that the upper switch is o and the lower switch is on. In Figure 2.8 the inverter is currently in state 101 with switches 1,4 and

5 on, which corresponds to space vector V6. The space vectors V7 and V0 are zero-current vectors, which means that no current enters the motor through the power inverter when the switches are in these states.

Let's for example assume that some Vα and Vβ are given from the inverse Park transformation. A voltage Vref is then obtained by Equation (2.10) [2],

q 2 2 (2.10) Vref = Vα + Vβ V θ = arctan α (2.11) Vβ

13 An image representation of the space-vectors as well as Vref can be seen in Figure 2.10. By projecting Vref onto the two space vectors V1 and V2, the times T1, T2 can be found. These times represent the amount of time during the next PWM period Ts of which the inverter should be in the switching state corresponding to space vector V1 and V2 respectively. This can be written as[2],

Z Ts Z T1 Z T1+T2 Z Ts Vref = V1dt + V2dt + V0dt (2.12) 0 0 T1 T1+T2

Ts = T0 + (T1 + T2) (2.13)

The method to nd the exact times depends on where the vector Vref is pointing, and won't be covered in this report. During the remaining time T0 = Ts − (T1 + T2) of the PWM period both of the zero vectors V0 and V7 have to be used. In this example when Vref is between V1 and V2, the corresponding inverter output can be seen in Figure 2.11. Note that for the rst and last period marked as T0 , the inverter is in state , but in the middle two periods marked T0 , the inverter is in state . 4 V0 4 V7

Figure 2.10: A representation of the space vectors V1 to V6, and a voltage vector Vref .

Figure 2.11: The voltages of the three phase and the corresponding space vectors for a PWM period Ts.

14 2.6 Current Measurement

In order to control the motor currents in a satisfactory way, good measurements of the phase currents is vital. There are several dierent methods available in order to measure the current, for example current sensors such as Hall sensors or current transducers. These methods works well but brings disadvantages such as drive cost and non-linearity. For low-cost drive systems, some other techniques exists. The most common is probably to measure the DC-link current using a single shunt resistor. Another common solution is to place a shunt resistor in series with each emitter of the low-side switches [13]. Since the purpose of this project is to design a low-cost solution, the two latter techniques are covered in this report. For the rst system design, the single-shunt method is used and for the second system design the three-shunt method is used. The single shunt circuit can be seen in Figure 2.8. The shunt is placed as a DC-link between the switches and the ground. In this case, precise knowledge of the PWM switching pattern is required in order to sample the voltage drop over the shunt at precisely the correct time. Depending on which switching state the inverter currently is in, a single current can be measured. For example, let's assume that the inverter is currently in state [101] as in Figure 2.8. In this state the current owing into the motor is ia + ic. Since ia + ib + ic = 0 this means that the current we measure is ia + ic = −ib. A table of which current can be measured in which space vector can be seen in Figure 2.12.

Figure 2.12: A table of the current owing through the DC-link shunt for dierent space vectors.

As explained in Section 2.5.2, the inverter will almost always switch rapidly between the zero vectors and two active vectors. This means that during a single PWM period, up to two dierent currents can be measured depending on the direction of Vref . Note that measuring two currents is enough since the third current can be reconstructed by calculations. The only time when only one current can be measured is if Vref is too close to one of the space vectors. In this case only the current corresponding to that space vector can be sampled. The reason for this is that sampling a current takes a small time, but if Vref is too close to a space vector, the time spent in the adjacent space vector will be too small for a reliable measurement. In order to produce a satisfactory sample the timing of the sampling is usually set in the middle of the active vectors. In Figure 2.11 an typical PWM period can be seen where two currents could be measured. For space vector the measurement should happen after a time T0 T1 and for after V1 4 + 2 /2 V2 a time T0 T1 T2 , resulting in measurements of currents and . 4 + 2 + 2 /2 ia −ic The second technique covered in this report is the three-shunt current measurement method. By placing a shunt resistor at the emitter of each low-side switch as seen in Figure 2.13, all three currents can be measured at the same time instead of one at a time. In that case, the timing of the measurements is not in the middle of an active space vector but instead in the middle of the zero vector V0, when all lower side switches are turned on. This creates a dierent limitation, namely that the time T0 has to be big enough. The limitations for the two techniques can be seen in Figure 2.14. The blue areas are areas where current measurements are limited or impossible altogether if Vref is in that area. Dierent

15 methods may be used to circumvent these problems but the easiest one is probably to ignore all the measurements in these regions. [14]

Figure 2.13: The placement of the resistors in the three-shunt current measurement method and the switching state during measurements.

Figure 2.14: If Vref is inside the blue regions, current measurement is dicult or impossible. The gure to the left is for three shunt current detection and the right one is for single shunt current detection

2.7 Torque ripples

One of the main disadvantages of permanent magnet synchronous motors (PMSM) are the parasitic torque pulsations which occurs at periodic rotor positions. These torque pulsations are especially no- ticeable at low-speed operations, and is naturally ltered down at higher rotor speeds [15]. These are various sources of the torque pulsations, such as deviations from a sinusoidal ux density distribution in the air gap, errors in current measurements, phase unbalancing and cogging. Torque ripple minimization techniques can be classied into two dierent broad categories. The rst category consists of techniques aimed at the motor design so that the characteristics of the PMSM approaches the ideal case. This would make the torque production more smooth, but would complicate the production process and increase the cost of the motors. The second class of techniques consists of algorithms used for an additional control eort to correct for these non ideal characteristics of the [16]. Lots of research has been done

16 on the second class of techniques, and a technique named Iterative Learning Control [15] was tested and evaluated in this project.

2.8 Controllers

Two dierent kind of controllers are used in this project, the PI controller and ILC.

2.8.1 PI controller The PI controller is a standard proportional, integrative and derivative (PID) controller where the derivative part is set to zero. The PID controller algorithm is:

Z t d u(t) = Kpe(t) + Ki e(τ)dτ + Kd e(t) (2.14) 0 dt where e(t) is the error signal (reference signal minus the current signal value) at the time t, and u(t) is the controller output at time t. The PID controller works just as well in discrete time as it does in continuous time, but the equation looks slightly dierent.

2.8.2 Iterative learning control (ILC) ILC is a control algorithm created to reduce the error of periodic disturbances. The control law used in this project has the following equation:

ui+1(n) = (1 − α)ui(n) + Φei(n) + Γei+1(n) (2.15)

where n is the position, ei is the error during the ith repetition, ui is the input to the system during the ith repetition, α is a forgetting factor to reduce the eect of temporary disturbances, Φ and Γ are ILC tuning variables. In ILC, the error and controller output for each position are saved in a memory and updated each repetition in order to reduce the eect of the periodic error. When using ILC in a

PMSM the following condition must hold in order for the algorithm to converge[15], where Kt is the torque constant and J is the combined inertia of the rotor and the load .

K k1 − t Φk < 1 (2.16) J

17 Chapter 3

Implementation

3.1 Project Specications

The present project is concerned with the inner servo system shown in Figure 2.1. The system is intended to control the position of the motor via two inputs. The rst input species the motor rotation direction. For a zero on the input the motor will spin in a counter-clockwise direction, and for a one the motor will spin in a clockwise direction. The second input was a stream of pulses. For each received pulse the motor should rotate one encoder step. An important characteristic of the rst input is that the unit sending the stream of pulses (the outer servo system) changes the pulse rate every 50 milliseconds, and during these 50 ms the pulse rate is constant. The limit of the nal movement of the outer servo system was about 35 degrees per second. The gear ratio will be somewhere between 1:40 to 1:50 which means that the maximum rotation speed of the motor needed for this project will be about ve revolutions per second, or 300 rpm. This is quite a slow rotation speed, but on the other hand the error in position had to be very low. In the nal position, the error had to be max 2 encoder points out of 65536 for that encoder. The encoder in the inner system has a resolution of 8192 points per revolution. This converts to an acceptable encoder error of about 2∗8192∗50 points for this project with a gear ratio 50:1, which is about 0.5 degrees. 65536 = 12.5

3.2 Motor Specications

The motor used is this project is a 4-pole FL57BLS03 DC Brushless Motor. The specications for this motor are given in Table 3.1. The motor is also equipped with a HKT 56 incremental rotary encoder from Hedss. This encoder has 2048 counts of phase A and B per revolution, but if you count both anks for both the A and B channel the precision is 8192 points per revolution which corresponds to a mechanical resolution of ≈ 0.044 degrees. The electrical position of the rotor in the FOC loop is controlled by the variable θ. This is a 16-bit variable which means that the precision is 65536 points per electrical revolution. The motor has 2 pole- pairs, which means that for each mechanical revolution there are two electrical revolutions. So if the motor moves one encoder point, the variable θ changes 65536 ∗ 2/8192 = 16 points.

3.3 Pulse-width modulation

The pulse width modulation circuit of the TMPM373 gives you two options for waveform; sawtooth or triangular. In this project a triangular waveform was chosen, since it gives you a symmetrical center aligned PWM output automatically. A triangular PWM waveform means that the PWM counter starts at zero, counts up to a max value, and counts downwards to zero again which would look like a triangle in a diagram. The output of the PWM circuit is controlled by a counter in the CPU. When the CPU is operating at 80 MHz, the resolution of the PWM counter is 25 nanoseconds when using a triangular waveform. For

18 Table 3.1: The motor specications. each phase a comparator variable is then set, and when the counter is below that comparator variable the PWM output for that phase is on. This can be seen in Figure 3.1. In this project, the PWM frequency was set to 20 kHz which means that the maximum counter value was set to 1/25∗10−9 20000 = 2000

Figure 3.1: The pulse width modulation counter operation and output for a single phase.

3.4 Computer Communication

Communication between the microprocessor and the computer is done via an serial port using an Uni- versal Asynchronous Receiver/Transmitter (UART) which is a on-chip feature of the microprocessor. An UART sends bytes of data by transmitting the individual bits sequentially. Another UART is used as the receiver and puts the received bits in a shift register until a full byte has been assembled. The receiver and transmitter UART has to be set to the same number of data bits per transmission, transmission rate, parity bit setting and other options in order to work. In this project 8 bits of data was sent in each transmission, plus a start and a stop bit. The baud rate was set to 115200 bits per second.

3.5 Current Measurement

For the rst system design the single-shunt described in Section 2.6. For the second system design the three-shunt method was used. Both system designs used the circuit described in this chapter to measure the current owing through the shunt resistor(s). The switch from the single-shunt to the

19 three-shunt method was done because of easier timing implementation. It was also possible to always measure the current of all three phases with the three-shunt method. In the single shunt case there are certain moments for each revolution of the motor when the electrical vector is in areas where current measurements are impossible. The circuit in Figure 3.2 was chosen in order to reliably measure the current [17]. This circuit works for both the single shunt and the three-shunt case. Some additional components such as capacitors was added to various places in order to reduce noise.

Figure 3.2: A circuit used to measure the current passing through a shunt resistor.

Let's analyse what this circuit does. The operation amplier is assumed to be ideal, which means

that it has an innite amplication, innite input resistance, zero output resistance and V+ is equal to V− at all times. This gives us the following equations

 R3 V− = Vout  R3+R4 R1 (3.1) V+ = Vin + (10 − Vin) R +R  1 2  V+ = V−

Combining these equations leads to an expression for the output voltage Vout

R1 R3 + R4 Vout = (Vin + (10 − Vin) ) (3.2) R1 + R2 R3 R1 R1 R3 + R4 = (Vin(1 − ) + 10 ) (3.3) R1 + R2 R1 + R2 R3 The maximum peak current allowed into the motor at stall torque is 16.5 A according to the motor

specications in Figure 3.1. Since Vout is sent straight into one of the analogue-to-digital inputs of the processor it should never go above 5 V or the processor might break. Rshunt was chosen to be 0.022 Ω which gives the maximum voltage drop over the resistor to be U = 0.022 ∗ ±16.5 = ±0.363 V. The resistors then needs to be dimensioned so that the voltage Vin = −0.363 V to +0.363 V corresponds to a Vout = 0 V to 5 V. A good place to start is to assume that when Vin = 0, the output voltage is Vout = 2.5 V. The amplication needed to push up to 5 V when is 0.363 V is then (5−2.5) times. A Vout Vin Av = 0.363 = 6.9 close match in the E12 resistor series would be to put R4 = 120kΩ and R3 = 22kΩ which gives the R3+R4 22kΩ+120kΩ amplication Av = = = 6.55 times. R3 22kΩ Given this amplication, it's straightforward to nd the values of R1 and R2 to get the wanted oset of +2.5 V.

20 R R 2.5 = (0 ∗ (1 − 1 ) + 10 1 ) ∗ 6.55 (3.4) R1 + R2 R1 + R2 R 2.5 ⇒ 1 = (3.5) R1 + R2 65.5

A close enough match (again from the E12 resistor series) in this case is R1 = 2.2kΩ and R2 = 56kΩ, diering only ≈ 1% from 2.5/65.5.

3.6 First design

The rst design of the system consisted of three separate PCBs (printed circuit boards) as seen in Fig- ure 3.3. The rst PCB had a UART communication bus, a linear voltage regulator, a crystal oscillator and all of the CPU pins drawn to dierent connectors. Basically everything needed to get the micro- processor running and be able to communicate with a computer. This PCB is the left-most one in Figure 3.3. The second PCB was a three-phase inverter board. The components used was three switch controlling ICs (integrated circuits), six MOSFET switches and three shunt resistors. This card is in the top-right corner of Figure 3.3. As can be seen from the gure, three sets of cables goes out of this PCB. First, there is a yellow, red and black cable going into the motor. These are the three-phase connectors for the motor currents. Then there is a wide 16 pin IDC connector going between the inverter board and the CPU board (and going out of the picture for a little while). This connector contains the cables for the six switches of the inverter. The last set of cables are the red and black cables going down to the last PCB. These cables are connected to the shunt resistor and transports the signal down to the measurement circuit on the last PCB. The third PCB is a card made for an entirely dierent project, but since it had some high performance OP-amps (operational amplier) as well as all the support circuits needed to make them work, it was (after a couple of modications) used as a current measurement circuit. Only the part of the PCB inside the white circle was actually used by this project and the components used were only a couple of resistors and an OP-amp for each red-black connector couple. The three white cables going out of the picture are the outputs of the current measurement circuit and enters the analogue-to-digital converter in the CPU via the 14 pin IDC connector at the bottom of the CPU card.

Figure 3.3: A view of the dierent printed circuit boards used in the rst design of the system.

3.7 Second design

The second design of the system was done by integrating all necessary components on one single PCB. This PCB, without the ground planes drawn out for easier viewing, can be seen in Figure 3.4. The legend

21 points out where specic important components are located on the PCB. The schematics for the PCB can be found in appendix 6.2. The schematics for this PCB was drawn by Andreas Nilsson at Research Electronics and the CAD was done by me in a program called Tango PCB. The PCB is fed 36 V as input voltage at no 1 in Figure 3.4, since that is the rated voltage for the motor. This voltage is reduced to 12 V by an LM317 linear voltage regulator located at no 5. The 12 V is used to power the three no 9 ICs, which controls the switching of the six power inverter switches. There are also two dierent LM340 linear voltage regulators which regulates the 12 V down to 5 V, marked as no 6. The reason to have two dierent regulators is to create separate circuits so that noise is limited. Integrated circuits tend to use current in short, bursty segments and such behaviour tend to create a lot of noise. One of the 5 V regulators powers a circuit (no 12) used to create -5 and +10 voltages used to drive the operational ampliers of the current measurement circuits, no 7. The current measurement circuit is placed very close to the shunt resistors, marked as no 8. The second of the 5 V regulators is used to power the microprocessor (no 10), and the communication ICs (no 14 and 13). The system in real life can be seen in Figure 3.5 with everything connected. The big heat sink seen in the upper parts of the system is due to bad choice of voltage regulator. Using a linear regulator to bring the 36 V input voltage down to 12 V produced a lot of heat. The 12 V part of the PCB used about 0.15 Ampere of current so the power loss in the linear regulator will be (36 − 12) ∗ 0.15 = 3.6 watt. This required quite a big heat sink to dissipate. In the next production iteration the linear regulator will be replaced by a switched voltage regulator which produces almost no heat.

Figure 3.4: The printed circuit board used for the second layout of the system.

22 Figure 3.5: The second design of the system with everything connected.

3.8 Programming

The embedded software used in the microprocessor was developed in IAR Embedded Workbench and written entirely in C. Everything needed to make the system work in terms of software will be covered in this section.

3.8.1 Main method The main loop of the software has the following structure: int main ( ) { init_CPU_clock ();

__disable_interrupt (); init_IO_ports (); init_interrupts (); __enable_interrupt ();

//Initialize all units such as UART, com−port, timer etc ...

//Initialize all global variable values ...

FOC_startup (); //Do zero−current AD measurements, and init FOC

while (encoder_foundZphase==0)

23 { syncEncoder=1; //spins the motor at a low speed } syndEncoder=0; delay =5; while ( delay ) ; //Wait some time until motor stops moving

while ( 1 ) //Main loop { tgt_inp ( ) ; i f (print_info_flag) { //print info for data collection ... } } } All of the initialization functions looks almost the same. The features of the microprocessor used in this project are;

• 16-bit timer

• Vector engine, calculation unit for motor control

• Programmable motor driver, 3-phase PWM generator and generator of synchronous AD converter start triggers

• Encoder input circuit, counter and comparator for absolute position detection

• General-purpose serial interface (UART), communication circuit

• 12-bit AD converter, analogue-to-digital (AD) converter circuit

• General-purpose Input/output ports In order to initialize these you just write to a bunch of registers in the order specied in the manual. For example, this is the code to initialize the Vector Engine in the microprocessor: void init_VE ( void ) { VEEN=0x3 ; VEERRINTEN=0x2 ; VEREPTIME=0x10 ; VETRGMODE=0x8 ;

VEMODE1=0x2 ; VEFMODE1=0x50 ;

VEMDPRD1=0x7d0 ; VEEMGRS1=1; } Once all the initialization is done, the next step is to do the FOC start up. This is an automated process where the microprocessor saves the AD values from the current measurement circuit while no current is owing into the motor. This is done three times with some delay in between to minimize the eect of disturbances on the measurements.

24 The next step is to look at the encoder synchronization. After the initialization of the programmable (PMD), an interrupt is turned on so that every time the PWM counter reaches the maximum value a function called PWMinterrupt() is called. This is used to either start the main FOC loop (most of the time) or to start a smaller FOC loop only used for encoder synchronisation. This small FOC loop is shown in the next code segment. void VE_syncEncoder( void ) { i f (VESCHTASKRUN&0x020) print_to_com0("Error , . . . " ); VETHETA1 += 1 ; //spin around until Z is found

i f (EN1TNCR&0x1000 ) { ENC_foundZ=1; //encoder Z found }

VEACTSCH=0x10 ; //Schedule 1 VETASKAPP=0x50 ; VECPURUNTRG=0x2 ; //run cpu i f (VEERRDET&0x2) print_to_com0("PWM interrupt detected .\n" ); }

3.8.2 Vector Engine Let's look at the purpose of the vector engine (VE). The VE is a part of the microprocessor which has its own CPU and hardware so that the main CPU can be free to do other things. To control the VE, you specify a schedule to be executed. After specifying a schedule, you choose a task for the VE to start executing from. The VE will then do all tasks from that task to the last task in that specic schedule. The dierent tasks are all used in the FOC loop and are as follows;

• Current control, this is PI control of the currents

• SIN/COS computation, calculates sin/cos of the current θ

• Output coordinate axis conversion, this does the inverse Park transformation

• Output phase conversion, this does the space vector modulation

• Trigger generation, calculates PWM compare values for the phases

• Input processing, this collects the measured current values

• Input phase conversion, this does the clarke transformation

• Input coordinate axis conversion, this does the Park transformation There are four schedules available to choose from. The rst schedule (schedule 0) is Individual task execution where you specify just one task to execute. The second schedule executes all task (schedule 1). The third schedule (schedule 4) executes all tasks except the current control (useful for forcing the motor to move without any measurements of the currents) and the last schedule (schedule 9) only executes Output control, trigger generation and Input processing. The last schedule is used to do the zero-current AD measurements. The small FOC loop in the code segment above shows how you use the vector engine properly. First there is a small safety check so that no other schedule is currently executed. Then, θ is increased by one. A PWM/FOC frequency of 20 kHz where you increase θ by one for every loop means one revolution will take approximately 6.5 seconds. If Z is found the motor is stopped and the synchronisation complete. Then, the rst schedule and the Current control task (0x50) are chosen and the VE CPU started. Finally a last safety check is conducted to check that the CPU didn't get stuck/took too long during calculations.

25 3.8.3 Key press detection loop

The next part of the program is the main loop. By pressing w on the keyboard the print_info_ag turns true which prints chosen variables at a chosen speed. This is how the data for all the experiments in this project were collected. The tgt_inp() function detects when data is being sent to the microprocessor, from a computer for example. Its structure is as follows; void tgt_inp ( void ) { i f (char_receive_count > 0) { char_receive_count −−; char=∗receive_pointer++; switch ( char ) { case ' h ' : { ... }

...

default : { print_to_com0("%c has no command attached to it ," , char ); print_to_com0(" press 'h' for avaliable commands.\n"); break ; } } } } Every time a character is received on the UART it is put into a receive buer and char_receive_count is increased by one. The variable receive_counter is always pointing at the current location of the receive buer, and once the CPU executes the tgt_inp() function it checks if there are newly received characters in the buer. If a character is received, some commands corresponding to that character is executed with the switch-statement. Some of the most useful commands are h (prints a help menu), + and - which controls the rotation speed of the motor, p which turns the FOC loop on/o, m which changes between dierent driving modes, c which allows you to enter a new Iqref etcetera. The print_to_com0 command is a function that sends characters one at a time via the UART to the computer, where a program made by Research Electronics is used to receive the data and communicate with the microprocessor.

3.8.4 Field Oriented Control loop Before looking at the main FOC loop a few supporting functions need to be looked at. Since the system was tested on its own, a temporary function that created motor commands had to be implemented. This function was made as simple as possible: void MC_tick( int tick , int d i r ) { i f ( d i r ==0) { MC_pos += t i c k ; i f (MC_pos >= EN1RELOAD) MC_pos −= EN1RELOAD;

26 } else { MC_pos −= t i c k ; i f (MC_pos < 0) MC_pos += EN1RELOAD; } } Here, the variable MC_pos is the position command of the system. It's value can be from 0 to the maximum encoder value 8192 (denoted EN1RELOAD). Dir is a variable which decides if the motor should spin clockwise or counter clockwise. This function will be replaced with the two inputs in the nished cascade servo system. Another simple function is a function which calculates the shortest distance between two encoder values, with the result being able to be both positive and negative: int encoder_distance( unsigned int curr , unsigned int r e f ) { i f (ref >= curr) i f ( ( r e f −curr )<( curr+EN1RELOAD−r e f ) ) return r e f −curr ; else return r e f −curr−EN1RELOAD; else i f ( ( curr−r e f )<( r e f+EN1RELOAD−curr ) ) return r e f −curr ; else return r e f −curr+EN1RELOAD; } Again, EN1RELOAD is 8192, the maximum encoder value. An example: If curr = 10 and ref = 8180, this function would return -22. This function is used to calculate the position errors plotted in the experiments chapter. There is also a similar function to calculate the distance between two θ values. The biggest dierence is that EN1RELOAD is replaced by the maximum θ value of 65536. Now let's look at the main FOC loop. To save space, some driving modes mostly used for testing and some additional statements at various locations have been removed. void FOC( void ) { i f (VESCHTASKRUN&0x020) print_to_com0("Error , . . . " ); MC_tick(MC_speed ,MC_ccw) ;

MC_dist=encoder_distance (EN1CNT,MC_pos); THETA_dist=theta_distance (EN1CNT,VETHETA1) ;

i f (DC_loop==0) { DC_loop=20−1; DC_error=MC_dist ; //Wanted pos error = 0 => ref = 0 DC_int_ccw = DC_ki∗DC_error + DC_int_ccw; //some i f −statements to limit the integral part not shown DC_output = DC_int_ccw + DC_error∗DC_kp; } else { DC_loop−=1;

27 }

MC_speed_temp = ( int ) DC_output; MC_buffer += DC_output − MC_speed_temp ; i f (MC_buffer >= 1) { MC_buffer −= 1 ; MC_speed_temp += 1 ; } //not shown to save space: (else, do the opposite)

i f ( ! ( THETA_dist >= 16384) && ! ( THETA_dist <= −16384)) { VETHETA1 += MC_speed_temp ; } //not shown to save space: (else, do the opposite)

VEACTSCH=0x10 ; //Schedule 1 VETASKAPP=0x50 ; VECPURUNTRG=0x2 ; //run cpu i f (VEERRDET&0x2) print_to_com0("PWM interrupt detected .\n" ); } The FOC loop starts by updating the position command, based on what the speed and direction variables are currently set to (the version shown here is not exactly as it is, but if you assume speed can be non-discrete values such as 0.05, it is close enough). The distances to the new goal in both θ and encoder points are then calculated. The DC_loop variable determines how often a new speed should be calculated. Using a FOC frequency of 20kHz and a DC_loop value of 20, the frequency of the speed controller loop is 1000 Hz. If it is time to update the speed, the position error PI controller recalculates the speed. Since the reference position error is zero, the PI controller error signal is simply the current distance to the goal. There is some safety code to prevent the integral part of the PI regulator to grow too large not shown as well. Once a new speed has been calculated, it is rounded down to the nearest integer. The remained is saved in a buer variable which grows for each FOC loop until it grows bigger than one or smaller than minus one, at which point it is used to increase/decrease the speed by one and then starting over again. The last if-statement is used to limit the position of the electric vector in case the rotor is stuck. If you set θ to a xed value and forcefully move the rotor, you notice that maximal torque is produced when the rotor is moved 90◦ electrical degrees from the set position. So by limiting the distance between the rotor and the electrical vector position to a maximum of 90/360 ∗ 216 = 16384 points of θ, we ensure that a maximum torque is produced if the rotor gets stuck.

28 Chapter 4

Experiments

4.1 Setup

The printed circuit boards were connected to a standard power supply unit, capable of providing up to 30 V and 5 A. Troubleshooting was performed using a standard multimeter to detect erroneous voltages or faulty component placements. All data values plotted were obtained by the measurement circuits on the PCBs, and collected via the UART circuit to a computer. A program made by Research Electronics was used to send keystrokes to and receive data from the microprocessor.

4.2 Testing the rst design

For the rst design, some experiments were conducted to see how good the current control could become,

as well as how good position control could be obtained. The reference values were set to Id,ref = 0 and Iq,ref = 8000. The motor voltage was set quite low, about 16-18 V. The current owing into the motor was also quite low, about 0.3 - 0.6 A. This is because of the limitations of the rst system hardware layout, where the thin cables and the separate PCBs caused problems with the common ground when the current was too high. Also, the voltage regulator that supplied the integrated circuits on the PCBs could not handle more than about 20 V before breaking. For the current control, the PI-controller on the microprocessor

was used and the Kp and Ki were altered to try and get as good control as possible. For the position control an simple home made method was used. The motor was set to rotate at 0.8 Hz by specifying how much the θ variable was changed every FOC loop. As stated earlier in Section 3.2, θ has to be increased 16 points for each encoder point. The PWM/FOC frequency was 20 kHz, so the speed (points added to θ every FOC loop) was then: 16 ∗ (0.8 ∗ 8192)/20000 ≈ 5.24 points per loop. Then, if the distance between the commanded position and the position given by the encoder was too large, the speed was either increased or decreased by one point for that loop. Since the θ register can only hold discrete values, all speed values were round down to the closest integral and a buer variable stored the non-integral part of θ until the next loop, where it was added to θ again. Figure 4.1 shows the results of the experiments for the rst system layout with a sampling rate of about 114 Hz (one sample every 8.75 ms). Position error is dened as the dierence between wanted and actual position. For the current graphs, the values of the Y-axis are not very important except for illustration purposes. It is simply the value given from the analogue-to-digital converter saved as a xed point variable but read as an integer. In Figure 4.1 the dierence is shown between the commanded position and the actual encoder position

as well as the speed multiplied by ten in the upper graph, and the Id and Iq current in the lower graph. It easy to see that when Ki = 1 and Kp = 1 the current control is not very good. There is one huge current spike about twice every mechanical revolution.

29 Figure 4.1: Upper graphs: Position error and speed during a current control test of the rst design. Lower graphs: The d and q axis currents

When the PI controller is set to Kp = 1000 and Ki = 10 the huge current spikes are dampened quite a lot, but both id and the position seems to be a lot more periodic. The last current controller result for the rst design can be seen in the two rightmost gures. For

this test, the PI controller was set to Kp = 10000 and Ki = 1000. Compared to the other results, all the periodic errors in the current seems to have disappeared. The control of the current looks to be quite smooth and nice except for some white noise. The source of this white noise was most likely the sub-optimal set-up of the system, with three separate PCBs and not very good grounding, which resulted in noisy current measurements. The dierence between wanted and actual position almost looks like white noise as well in this example. The position control of the motor turned out to be quite a disappointment for all tests done on the rst layout of the system. As you can see from the three dierent setting of the current controller presented in this chapter, the position error of the motor is quite rough, sometimes diering as much as 150 encoder points from the commanded angular position (≈ 6.6 degrees). Also, it seems like the position dierence gets more noisy when the current control gets more smooth. After these results were gathered, at least one of the PCBs broke during an experiment with higher voltage.

30 4.3 Testing the second design

For the second system design, a software implementation of a PI controller was used to control the speed of the motor during all tests. Various tests were performed to properly tune the PI controller for the current, as well as for the PI controller of the speed. In most of the recent research on FOC, the output from the speed PI controller is a reference current as discussed in Section 2.2. In this project the output from the speed PI controller is instead the increment of θ for every FOC loop. The benet of this is that the current consumption of the motor is more or less constant, and it's easier to handle situations where the "base speed" of the motor is unknown. In order to test the motor in a real environment, a small disc of wood was built and mounted on the motor. The rotor inertia, as seen in Figure 3.1, was 0.173 kgcm2. A general rule of thumb is to keep the inertia ratio below 10:1, which means that the inertia of the load should be kept at a maximum of 1.73 kgcm2. In this case, the small disc of wood had a weight of 67 g and a radius of 3.6 cm. This corresponds of an inertia of mr2 0.067∗3.62 kgcm2. The inertia ratio is then 0.434 , which is Iz = 2 = 2 = 0.434 0.173 = 2.5 : 1 satisfactory. The wooden disc can be seen in Figure 4.2 next to the motor.

Figure 4.2: The motor and the wooden disc used as a load during the tests of the second system design.

As in the rst system design, the sampling rate of all gures shown here is about 114 Hz and speed refers to how much the electric vector angle θ is increased for each FOC loop. Position error means the dierence between wanted and actual position. The pulse-width modulation and FOC loop frequency is 20 kHz.

4.3.1 Determination of current PI controller settings In Figure 4.3 the appearance of the pulse-width modulation can be seen at the same time as the currents, for two very dierent settings of the current PI controller. In the two gures to the left, the current PI

regulator is set to Kp = 8 and Ki = 3. For the two gures to the right, the settings are Kp = 20000 and Ki = 1000. For the left graphs, the current control is not very strict, but the shape of the pulse-width modulation is almost perfect. On the other hand, in the right graphs, the current control seems to be almost perfect, but the shape of the pulse-width modulation is not very smooth. In this test no speed controller was used, the variable θ was simply increased by one every FOC loop so the motor would rotate.

From this experiment, the values of Kp = 12 and Ki = 4 for the current PI controller were chosen. Later tests not included in this report showed that the values doesn't really make that much of a dierence when it comes to the most important thing, the position error of the rotating motor.

31 Figure 4.3: A view of how the current PI controller settings aects both the shape of the current and the shape of the pulse-width modulation.

4.3.2 Determination of speed PI controller settings The speed PI controller loop was executed once every twenty FOC loops, which translates to 1000 Hz. In order to nd a good starting point for the tuning of the speed PI controller, Ziegler-Nichols tuning rules were used. They are as follows:

1. Set Ki = 0

2. Change Kp until the system oscillates with a constant amplitude, this value is denoted Ku

3. Find the oscillation period Tu when this happens.

Kp 4. Set Kp = 0.45Ku and Ki = 1.2 Tu

This gives a good basis from where additional adjustments can be made. In Figure 4.4, KP = 0.08 and KI = 0 and this makes the system oscillate with an almost constant amplitude. The interesting oscillations are the small ones, since the bigger ones occur for dierent reasons and indierent from the controller settings. The distance between the oscillations is about 8 samples, which translates to 0.00875 ∗ 8 ∗ 1000 = 70 Kp controller loops. Following Ziegler-Nichols rules, this results in: Kp = 0.45Ku ≈ 0.03 and Ki = 1.2 = Tu 0.036 Using and , the resulting position error over time can be seen in 1.2 70 = 0.0006 Kp = 0.03 Ki = 0.0006 Figure 4.5. A longer test, about twenty thousand samples, can be seen in Figure 4.6. In this gure the position error is plotted against the rotor position, and it seems like the position error is quite dependant on the rotor position.

32 Figure 4.4: The system is oscillating with an almost constant amplitude when KP = 0.08 and KI = 0.

4.3.3 Iterative Learning Control in order to reduce periodic disturbances The periodic disturbances seen in Figure 4.6 are probably a type of torque ripple, as explained in Section 2.7. In order to reduce these torque ripples, an algorithm called Iterative Learning Control (ILC) was implemented. In order to test this algorithm, over twenty thousand samples were collected. The root mean square error of one hundred samples at a time was calculated and can be seen in Figure 4.7. It seems like the positioning error does indeed get smaller using ILC. However, the memory size of the Toshiba microprocessor was not big enough to implement ILC in a satisfactory way. The 8192 measurable angular positions had to share only 512 position variables, resulting in segments of length sixteen. This probably severely limited how much ILC could improve the results.

33 Figure 4.5: Upper graph: Position error during a speed PI control test with KP = 0.03 and KI = 0.0006. Lower graph: The d and q axis currents.

Figure 4.6: The position error is plotted versus the rotor position for twenty thousand samples.

34 Figure 4.7: Using ILC reduces the root mean square of the position error.

35 Chapter 5

Results and Discussion

The results show that the performance requirement of a position error less than 12.5 encoder points is met. The root mean square of the position error of 18071 samples was 3.34 encoder points, which is about 0.15 degrees. Using iterative learning control, this RMS value can be decreased further, to about 2.5 − 3 encoder points. The eect of ILC is probably limited by the small memory of the microprocessor which decreases the "resolution" of ILC to segments that are sixteen encoder points wide. These results were obtained when tuning the speed PI controller at a xed speed. Increasing the speed and using the same PI controller settings seems to decrease the accuracy of the position control. The PI controller was never tuned for a higher speed, so if performance also degrades when the speed is lower than the speed which the PI controller was tuned for is not known. When the position error is used as control signal to the speed PI controller the current consumption of the motor is not minimized. The current is minimized if we use the least torque needed and the electric vector is exactly ninety degrees from the rotor position. When manipulating the electric vector as in this project, a reference current is set and the electric vector is changed until enough torque is produced so that the rotor starts to move. This means that a lot more torque is available but not utilized. In the beginning of the project a lot of time was spent trying to set up the microprocessor properly and that turned out to be quite troublesome because the manual had some severe errors. For example, for one of the registers (VEMODE1) the manual tells you explicitly to always write zero to certain bits (4 and 6). But you have to write ones to these bits or an important feature of the microprocessor called Vector Engine will not work at all. An impressive feature of the microprocessor is the way it handles the pulse-width modulation levels. As stated in Section 3.3, the maximum PWM counter value is 2000. This means that the compare value of the three phases can only take discrete values between one and two thousand. This should severely decrease the resolution of the outputted current. Figure 2.10 in Section 2.5.2 spans the which contains all possible currents for the PWM output using space-vector pulse-width modulation. But if the compare values are limited to 1 to 2000, this space should consist of dots, instead of being a continuous space. The problem would get even worse with higher PWM frequency. Using a 50 kHz PWM frequency results in a maximum counter value of just 800. Also, using a shorter current vector (less current) would also result in a larger discretization error. But it turns out that the microprocessor actually solves this by itself by using a PWM-like algorithm on the compare values. If you set θ to a xed value where you might expect problems to arise and observe the compare values, it can be seen that they rapidly change between two adjacent values in order to avoid discretization errors. If the "true value" of the compare value should be for example 14.2, the compare value will be 14 about 80% of the time and 15 during 20% of the time.

5.1 Dead-time aecting the performance

During the rst weeks of experiments on the second design of the system the performance was much worse than the ones presented in Chapter 5. A typical plot of the position error over time can be seen in

36 Figure 5.1, as well as the phase currents (these are scaled to a maximum value of 150). The interesting feature here is that as soon as one of the phase currents cross the zero current section, there is a clear distortion of the phase current. This causes the position error to quickly rise to about seventy encoder points, equal to about three degrees of error. The cause of these distortions is a feature of the pulse width modulation called dead-time. As explained in chapter 2.5.2 in an inverter leg with two power switches, one of the power switches is always on and one is always o. When the inverter leg then switches state, both of the power switches needs to change. Since they both change at the same time, this could cause some kind of situation when one switch is on and the other one manages to nish switching from o to on. In this case, a short circuit situation will happen. To prevent this, a dead-time is introduced which is a time lag between the starting times of the switching. In this project that time lag was 500 nanoseconds. There are a lot of research available on this subject, and on how to compensate for this eect [18]. But in this project, this problem was solved by simply setting the dead-time to zero in the microprocessor. According to the data sheet of the inverter gate drivers, the turn o-time is shorter than the turn-on time. That means that something almost like dead-time is already built into the hardware of the circuit, and an additional software-controlled dead-time is not needed, and does more harm than good.

Figure 5.1: The position error compared to the phase currents when using a dead-time of 500 nanoseconds.

37 Chapter 6

Conclusions and suggestions for future work

6.1 Conclusions

The start of this project was quite slow due to problems with the microprocessor and how to use it, but once that part was solved three printed circuit boards were built and connected together to create a rst design of the system. The experiments done on this system showed that the performance of both the hardware and software was severly lacking. The hardware was therefore completely redesigned and placed on a single printed circuit board, and the software was rewritten to control the speed via a PI controller. The experiments on the redesigned system shows that is is possible to build a very cheap servo system around a BLDC motor with very good performance using FOC. The root mean square of the position error was about 3.3 encoder points for a xed speed and xed rotation direction, which is about 0.15 degrees. Using ILC, this error was further reduced to about 2.5 − 3 encoder points, but memory and resolution problems reduced the practical use of this algorithm.

6.2 Suggestions for future work

A lot of more work can be done on the programming part. For instance an interesting issue is how to control the rotation speed in a good way. As stated in chapter 4.3, for this project the speed controller input is the position error and it controls the position of the electrical vector. But imagine that you set the electrical vector to always be 90◦ ahead/behind the rotor position, and then you slowly increase the current (starting from zero) until the motor starts to move. This way you could always get the maximal torque per current and use the reference current to control the speed. This is how systems built around FOC generally work from what I've seen. A problem one would need to solve if attempting this is how to implement a good controller. How do you create a controller that both tries to minimize the current consumption and is quick to react to load changes without causing a huge position error? Another way to implement this would be to utilize the existing function theta_distance(). This function returns the distance between the rotor and the electrical vectors position. A controller could easily be implemented to try and keep this distance as close as possible to 90◦ by manipulating the value of the reference current. This would be sort of a tradeo between a strict "90◦-only" algorithm and the algorithm presented in this project which does not try to minimize current consumption at all.

38 Appendix

A1. Schematics for the second system design

These schematics were drawn by Andreas Nilsson at Research Electronics.

A B C D

1 1

PH1 PH2 PH3

ISGND3

GND GND GND 2 T1 ISGND1 T2 ISGND2 T3 2 R1 R2 R3 10 10 10 R4 R5 R6 10 IRFR3806 10 IRFR3806 10 IRFR3806 IC1 IC2 IC3 8 1 V12 8 1 V12 8 1 V12

LO VDD C1 LO VDD C2 LO VDD C3 GND 7 2 ISNS1 GND 7 2 ISNS2 GND 7 2 VSS HB VSS HB VSS HB ISNS3 1uF 1uF LI1 6 3 LI2 6 3 LI3 6 3 1uF LI HO LI HO LI HO HI1 5 4 HI2 5 4 HI3 5 4 HI HS HI HS HI HS LM5101AM V24 LM5101AM V24 LM5101AM V24 T4 T5 T6 10 10 R7 R8 10 R9 3 P8 P9 P10 3 IRFR3806 IRFR3806 IRFR3806

P11 TAB:n r ven Vout ISGND och ISNS skall ha korta avstnd till OP IC4 ... och en bit frn kraftiga strmbanor V24 3 2 V12 VI VO A

1 LM317 C4 C5 1uF R10 1uF Title Servo drive PWR part

4 560 Size Number Rev 4

C9 P12 1mF A4 A R11 C6 C7 C8 4700 110909 SAE GND 100nF 100nF 100nF Date Drawn by Filename SDRV.S01 Sheet 1 of ABCD

Figure A.1: THSERVO1

39 A B C D

V10

VAL 8 ISGND1R14 2 - IC8:A R6 1 ISAD1 VAL OPA2277 R16 3 10 ISAD:s till AD-in p CPU 1 ISNS1 + C18 1 4 R17 33nF R7 V5- VAL 1K 1uF V10 C20 GND

R18 VAL ISGND2 6 - IC8:B R8 7 ISAD2 OPA2277 ISNS2 R21 VAL 5 10 + C21 R22 VAL 33nF R9 1K 1uF V10 V10 C23 GND

R28 VAL 8 ISGND3 2 - IC11:A 2 R10 2 1 ISAD3 OPA2277 ISNS3 R31 VAL 3 10 + C24 4 R32 VAL 33nF R11 V5- 1uF V10 1K

C26 GND

6 - IC11:B 7 OPA2277 GND 5 +

V5REF till Toshibas VREF R15 och CAP:s nra CPU 3 R15 3 V5P V5REF 0 100nF 100nF C34 C35 C36 C62 100nF 22uF V24 R33 VAL GND IC17 V12 1 3 V5 R34 VAL VSPAD VI VO G C41 LM340 2 GND 1uF V5 GND VSPAD speglar batterispnning 100nF 100nF 100nF 100nF 100nF C10 100nF V10 C42 V5 C43 C44 C45 GND C46

4 4 P1 P2 P3 P4 V5 Title 24 bit A/D board 100nF 100nF 100nF Size Number Rev GND V5 +12 V5- C51 C52 C53 GND A3 A Date 130917 Drawn by SAE Filename VIBR2.S02 Sheet 2 of 3 A B C D

Figure A.2: THSERVO2

40 A B C D

IC16:A IC16:B IC16:C

1 2 3 4 5 6

1 4069 4069 4069 1 R23 C27 39pF R24 1M 22K

1 V10 V5 R29 R27 2 2.2K IC13 2 5 V5P 4 OUT IN 1 3 REF EN 2 GND GND 22uF C56 LM4120-5.0 GND 10uF

C57 GND 7 14 V5 GNDVCC GND T1 4069 V5P lgpassfiltreras i S02 till Toshiba VREF IRLML9303 12 13

IC16:F D5 BAT54 1 IC16:D

3 R25 3 BAT54 22uF 8 9 V10

D4 C58 4069 C59 1 10uF C32 R26 220 GND D2 4069 V5- 10 11 R30 BAT54 22uF T2 C30 C31 IC16:E Title D3 DC/DC PWR circuit 22uF 22uF BAT54 4 IRLML2030 Size Number Rev 4 GND A4 A Date 130917 Drawn by SAE Filename VIBR2.S03 Sheet 3of 3 ABCD

Figure A.3: THSERVO3

41 A B C D

1 IC5 2 1 1 3 V5D V5D V12 VI VO C11 22PF X1 2 10uF C12 G C13 C14 C15 C16 C17 C19

J1 LM340 11 2 1 V5 J2 GND 1uF 1uF 100nF 100nF 100nF 100nF 1

C25 26 10 V5 GND 10MHz 32 28 GND V5 GND GND V5D IC7 C28 100nF C22 100nF GND

R12 D1 22PF 27 25 PA2 IC6 XTAL1 PA.2/TB1IN 29 48 PA4 1 10K XTAL2 PA.4/SCLK1 C1+ C29 47 TXD1 2 3 PA.5/TXD1 V+ C1- J3 BAS16 GND 42 46 RXD1 6 4 AGND PA.6/RXD1 C33 V- C2+ 2 V5REF 43 5 100nF VREF 0 C2- 1 GND 31 16 PB3 TXD0 11 14 GND 1 C37 1uF MODE PB.3/SWDIO 100nF T1IN T1UT 34 15 PB4 TXD1 R13 10 7 2 RESET PB.4/SWCLK T2IN T2UT 30 14 PB5 RXD0 12 13 3 V15 PB.5/SWV R1UT R1IN 33 13 PB6 RXD1 9 8 4 GND V30 PB.6/TDI R2UT R2IN 5 BOOT 12 1 PD6 PF.0/BOOT * PD.6 R19 0 PF1 24 MAX202 2 PF.1/TB7OUT J4 2 EA 21 17 TXD0 PF.2/ENCA1 PE.0/TXD0 GND 15 16 V5D EB 22 18 RXD0 GND VCC PF.3/ENCB1 PE.1/RXD0 C38 4.7uF EZ 23 19 SDA PF.4/ENCZ1 PE.2/SCLK0 R20 C39 20 SCL 4.7K PE.4/TB2IN HI1 2 45 PE6 PG.0/U1 PE.6/TB3IN LI1 3 44 PE7 100nF C40 PG.1/X1 PE.7/TB3OUT HI2 4 PG.2/V1 V5D LI2 5 35 POTAD 4.7uF PG.3/Y1 PI.3/AN2 HI3 6 GND PG.4/W1 R35 LI3 7 36 ISAD1 IC9 PG.5/Z1 PJ.0/AN3 EMG 8 37 ISAD2 PG.6/EMG1 PJ.5/AN8 4.7K 7 1 GND OVV 9 38 ISAD3 R36 TEST A0 PG.7/OVV1 PJ.6/AN9 39 VSPAD PJ.7/AN10 SCL 6 2 40 PK0 4.7K SCL A1 PK.0/AN11 41 PK1 PK.1/AN12 SDA 5 3 SDA A2 3 TMPM373FWDUG X24C04 3 GND 4 8 V5D GND VCC C47 J8 J5 100nF 3 GND GND 1 2 EZ 2 C48 EA 3 4 V5D 1 EB 5 6 POTAD 100nF V5 IDC6 RELENC R38 V5D R37 4.7K J6 V5D 1 2 GND 10K 3 4 PE6 5 6 RXD1 BOOT 1 Title TXD1 7 8 PA4 2 TMPM373 simple system 4 Size Number Rev 4 ABSENC J7 GND A4 A Date 130620 Drawn by SAE Filename SERVO.S01 Sheet 1 of 1 ABCD

Figure A.4: THSERVO4

42 Bibliography

[1] D. Casadei, F. Profumo, G. Serra, and A. Tani, Foc and dtc: two viable schemes for induction motors torque control, , IEEE Transactions on, vol. 17, no. 5, pp. 779787, 2002.

[2] J. P. John, S. S. Kumar, and B. Jaya, Space vector modulation based eld oriented control scheme for brushless dc motors, in Emerging Trends in Electrical and Computer Technology (ICETECT), 2011 International Conference on, pp. 346351, IEEE, 2011.

[3] S.-B. Lee, Closed-loop estimation of permanent magnet synchronous motor parameters by pi con- troller gain tuning, Energy Conversion, IEEE Transactions on, vol. 21, no. 4, pp. 863870, 2006.

[4] P. C. Krause, O. Wasynczuk, S. D. Sudho, and S. Pekarek, Theory of brushless dc , in Analysis of electric machinery and drive systems, vol. 75, pp. 261265, John Wiley & Sons, 2013.

[5] C. Lee and W. Pang, A brushless speed control system using fuzzy rules, in Power Electronics and Variable-Speed Drives, 1994. Fifth International Conference on, pp. 101106, IET, 1994.

[6] R. Gabriel, W. Leonhard, and C. J. Nordby, Field-oriented control of a standard using microprocessors, Industry Applications, IEEE Transactions on, no. 2, pp. 186192, 1980.

[7] Field orientated control of 3-phase ac-motors. Literature Number: BPRA073, Texas Instruments, 1998.

[8] J. Zambada and D. Deb, Sensorless eld oriented control of a pmsm, in Application Note 1078, no. DS01078B, Micropship Technology Inc., 2010.

[9] J. R. Mevey, Sensorless eld oriented control of brushless permanent magnet synchronous motors. M.S. thesis, Dept. Elec. and Comp. Eng., Kansas State University, Manhattan, 2009.

[10] K. Zhou and D. Wang, Relationship between space-vector modulation and three-phase carrier-based pwm: a comprehensive analysis [three-phase inverters], Industrial Electronics, IEEE Transactions on, vol. 49, no. 1, pp. 186196, 2002.

[11] H. W. Van Der Broeck, H.-C. Skudelny, and G. V. Stanke, Analysis and realization of a pulsewidth modulator based on voltage space vectors, Industry Applications, IEEE Transactions on, vol. 24, no. 1, pp. 142150, 1988.

[12] L. Zhang, C. Wathanasarn, and F. Hardan, An ecient microprocessor-based pulse-width modula- tor using space vector modulation strategy, in Industrial Electronics, Control and Instrumentation, 1994. IECON'94., 20th International Conference on, vol. 1, pp. 9196, IEEE, 1994.

[13] F. Parasiliti, R. Petrella, and M. Tursini, Low cost phase current sensing in dsp based ac drives, in Industrial Electronics, 1999. ISIE'99. Proceedings of the IEEE International Symposium on, vol. 3, pp. 12841289, IEEE, 1999.

[14] S. Chi, X. Wang, Y. Yuan, Z. Zhang, and L. Xu, A current reconstruction scheme for low-cost pmsm drives using shunt resistors, in Applied Power Electronics Conference, APEC 2007-Twenty Second Annual IEEE, pp. 17011706, IEEE, 2007.

43 [15] W. Qian, S. Panda, and J. Xu, Speed ripple minimization in pm synchronous motor using iterative learning control, Energy Conversion, IEEE Transactions on, vol. 20, no. 1, pp. 5361, 2005.

[16] J. P. Yun, C. Lee, S. Choi, and S. W. Kim, Torque ripples minimization in pmsm using variable step-size normalized iterative learning control, in , and Mechatronics, 2006 IEEE Conference on, pp. 16, IEEE, 2006.

[17] D. Torres and J. Zambada, Single-shunt three-phase current reconstruction algorithm for sensorless foc of a pmsm, in Application Note 1299, no. DS01299A, Micropship Technology Inc., 2009.

[18] A. Oliveira, C. Jacobina, A. Lima, and E. Da Silva, Dead-time compensation in the zero-crossing current region, in Power Electronics Specialist Conference, 2003. PESC'03. 2003 IEEE 34th An- nual, vol. 4, pp. 19371942, IEEE, 2003.

44