control of marine current energy conversion system345686/fulltext01.pdf · control of marine...

80
UPTEC F10 048 Examensarbete 30 hp Augusti 2010 Control of marine current energy conversion system Erik Nyhlén

Upload: others

Post on 24-Mar-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

UPTEC F10 048

Examensarbete 30 hpAugusti 2010

Control of marine current energy conversion system

Erik Nyhlén

Page 2: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Teknisk- naturvetenskaplig fakultet UTH-enheten Besöksadress: Ångströmlaboratoriet Lägerhyddsvägen 1 Hus 4, Plan 0 Postadress: Box 536 751 21 Uppsala Telefon: 018 – 471 30 03 Telefax: 018 – 471 30 00 Hemsida: http://www.teknat.uu.se/student

Abstract

Styrsystem för ett marint strömkraftverk

Control of marine current energy conversion system

Erik Nyhlén

This thesis involves the development of a system for control of a marine currentenergy conversion system. The control system is developed on the principles of loadcontrol, i.e. it aims to control the rotational speed of the turbine by controlling thepower extracted from the generator. The system operates by feedback of thegenerator DC-voltage and current as well as the speed of the water currentpassing through the turbine. An IGBT-transistor controlled by anAVR-microcontroller executes control of the generator and hence the turbine. Adigitally implemented PID-controller serves as the fundamental automatic controlregime. The control system can be operated from a PC-application connected to themicrocontroller through a serial wire connection. From the graphical user interface ofthe PC-application the system operator can set the system control parameters andmonitor the state of the generator and turbine. The control system can be set tokeep the turbine operating at a desired tip speed ratio, rotational speed or generatorvoltage. Further, for purposes of indoor testing of the control system a separatesystem, a motor control system, was developed as a part of this thesis work. Thepurpose of the motor control system is to enable simulating the behavior of a turbinewith a motor driving the generator instead of an actual turbine. The motor controlsystem operates by control of an ACS800 variable frequency drive that is connectedto the motor. The motor control system allows its operator to feed in datadescribing the variations in water speed over time as well as data describing how thesimulated turbine's power coefficient depends on its tip speed ratio. From this datathe motor control system continuously calculates the torque that should be put onthe generator axis by the motor. Results from test runs of the system show that theperformance of the system is good. The system responds quickly to changes in thecontrol parameters. Also the system manages to keep the specified control parameterquite well even during rapid changes in the water speed.

ISSN: 1401-5757, UPTEC F10 048Examinator: Thomas NybergÄmnesgranskare: Sandra ErikssonHandledare: Katarina Yuen

Page 3: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Sammanfattning på svenska

Den växande efterfrågan av förnybar energi har lett en grupp forskare påAvdelningen för elektricitetslära vid Uppsala universitet till att undersökamöjligheterna att producera elektricitet från vattenströmmar. Genom desenaste årens utveckling inom kraftelektronik och permanent-magnetiseradesynkrongeneratorer, hoppas forskarna vid Uppsala universitet att det nu ärmöjligt att övervinna tidigare tekniska svårigheter, och utveckla en kommer-siellt hållbar lösning för kraftproduktion från vattenströmmar.

I forskningssyfte håller man nu på att utveckla ett system för produktionav elektricitet från vattenströmmar på Avdelningen för elektricitetslära vidUppsala universitet. Testanläggningen skall sjösättas i Dalälven i närhetenav Söderfors. Generator och turbin har specialutvecklats för att arbeta vid delåga rotationshastigheter som vattenströmmarna ger upphov till. Underhållär mycket kostsamt i marina miljöer, varför stor möda har lagts ner på attutveckla ett system som är så underhållsfritt som möjligt. Kraftelektronikskall användas för att styra turbinens hastighet för att maximera elproduk-tionen. Utvecklandet av ett styrsystem som kan användas till den planeradetestanläggningen i Söderfors var uppgiften för examensarbetet som presen-teras i den här rapporten.

Varje turbin har en optimal arbetspunkt, fackmässigt benämnd som tur-binens optimala löptal. Detta kan sägas vara den rotationshastighet därturbinen tar upp maximalt av rörelseenergin från den inkommande vatten-strömmen. Löptalet är förhållandet mellan hastigheten för turbinbladensyttersta spets och hastigheten för den inkommande vattenströmmen (eng.tip speed ratio). Naturligtvis är det önskvärt att kunna styra turbinen såatt den håller den hastighet som motsvarar det optimala löptalet för att påså vis maximera elproduktionen.

Enkelt beskrivet bestäms rotationshastigheten för en turbin av skillnadenmellan rörelseenergin som turbinen fångar från vattenströmmen och den elek-triska energin som tas ut ur generatorn. Genom att styra hur mycket effektsom tas ut ur generatorn är det således möjligt att styra turbinens hastighet.Denna princip kallas ibland för laststyrning och kan sägas vara fundamentetför det styrsystem som utvecklats genom detta examensarbete.

Styrsystemet implementerades med hjälp av en AVR-mikrokontroller, enslags mikrodator som används för inbyggda system. Mikrodatorn tar kon-tinuerligt in mätdata över generatorns DC-spänning, ström och hastighetenför vattenströmmen som flödar genom turbinen. Genom en IGBT-transistorstyr den hur mycket energi som skall tas ut från generatorn och därmed

1

Page 4: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

turbinens rotationshastighet. Styrning av IGBT-transistorn sker med hjälpav en digitalt implementerad PID-regulator. Till styrsystemet utveckladesockså ett PC-baserat användargränssnitt som gör det möjligt för systemop-eratören att interagera med styrsystemet via en seriell-kabelanslutning. FrånPC-gränssnittet är det möjligt att skicka styrparametrar till systemet samtövervaka systemets status. Systemet kan styras för att hålla en önskad ro-tationshastighet på turbinen, en önskad DC-spänning från generatorn ellerkanske framförallt för att hålla ett önskat löptal. I användargränssnittet log-gas och visas i realtid generatorns spänning, ström och effektuttag, turbinensrotationshastighet, löptal och effektupptag, IGBT-transistorns arbetscykelsamt vattenströmmens hastighet.

En labbuppställning upprättades för testning av styrsystemet. I labbupp-ställningen anslöts styrsystemet till en experimentanläggning i inomhusmiljöutvecklad av forskarna vid Uppsala universitet för att kunna utföra tester in-för anläggningen i Söderfors. I experimentanläggningen drivs generatorn aven motor styrd av en frekvensomriktare istället för en turbin. För att kunnatesta styrsystemet fullt ut blev det därför nödvändigt att även utveckla ettsystem för att styra motorn på ett sätt som simulerar beteendet hos en verkligturbin. Med detta avses att motorn skall leverera en effekt på generatoraxelnsom beror på den simulerade turbinens löptal. Motorstyrningssystemet somutvecklades tillåter användaren att mata in data som beskriver hur vatten-strömmens hastighet varierar över tiden samt data som beskriver hur densimulerade turbinens effektupptag beror på löptalet.

Från testkörningar framgår att övergripande design och implementering avstyrsystemet varit tillfredsställande. Resultaten från testkörningarna visaratt systemet är robust och klarar av att hålla valda styrparametrar väl trotsrelativt hastiga förändringar i vattenflödet. Misslyckade försök gjordes ävenpå att utveckla en alternativ styralgoritm, så kallad Maximum Power PointTracking. Denna teknik har fördelen att den inte kräver någon kunskap omhur turbinens effektupptag varierar med löptalet samt att den även tar hän-syn till hur förlusterna i generatorn varierar med dess rotationshastighet.Trots den tillsynes enkla teorin bakom denna algoritm framkom en del prak-tiska svårigheter som medförde att framgångsrik implementering av dennaalgoritm inte har hunnits med inom tidsramen för detta examensarbete.

2

Page 5: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Abbreviations

AC Alternating CurrentACS800 ABB ACS800 Variable Frequency DriveADCP Acoustic Doppler Current ProfilerAVR A common name for the series of microcontrollers developed by ATMELDC Direct CurrentDTC Direct Torque ControlGUI Graphical User InterfaceIGBT Insulated Gate Bipolar TransistorMCU MicrocontrollerMOSFET Metal Oxide Field Effect TransistorMPPT Maximum Power Point TrackingPID Proportional-Integral-Derivative controllerPM Permanent MagnetPWM Pulse Width ModulationRS-232 An interface for asynchronous serial data communicationTSR Tip Speed RatioUSART Universal Synchronous and Asynchronous serial Receiver and Transmitter

1

Page 6: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Contents

1 Introduction 41.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.2 Project specifications . . . . . . . . . . . . . . . . . . . . . . . 4

2 Theory 62.1 Power in a marine current . . . . . . . . . . . . . . . . . . . . 62.2 Power captured by a turbine . . . . . . . . . . . . . . . . . . . 62.3 Power control using IGBT fed with PWM . . . . . . . . . . . 72.4 Relation between voltage and rotational speed of a PM generator 92.5 Principles of load control . . . . . . . . . . . . . . . . . . . . . 102.6 MPPT (Maximum Power Point Tracking) . . . . . . . . . . . 122.7 Implementation of discrete PID controller . . . . . . . . . . . 13

3 System 153.1 System overview . . . . . . . . . . . . . . . . . . . . . . . . . 153.2 Experimental setup . . . . . . . . . . . . . . . . . . . . . . . . 16

3.2.1 Motor control system . . . . . . . . . . . . . . . . . . . 183.3 Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

3.3.1 Hardware overview . . . . . . . . . . . . . . . . . . . . 213.3.2 Microcontroller (MCU) . . . . . . . . . . . . . . . . . 223.3.3 IGBT driver . . . . . . . . . . . . . . . . . . . . . . . . 233.3.4 IGBT . . . . . . . . . . . . . . . . . . . . . . . . . . . 253.3.5 MAX232 . . . . . . . . . . . . . . . . . . . . . . . . . . 263.3.6 Voltage transducer LV25-P . . . . . . . . . . . . . . . 273.3.7 Current transducer HAIS 50-P . . . . . . . . . . . . . 293.3.8 AC/DC converter . . . . . . . . . . . . . . . . . . . . . 303.3.9 Power supply . . . . . . . . . . . . . . . . . . . . . . . 313.3.10 Circuit diagram . . . . . . . . . . . . . . . . . . . . . . 33

3.4 MCU software . . . . . . . . . . . . . . . . . . . . . . . . . . . 343.4.1 MCU software overview . . . . . . . . . . . . . . . . . 353.4.2 PWM library . . . . . . . . . . . . . . . . . . . . . . . 363.4.3 ADC library . . . . . . . . . . . . . . . . . . . . . . . . 403.4.4 USART library . . . . . . . . . . . . . . . . . . . . . . 44

2

Page 7: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

3.4.5 Load control library . . . . . . . . . . . . . . . . . . . 463.4.6 PID library . . . . . . . . . . . . . . . . . . . . . . . . 463.4.7 Motor control library . . . . . . . . . . . . . . . . . . . 483.4.8 Main program . . . . . . . . . . . . . . . . . . . . . . . 48

3.5 PC-application software . . . . . . . . . . . . . . . . . . . . . 503.5.1 Software architecture . . . . . . . . . . . . . . . . . . . 54

4 Results 564.1 Voltage control . . . . . . . . . . . . . . . . . . . . . . . . . . 564.2 Rotational speed control . . . . . . . . . . . . . . . . . . . . . 574.3 Tip speed ratio control . . . . . . . . . . . . . . . . . . . . . . 594.4 MPPT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

5 Discussion and conclusions 62

References 63

Appendix 64

3

Page 8: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Chapter 1

Introduction

1.1 Background

The growing demand for renewable energy sources has led a research group inthe Division of Electricity at Uppsala University to look into the possibilitiesof energy conversion from marine currents. Marine current energy and waveenergy are two of the largest unexploited renewable energy sources. However,due to technological shortcomings utilization of these energy sources has sofor been commercially unsuccessful. Recent development in power electron-ics and permanent magnet synchronous generators has led the researchersat Uppsala University to believe that it would be possible to overcome theseshortcomings and develop a viable solution. [3]

For research purposes an experimental marine current energy conversion sys-tem is currently being developed and built at Uppsala University. The energyconversion system is to be launched in the river Dalälven at a test site lo-cated in Söderfors. At an early stage the system will not be connected tothe power grid. Instead, the produced electrical power will be wasted in aresistive DC-load. Electricity will be produced with a cable-wound perma-nent magnet synchronous generator designed to operate at a low rotationalspeed. The generator will be driven by a vertical axis turbine with fixedblade pitch and passive stall properties. Further, a variable-speed generatorcontrol regime will be used for purposes of maximizing energy capture. De-velopment of such a control system is the objective of the work presented inthis thesis.

1.2 Project specifications

The aim of this thesis work was to develop a generator control system thatcould be used in the experimental marine current energy conversion systembeing developed at Uppsala University. A set of requirements that the control

4

Page 9: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

system should meet were outlined. These are listed below.

• The control system should include functionality for controlling DC-voltage, rotational speed and the tip speed ratio of the turbine. Fur-ther, the possibility to use an MPPT-algorithm (Maximum PowerPoint Tracking) to control the turbine should be investigated.

• An IGBT transistor should be used to control the current fed to theresistive DC-load.

• An AVR microcontroller should be used for control of the IGBT andcomputational tasks in the control system.

• The control system should operate by feedback of DC-voltage, currentand the water speed measured with an ADCP-sensor.

• A user interface that allows the system operator to set the controlparameters should be developed.

5

Page 10: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Chapter 2

Theory

2.1 Power in a marine current

Marine current energy conversion regards the generation of electrical energyfrom the kinetic energy of water currents. The power P in a current of waterwith velocity v passing through a cross section area A can be expressed as:

P =1

2ρAv3 (2.1)

where ρ is the density of water. Marine current energy conversion is in manyaspects more similar to wind power than conventional hydro power. However,there are two significant differences between the energy characteristics ofmarine currents and wind that deserves mentioning. First, the density ofwater is roughly 800 times the density of air. Thus, the same relationshipapplies in terms of energy density. Second, in contrast marine currents ingeneral have a much lower speed, typically in the range of a few m/s [7].

2.2 Power captured by a turbine

The portion of the power in a marine current defined by equation 2.1 that canbe captured by a turbine is given by a factor defined as the turbine efficiencycoefficient Cp. Thus, the power captured by a turbine can be expressed as:

Pturbine =1

2Cp(λ)ρAturbinev

3 (2.2)

where Aturbine is the area swept by the turbine blades. The turbine efficiencycoefficient Cp varies with the tip speed ratio of the turbine λ. The tip speedratio is defined by the relation between the speed of the tip of the turbineblades and the speed of the water flowing through it. This can be expressedmathematically as:

λ =Ωr

v(2.3)

6

Page 11: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

where Ω is the rotational speed of the turbine, r its radius and v the speedof the water flowing through it. The tip speed ratio yielding the maximumefficiency coefficient Cmax

p and hence the maximal power capture is definedas the optimal tip speed ratio λopt. Figure 2.1 shows the theoretical Cp(λ)function of the turbine used in the marine current energy conversion systemdeveloped at Uppsala University. The shape of the Cp(λ) function of a tur-bine depends on the mechanical design of that specific turbine. Looking atFigure 2.1 it is obvious that the power efficiency coefficient Cp of this turbinedecreases rapidly as the tip speed ratio λ approaches zero. This propertyof the turbine is called passive stall and aims to protect the turbine frompotentially harmful mechanical stress caused by strong water currents. Incase of a very rapid increase in the water speed v the tip speed ratio λ willapproach zero and thus the power efficiency coefficient Cp will also approachzero, caused by the turbine stalling.

Tip speed ratio, λ

Pow

erco

effici

ent,

Cp

2 3 λopt 4 5

0.1

0.2

0.3

Cmaxp

Figure 2.1: Theoretical Cp(λ) function of the turbine used in the marinecurrent energy conversion system developed at Uppsala University

2.3 Power control using IGBT fed with PWM

PWM (Pulse Width Modulation) signals are commonly used in electronicsfor controlling analogue circuitry with a digital device. Specifically, PWMsignals could be fed to an IGBT serving as an efficient tool for power control.

7

Page 12: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

In essence the PWM signal is a digital signal consisting of rectangular pulses.The PWM is often defined by its duty cycle, a ratio corresponding to therelation between the pulse width and the time period of the signal, i.e.

duty cycle =tHIGH

tPERIOD

(2.4)

Figure 2.2 shows a PWM signal with a duty cycle of 75%.

time

5 V

0 V

TPERIOD

THIGH DC averageduty cycle =THIGH

TPERIOD

= 75%

Figure 2.2: PWM signal with duty cycle 75%

C

E

G

VCC

GND

RLOAD

IGBTDIGITAL

CONTROLLER

current average

voltage

PWM

Figure 2.3: IGBT controlled by PWM

Ideally the IGBT (Insulated Gate Bipolar Transisor) can be viewed as aswitch. As the name suggests it is bipolar, i.e. it only has two states: ’on’

8

Page 13: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

and ’off’. In the ’on’ state the IGBT is conducting and in the ’off’ state itis not. The IGBT is turned on by applying a threshold voltage on its gateand automatically turned off if the voltage is removed. This simple gate-drive control inherited from the MOSFET transistors makes the IGBT veryeasy to use while still keeping the high current capabilities of conventionalbipolar transistors [6]. This also allows the IGBT to be controlled by aPWM signal. The PWM signal will turn the IGBT on causing it to conductwhen the signal is HIGH and turn it off and thus stopping the current whenthe signal is LOW. By adjusting the duty cycle of the PWM defined byequation 2.4 it is possible to control the power extracted through a resistiveload according to the relation:

PLOAD =U2

RLOADD (2.5)

where U is the voltage drop over the load, RLOAD its resistance and D thePWM duty cycle. Figure 2.3 illustrates how a PWM signal can be used withan IGBT to control the power extracted through a resistive load.

In practise the IGBT is not a perfect switch. There will be a small forwardvoltage drop over the IGBT, when in conducting state, causing a power lossproportional to the current running through the component. Further, theswitching between ’on’ and ’off’ state is not completely instant but ratheroccurs over a time interval typically in the order of microseconds. This willlead to some additional power losses proportional to the switching time andswitching frequency [6].

2.4 Relation between voltage and rotational speedof a PM generator

The rectified output voltage of a PM generator UDC is directly proportionalto the rotational speed of its rotor, Ω. This relation is shown through thefollowing expressions:

The voltage induced in a phase Uph is given by Faraday’s law:

Uph(t) = −NdΦ(t)

dt(2.6)

where N is number stator windings [4]. The magnetic flux in a statortooth Φof a PM generator varies approximately as sine with the electrical frequencyω.

Φ(t) = Φ sin(ωt) (2.7)

9

Page 14: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

The electrical frequency ω is given by the rotational speed Ω and the numberof pole-pairs in the stator pp

ω = Ω · pp (2.8)

This yields:

Uph(t) = −Nd

dt(Φ sin(ωt)) = −N Φω cos(ωt) = −N ΦΩpp cos(Ω·pp·t) (2.9)

⇒ Uph = N ΦΩ · pp (2.10)

UDC ≈√

3Uph =√

3N ΦΩ · pp ∝ Ω (2.11)

2.5 Principles of load control

In section 2.2 it was stated that for a specific turbine there is an optimaltip speed ratio λopt yielding the maximum power capture. This implies thatit would be desirable to keep a turbine operating at the rotational speedcorresponding to its optimal tip speed ratio. The approach to achieve this isto control the power extracted from the generator load. Thus, this controlregime will throughout this thesis be referred to as load control. [1]

Neglecting generator losses the rotational speed of a turbine is determinedby the difference between the kinetic energy captured by the turbine andthe electrical energy extracted from the generator. This can be expressedmathematically as:

Pturbine − Pload =d

dt(1

2IΩ) (2.12)

where Ω is the rotational speed of the turbine and I its moment of inertia [4].

To illustrate the concept of load control it is convenient to express the in-coming and outgoing power as functions of the rotational speed. For a givenwater speed v the incoming power Pturbine given by equation 2.2 can be ex-pressed as a function of the power coefficient Cp. Further, expressing theoutgoing power Pload as power extracted from a resistive DC-load and usingthe relation between voltage UDC and rotational speed Ω given in equa-tion 2.11 yields the following relations describing incoming and outgoingpower as functions of the rotational speed.

Pturbine = k1Cp(Ω) (2.13)

Pload =U2

DC

Rload

= k2Ω2

Rload

(2.14)

10

Page 15: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

where k1 and k2 are some proportionality constants.

Rotational speed, Ω

Pow

er,P

Pload

Pturbine

ΩequilibriumΩmin

Figure 2.4: For a fixed water speed the power captured by a turbine Pturbine

and the power extracted from a load Pload can be expressed as functions ofthe rotational speed Ω

Recall that the rotational speed of the turbine obeys the law expressedin equation 2.12. Looking at the plot in figure 2.4 with this in mind revealsthe behaviour of the turbines rotational speed. If the system is put in a statewhere the rotational speed is at a point to the left of the first intersectionthe turbine will decelerate and stop. On the other hand if the system is putin a state where the rotational speed is at any point to the the right of thefirst intersection the rotational speed will approach an equilibrium state atthe second intersection.

To control the rotational speed of the turbine it is essential to be able tocontrol the outgoing power Pload. In section 2.3 it was expressed how thepower extracted from a resistive DC-load can be regulated using an IGBTtransistor controlled by PWM. Adopting this theory the outgoing powerPload expressed in equation 2.14 can be developed into:

Pload = k2Ω2

Rload

D (2.15)

11

Page 16: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

where D is the PWM duty cycle.

This allows for the outgoing power to be regulated by adjusting the PWMduty cycle from 0% to 100%. Figure 2.5 illustrates how load control can beused to control the rotational speed of a turbine by changing the PWM dutycycle and thus moving its equilibrium state.

Rotational speed, Ω

Pow

er,P

Pturbine

Pload at 30% duty cycle

50% duty cycle

80% duty cycle

Ω80% Ω50% Ω30%

Figure 2.5: Illustration of the load control concept

2.6 MPPT (Maximum Power Point Tracking)

MPPT (Maximum Power Point Tracking) is an algorithm that can be usedfor optimal control of a variable-speed energy conversion system. Its nameand main principles originate from an algorithm often used for control ofphotovoltaic systems [5]. The MPPT algorithm has the advantage that itdoes not require knowledge of the tip speed ratio λ of the turbine. Conse-quently measuring the speed of the water current v is not necessary. Thealgorithm operates by iteratively tracking its way to the optimal tip speedratio λopt yielding the maximum output electrical power Pout by feedback ofthe change of the power ∆Pout and rotational speed of the turbine ∆Ω. Thesign of ∂P

∂Ω determines if the reference rotational speed should be increased

12

Page 17: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

or decreased. If the reference rotational speed is adjusted proportionally tothis derivative, the reference will move towards an optimum where ∂Pout

∂Ω = 0.[1]

2.7 Implementation of discrete PID controller

The Proportional-Integral-Derivative (PID) controller is by far the most com-monly used technique for automatic control of a process. Its simplicity andgood performance has made it the number one choice for control of industrialprocesses. Implementation of the PID controller dates back to the eighteenthcentury. Over the years many different approaches have been used for real-ization of the PID controller, including mechanical, pneumatic and electronicdesigns. Today implementation is mostly done by use of microcomputers orsignal processors that operate in discrete time. [2]

The PID controller aims to minimize the error between the process out-put signal and the desired reference signal. It is designed to operate in afeedback loop, i.e. the controller inputs the output of the process and thereference, and outputs a signal for input to the process. See Figure 2.6

PID PROCESS

PROCESSOUTPUT SIGNAL

y(t)

REFERENCE SIGNALr(t) CONTROL SIGNAL

u(t)

Figure 2.6: PID controller feedback loop

Mathematically the output of the PID controller can be described as asum of a proportional, an integral and a derivative term:

u(t) = Kp

(

e(t) +1

Ti

∫ t

t0

e(τ) dτ + Td

(

−dy(t)

dt

))

(2.16)

where Kp is a proportionality constant and Ti and Td denotes time constantsof the integral and the derivative terms respectively. y(t) is the processoutput signal and r(t) is the reference signal. u(t) is the control signaloutput from the PID controller. e(t) is the process error defined as

e(t) = r(t) − y(t) (2.17)

When implementing the PID controller in a microprocessor the mathemat-ical description has to be approximated with a discrete expression. The

13

Page 18: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

derivative term can be converted to discrete form using the approximation

dy(t)

dt≈

1

Ts(y(n) − y(n − 1)), t = nTs (2.18)

where Ts denotes the sampling interval. This approximation is known asEuler backwards. The most straightforward approach to implementing theintegral term is by using the approximation

∫ t

0e(τ) dτ ≈ Ts

n∑

k=0

e(k), t = nTs. (2.19)

Thus, in discrete form the controller can be expressed as:

u(n) = Kpe(n) + Ki

n∑

k=0

e(k) + Kd(y(n) − y(n − 1)) (2.20)

where

Ki =KpTs

Ti

Kd =KpTd

Ts

In practise the control signal u(t) output from the PID controller is alwayslimited. This can cause undesirable behaviour of the controller when largechanges in the reference is made. A large change in the reference signal r(t)will likely cause the control signal u(t) to saturate and as consequence causethe integral term to sum up to a big number. This phenomena is calledintegral windup. To avoid this it is good practice to also limit the integralterm in some way, thus preventing it to grow infinitely when the controlsignal saturates. [2]

14

Page 19: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Chapter 3

System

3.1 System overview

The power captured by a turbine is dependent on the ratio between its rota-tional speed Ω, and the speed v of the fluid passing through it, as explainedby the relations given in sections 2.1-2.2. As suggested, every turbine has anoptimal operation point, defined as its optimal tip speed ratio λopt, yieldingthe maximum power capture [1]. Consequently, it is desirable to keep theturbine operating close to the rotational speed corresponding to its optimaltip speed ratio. Such a control system is the objective of the work presentedin this thesis. The system is designed to be used within the marine currentenergy conversion system described in section 1.1.

The rotational speed of a turbine can be controlled by adjusting the powerextracted from the generator. This control regime is described in section 2.5.The principles of the system is further developed in section 2.3 where it isexplained how the power extracted from a generator can be controlled bymeans of an IGBT transistor fed with a PWM signal.

The control system inputs are the voltage induced in the generator, thecurrent passed through the load and the speed of the water current. Theseinputs are read by a microcontroller (MCU) holding the control algorithmsand executing control of the system. Figure 3.1 shows an overview of thedeveloped system.

To allow the operator to interact with the system the MCU can be con-nected to a PC-application through a serial wire connection. If connectedto the PC-application the MCU will continuously send data containing thecurrent voltage, current, rotational speed, tip speed ratio, duty cycle, controlalgorithm and power. The PC-application has a graphical interface wherethe system data is plotted in real-time. The PC-application also has func-

15

Page 20: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

tionality to log this data and save it to a file.

The system is designed to be operated with a number of different controlparameters. This allows the operator to choose to run the system to keep adesired DC-voltage level, rotational speed or tip speed ratio. When the MCUis connected to the PC-application the control parameters can be changeddirectly from the PC-application while the system is running.

Control system

GENERATOR

AC

DCI + U

DC -

MCUIGBT

RLOAD

UDC

, I

PWM

ADCP

Water speed, v

Control

parameters

System

dataPC-application

Figure 3.1: Control system overview

3.2 Experimental setup

An experimental setup was made for testing the control system in a labora-tory environment. The control system was connected to a permanent magnetsynchronous generator built for indoor laboratory tests. This generator isdriven by a motor instead of an actual turbine. The motor is controlled byan ACS800 AC Variable Frequency Drive. The ACS800 has a built in func-tion called Direct Torque Control (DTC) that enables controlling the torqueput on the generator axis by the motor. Figures 3.2 - 3.4 shows photos ofgenerator, the ACS800 and the load used in the experimental setup.

16

Page 21: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Figure 3.2: Generator and motor used in the experimental setup

Figure 3.3: The ACS800 AC Variable Frequency Drive that controls themotor driving the generator

17

Page 22: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Figure 3.4: The resistive DC-load that absorbs the electrical power producedby the generator

3.2.1 Motor control system

To make the experimental setup realistic it was necessary to be able tocontrol the motor in a manner that simulates the behaviour of a real turbine.For this purpose a motor control system was developed and integrated withthe MCU and PC-application software of the control system. This motor

control system should only be regarded as a part of the experimental setupand not a part of the load control system referred to as the control system

which is the main objective of this thesis work. The functionality of themotor control system that was developed is illustrated in Figure 3.5 and isfurther described in the list below. Figure 3.6 shows how the control systemis connected together with the motor control system in the experimentalsetup.

• A sequence of water speed data can be saved in a text-file that will beread by the PC-application.

• Data that describes the power efficiency coefficient Cp(λ) function ofthe simulated turbine can be saved in another text-file that will be readby the PC-application.

• The turbine radius r and the density of water ρ are saved as constantsin both the PC-application and MCU software.

• The PC-application continuously sends the current water speed v to theMCU. The MCU measures the DC-voltage and calculates the currentrotational speed Ω of the generator.

18

Page 23: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

• Knowing the rotational speed Ω and water speeed v the MCU cancalculate the tip speed ratio λ according to equation 2.3. The MCUcontinuously sends the current tip speed ratio to the PC-applicationas a part of the system data.

• Knowing the tip speed ratio λ the PC-application can calculate a cor-responding turbine efficiency coefficient Cp from the data file.

• From the turbine radius r, the density of water ρ, water speed v andpower coefficient Cp the PC-application calculates the power capturedby the simulated turbine Pturbine according to equation 2.2. This tur-bine power Pt is continuously sent to the MCU.

• The MCU recalculates the turbine power Pt to a corresponding torqueM and outputs this torque to the ACS800 as a PWM signal.

• The ACS800 reads the torque from the MCU and adjusts the torqueput on the generator axis by the motor.

19

Page 24: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Motor control system

MOTOR

GENERATOR

PC-APPLICATION

WATER SPEED

DATA FILE

0.1

0.2

0.3

0.4

...

Cp0.00

0.01

0.03

0.05

...

t0.0

0.1

0.2

0.3

...

v1.12

1.06

1.01

0.89

...

Cp DATA FILE

MCU

ACS800

Torque, M

Ω

1

2

Water speed, v

Tip speed ratio,

Turbine Power, Pt

Figure 3.5: Motor control system overview

20

Page 25: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Control system in

GENERATOR

AC

DCI + U

DC-

MCUIGBT

RLOAD

UDC

, I

PWM

ACS800

+ Control parameters

+ Water speed, v

+ Turbine power, Pt

System

dataPC-application

MOTOR

Torque, M

experimental setup

Figure 3.6: Control system in experimental setup

3.3 Hardware

3.3.1 Hardware overview

At the core of the system lies the MCU, an AVR ATMEGA16 microprocessor.It runs a program that governs the control of the IGBT and as a consequencethe speed of the turbine, in accordance with the operating parameters sentfrom the PC-application. The MCU is surrounded by a number of hardwarecomponents that allow it to communicate with the rest of the system. Theseare listed below. Figure 3.7 shows an overview of the hardware used in thecontrol system.

• A voltage transducer and a current transducer. These componentsmeasure the voltage and current running through the load and outputsa proportional maximum 5V voltage for input to the MCU.

• An IGBT driver sits between the MCU and the IGBT. It inputs thePWM signal from the MCU and outputs an amplified PWM to theIGBT gate.

• MAX232 is a component custom built for RS-232 serial communica-tion. This component is used for the communication between MCU andPC-application. It converts data between the 5V digital logic used bythe MCU and 9V digital logic appropriate for RS-232 communication.

21

Page 26: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

• An AC/DC converter sits at the peripheral of the system. It collectsthe 3-phase AC-voltage from the generator and converts it to a DC-voltage.

DC

AC

MCUIGBT

RLOAD

IA

IGBTDRIVER

VOLTAGETRANSDUCER

MAX232

ADCP

+

-

UDC

3-PHASEAC-VOLTAGE

CURRENTTRANSDUCER

PWM

5 VMCULOGIC

9 VRS-232LOGIC

INPUT/OUTPUTDATA

vcurrent

System hardware

PC-application

C

E

Figure 3.7: System hardware

3.3.2 Microcontroller (MCU)

The MCU used in this system is an AVR ATMEGA16-16PU microcontrollerfrom ATMEL. On it runs a program that governs the control of the system.It inputs the generator DC-voltage and load current and outputs a PWMsignal to the IGBT driver. In the experimental setup the MCU also outputsa PWM signal to the ACS800 for purpose of controlling the motor. Further,the MCU communicates with the PC-application, receiving control parame-ters, water speed and turbine power and sending the system data.

The ATMEGA16 microcontroller is is a versatile component with many fea-tures, however the relevant characteristics and pin connections used in thissystem are explained in Figure 3.8 and Table 3.1. For more extensive infor-mation regarding the ATMEGA16 microcontroller consult the ATMEGA16data sheet1.

1www.atmel.com/atmel/acrobat/doc2466.pdf

22

Page 27: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

40

39

38

37

36

35

34

33

32

31

30

29

28

27

26

25

24

23

22

21

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

ATMEGA1616PU

TXD

RXD

GND

VCC

RESET

SCK

MISO

MOSI

PB3 (OC0)

PC0

PC1

PC2

PC3

PC4

PC5

PC6

PC7

AVCC

GND

AREF

ADC2

ADC1

ADC0

INPUTS

FROM CURRENTTRANSDUCER

FROM VOLTAGETRANSDUCER

PORT COUTPUT

TO LCDDISPLAY

ANALOG TO DIGITALCONVERTER

ADC POWER SUPPLY& REFERENCE

PWM OUTPUT 1

TO IGBTDRIVER

PROGRAMMINGINPUTS

FROMPROGRAMMER

VCC / GND+5 V

GND

USART RS232COMMUNICATION

TO MAX232

FROM MAX232

PWM OUTPUT 4

TO ACS800

(OC4) PD7

Figure 3.8: ATMEGA16 microcontroller

Table 3.1: MCU ATMEGA16 characteristics

Parameter Definition Value Remark

Power supply Vcc +5 V

Power consumption <20 mW

Clock frequency fCPU 0-16 MHz

Register size 8 bits

Flash program memory 16 kb

SRAM Data memory 512 bytes

8-channel 10-bit ADC

4 PWM channels

Programmable serial USART

3.3.3 IGBT driver

The IGBT driver used in the system is the IR2121 component from Inter-national Rectifier. It is located on the main circuit board seen in Figure 3.18.

The purpose of the IGBT driver is to feed the IGBT gate with with thevoltage and current required to switch the IGBT. It takes input from the

23

Page 28: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

MCU, a 5 V logic PWM signal intended for controlling the IGBT, and out-puts an amplified signal to the IGBT gate.

5

6

7

8

1

2

3

4

IR2121

VCC

OUT

CS

VS

IN

ERR

COM

100 Fm1 Fm

+

+15 V

GND 0 V

TO IGBTGATE

15 V / 1ALOGIC

PWM

FROMMCU

5 VLOGIC

PWM

RGATE

15 W

C1 C2

5 V

INPUT OUTPUT

15 V

Figure 3.9: IGBT driver circuit

In this system the IR2121 was designed to operate with an output of 15V / 1 A. The output current is decided by the resistor RGATE on the outputpin as seen in Figure 3.9. RGATE was chosen according to:

IO+ =Vout

RGATE=

15V

RGATE= 1A =⇒ Choose RGATE = 15Ω (3.1)

To avoid undesired voltage drops when current is drawn from the IR2121component two bootstrap capacitors C1 and C2 as seen in the circuit dia-gram shown in Figure 3.9.

The most important characteristics of the IR2121 relevant in the designof this system are listed in Tables 3.15 - 3.3. For more extensive informationabout the IR2121 component consult the IR2121 data sheet2.

Table 3.2: IR2121 driver characteristics

Parameter Definition Operating value Min Max

Supply voltage Vcc +15 V +12 V +18 V

Input logic voltage Vin 5 V 2.5 V Vcc

Output logic voltage Vout 15 V Vcc

Output source current IO+ 1 A

Output sink current IO− 2 A

Turn-On rise time tr 43 ns 60 ns

Turn-Off fall time tf 26 ns 35 ns

2www.irf.com/product-info/datasheets/data/ir2121.pdf

24

Page 29: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Table 3.3: IR2121 driver design parameters

Parameter Definition Value Remark

Gate resistance RGATE 15 Ω IO+ = Vout

RGATE≈ 1A

Bootstrap ceramic capacitor C1 1 uF Close, fast, small

Bootstrap electrolyte capacitor C2 100 uF Bigger, slower

3.3.4 IGBT

The IGBT used in this system is the SKM300GB128D component fromSemikron. It is mounted separately on a cooling element as seen in Fig-ure 3.11. The circuit is shown in Figure 3.10. The IGBT is used to controlthe current passed through the load according to the concept developed insections 2.5 and 2.3.

Table 3.4: SKM300GB128D characteristics

Parameter Definition Value Remark

Maximum Collector-to-Emitter voltage VCES 1200 V

Maximum Collector current IC @ 25 C 370 A

IC @ 80 C 265 A

Gate-to-Emitter threshold voltage VGE(th) 5.5 V

Collector cutoff current ICES 0.2 mA @VGE = 0V

Collector-Emitter On voltage VCE(on) 1 V

Collector-Emitter saturation voltage VCE(sat) 1.9 V

Turn-On delay time td(on) 170 ns VCC = 600V, IC = 200A

Rise time tr 55 ns

Turn-Off delay time td(off) 660 ns VGE = 15V

Fall time tf 60 ns

25

Page 30: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

C

E

G 2 F1000 VDC

m

TO LOAD

TO DC+ TERMINAL

TO RGATE

TO GND

Figure 3.10: IGBT circuit

Figure 3.11: Photo of the IGBT circuit. The IGBT is mounted on a blackcooling element. The cubical objects mounted on top of the IGBT are ca-pacitors.

3.3.5 MAX232

The MAX232 is a driver/receiver component custom made by MAXIM forRS-232 communication. It is used in this system for communication betweenMCU and PC-application and is located on the main circuit board seen inFigure 3.18. It basically works as a bridge between the 9V logic RS-232communication interface and the 5V logic used by the MCU. The relevantpin connections of the MAX232 is shown in Figure 3.12.

26

Page 31: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

16

15

14

13

12

11

10

9

1

2

3

4

5

6

7

8

1 Fm

1 Fm

1 Fm

VCC

GND

T1OUT

R1IN

R1OUT

T1IN

1 Fm

GND 0 V

TO MCU5 V LOGIC

TO DB9 FEMALE12 V LOGIC

MAX232

1 Fm

+5 V

Figure 3.12: MAX232 circuit

The MAX232 component requires a number of external capacitors asapparent in Figure 3.12 above. For more extensive information regardingthe MAX232 component consult the MAX232 datasheet3

3.3.6 Voltage transducer LV25-P

A voltage transducer LEM LV25-P is used to measure the rectified generatorvoltage UDC . The LV25-P component is located on the main circuit boardseen in Figure 3.18. Its input is the generator voltage UDC measured at theDC+ and DC- terminals of the AC/DC converter. It outputs a proportionalmaximum 5V voltage to the MCU.

LV25-P operates using the Hall effect. The measured voltage passes througha primary circuit IP and induces a voltage in a secondary circuit IS connectedto the MCU.

3datasheets.maxim-ic.com/en/ds/MAX220-MAX249.pdf

27

Page 32: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

LV25-PVCC-

VCC+

M

HT+

HT-

R1

TO DC- TERMINAL

TO DC+ TERMINAL

100 W

TO MCU ADCMAX 5 V

GND 0 V

-15 V +15 V

IP IS

33 k4

W

W

RM

MEASURETERMINALS

OUTPUTTERMINAL

Figure 3.13: Voltage transducer circuit

A resistor R1 and the voltage over the measure terminals Vmeasured de-cides the current IP running through the primary circuit. LV25-P is designedfor a primary current IP in the range 0..±14 mA. Hence, the resistor R1

should be chosen with the maximum measured voltage in mind to producea primary current less than 14 mA. In this system R1 is chosen to 33 kΩcorresponding to a maximum measured voltage of 462 V.

IP =Vmeasured

R1, Imax

P = 14mA

Choose R1 = 33kΩ =⇒ V maxmeasured = 33kΩ · 14mA = 462V

Further, the resistor RM should be chosen so that the voltage induced in thesecondary circuit does not exceed the maximum 5V permitted for input tothe MCU.

ImaxS = KN · Imax

P = 2.5 · 14mA = 35mA

Choose RM = 140Ω =⇒ V maxOUT = Imax

S · RM = 35mA · 140Ω = 4.9V

The most important characteristics of the LV25-P voltage transducer aresummarised in Table 3.5, for more extensive information consult the LEMLV25-P data sheet4.

4www.lem.com/docs/products/lv%2025-p%20sp2%20e.pdf

28

Page 33: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Table 3.5: LV25-P characteristics

Parameter Definition Value Remark

Supply voltage Vcc+ +15 V +12V ≤ Vcc+ ≤ +15V

Vcc− -15 V −12V ≤ Vcc− ≤ −15V

Primary nominal current IPN 10 mA

Primary current IP 0..±14 mA IP = Vmeasured

R1

Secondary nominal current IS 25 mA

Conversion factor KN 2.5 IS = KN ∗ IP

Table 3.6: LV25-P design parameters

Parameter Definition Value Remark

Primary circuit resistance R1 33 kΩ R1 =V max

measured

IPmax

Secondary circuit resistance RM 140 Ω RM ∗ ImaxS ≤ 5V

3.3.7 Current transducer HAIS 50-P

A current transducer LEM HAIS 50-p is used to measure the current IA run-ning through the load. The HAIS 50-p component is attached to a separatecircuit board connected to the main circuit board by a four wire cable. Thecircuit is seen in Figures 3.14 and 3.18.

HAIS 50-p measures a current by means of induction. The cable of thecurrent intended to measure runs through a hole in the middle of the com-ponent, e.g the HAIS 50-P is not directly connected to the measured circuitand does not affect this circuit significantly. The output connected to theMCU is a maximum 5V voltage proportional to the measured current.

29

Page 34: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

HAIS 50-P

VCC

GND

VOUT

VREF 47 nF

47 nF

CORE EARTH

IP +5 V

TO MCU ADCMAX 5 V

OUTPUTTERMINALS

MEASUREDCURRENT

4.7 nF

Figure 3.14: Current transducer circuit

Table 3.7: LEM HAIS 50-p characteristics

Parameter Definition Value Remark

Supply voltage Vcc +5 V

Primary nominal current IPN 50

Primary current IP -100..+200 A (measured)

Reference voltage Vref 2.5±0.025 V

Output voltage Vout Vref ± 0.625 ∗ IP /IPN V

3.3.8 AC/DC converter

An AC/DC converter was constructed to rectify the 3-phase AC voltageoutput from the generator. It consists of six diodes mouned on a coolingelement and a large electrolytic capacitance. The ciruit diagram is shown inFigure 3.15 and Figure 3.16 shows a photo of the AC/DC converter built forthis system.

30

Page 35: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

3-PHASE ACVOLTAGE

FROMGENERATOR

+

DC+

DC-

76 mF500 VDC

INPUT

RLOAD

IGBT

Figure 3.15: AC/DC converter circuit

Figure 3.16: Photo of AC/DC converter. The diodes are seen in the front ofthe picture mounted on the black cooling element. The cylindical objects inthe background are capacitors.

3.3.9 Power supply

A Traco Power TML15215C AC/DC power module is used for system powersupply. The TML15215C inputs 230V/50Hz from the regular power outletand outputs ±15V/±500mA for system power supply.

Further, a TS78M05 voltage regulator is used to provide a +5V voltagesource. This component is solded on the main circuit board and can be seenin the top of Figure 3.18. It inputs +15V from the TML15215C and outputs

31

Page 36: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

+5V/500mA. It also requires a 1µF capacitor as seen in Figure 3.17 below.

TRACO POWERTML15215C

FG

AC(N)

AC(L)

100-240 VAC47-63 Hz

0.375 A max

AC INPUTTERMINALS

GND

-15 V

+15 V

+15 V / 500 mA

DC OUTPUTTERMINALS

TS78M05

GND 0 V

-15 V / 500 mA

+5 V / 500 mA

1 Fm

Figure 3.17: Power supply

32

Page 37: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

3.3.10 Circuit diagram

16

15

14

13

12

11

10

9

1

2

3

4

5

6

7

8

40

39

38

37

36

35

34

33

32

31

30

29

28

27

26

25

24

23

22

21

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

ATMEGA1616PU

MAX232

5

6

7

8

1

2

3

4

IR2121LV25-P

VCC

OUT

CS

VS

RGATE

TXD

RXD

GND

VCC

RESET

SCK

MISO

MOSI

OC0

VCC-

VCC+

M

VCC

GND

T1OUT

R1IN

R1OUT

T1IN

PC0

PC1

PC2

PC3

PC4

PC5

PC6

PC7

AVCC

GND

AREF

ADC2

ADC1

ADC0

IN

ERR

COM

GND 0 V

VCC -15 V

TO LCDDISPLAY

TOPROGRAMMER

TO CURRENTTRANSDUCER

TO IGBTGATE

HT+

HT-

33 kW

TO DC- TERMINAL

TO DC+ TERMINAL

4 W

15 W

100 Fm1 Fm

1 Fm

1 Fm

1 Fm

1 Fm

1 Fm

2

3

5

TO IGBTCOLLECTOR

VCC +5 V

VCC +15 V

HAIS 50-P

VCC

GND

VOUT

VREF 47 nF

47 nF TO MAINCUIRCUITCONNECTOR

CORE EARTH

IA

C

E

G 2 Fm

TO LOAD

TO DC+ TERMINAL

TO RGATE

TO GND

1. Main circuit

3. Current transducer circuit2. IGBT curcuit

+

100 W

4.7 nF

TS78M05

GND 0 V

OUTGNDIN1 Fm

100 nF

10 uH

PB3

120 W

TO ACS800

Figure 3.18: Circuit diagram

33

Page 38: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Figure 3.19: Photo of main circuit

3.4 MCU software

The software for the MCU was implemented in C using WinAVR5. This is apackage of open source tools used for software development for AVR micro-controllers. It contains a C compiler avr-gcc, and a programmer avrdude, thatuploads the software from the PC to the MCU component. Programming ofmicrocontrollers also requires a hardware device called a programmer thatconnects the MCU with the PC from which the program is to be uploaded.This system was developed using ATMELS AVR STK500 programmer shownin Figure3.20. The source code of the MCU software can be found in theAppendix.

5http://winavr.sourceforge.net/

34

Page 39: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Figure 3.20: The ATMEL AVR STK500 programmer

3.4.1 MCU software overview

The source code for MCU software was implemented in a number of functionsdivided into different C libraries. Each library will be explained further inthe following sections. Figure 3.21 illustrates the main architecture of thesource code implementation.

35

Page 40: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

USART

+ USARTInit

+ USARTWriteChar

+ USARTWriteString

PWM

+ PWMInit

+ PWMSet DutyCycleIGBT

+ PWMSet DutyCycleACS800

Main program

+ readMeasurementData

+ readUSARTDataPackage

+ sendUSARTDataPackage

+ runControlAlg

+ printDataOnLCD

+ ISR(USART_RXC_vect)

+ main

Load control

+ loadControlInit

+ dutyCycleControl

+ tipSpeedControl

+ voltageControl

+ rotSpeedControl

ADC

+ ADCInit

+ ADCRead

PID

+ PIDInit

+ PIDController

+ PIDResetIntegrator

Motor control

+ MotorControlInit

+ SetMotorTorque

Figure 3.21: MCU software overview

3.4.2 PWM library

This library contains code for setting up and controlling the PWM signalsoutput from the MCU. It consists of three functions, a function PWMInit forinitialising the two PWM signals and two functions PWMSetIGBTDutyCycle

and PWMSetACS800DutyCycle that sets the duty cycle of PWM signals out-put to the IGBT and the ACS800.

There are four possible output pins for PWM signal generation on the AT-MEGA16, each one associated with a timer. The PWM output pins areshown in Figure 3.22 below, with the pins used in this system highlighted.This system uses Timer/Counter0 for the PWM signal output to the IGBTand Timer/Counter2 for the PWM signal output to the ACS800, i.e. for theload control and motor control respectively.

36

Page 41: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

40

39

38

37

36

35

34

33

32

31

30

29

28

27

26

25

24

23

22

21

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

ATMEGA1616PU

(OC1B) PD4

(OC0) PB3

PD7 (OC2)

Timer/Counter08-bit

Timer/Counter28-bit

Timer/Counter116-bit

(OC1A) PD5

PWM OUTPUT 1

PWM OUTPUT 2,3

PWM OUTPUT 4

Figure 3.22: ATMEGA16 PWM output pins

PWMInit

The PWMInit function initialises the PWM signals. The function is imple-mented by setting the bits of the Timer/Counter Control Registers (TCCR0)and (TCCR2). The following list explains how the the PWM signal outputto the IGBT is implemented.

• The timer mode of operation is set to Fast PWM by setting the Wave-form Generation Mode bits WGM00=1 and WGM01=1 in the TCCR0register.

• PWM frequency is set to 500 Hz by setting the Clock Select bitsCS02=0, CS01=1 and CS00=1 in the TCCR0 register, yielding theprescaler factor 64. Tables 3.8 and 3.9 describe the TCCR0 regis-ter Clock Select bits further. The PWM frequency can be explainedthrough the following relation:

fPWM =fCPU

256 ∗ prescaler

fCPU = 8MHz, prescaler = 64 −→ fPWM = 488.28Hz

• The PWM is set to non-inverting mode by setting the Compare OutputMode bits COM01=1 and COM00=0 in the TCCR0 register.

• The data direction of the PWM output pin PB3 (OC0) is set to outputby setting bit PB3=0 in the DDRB register.

37

Page 42: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Tables 3.8 - 3.11 give a more complete picture of how to set the bitsin the Timer/Counter0 Control Register (TCCR0) to obtain a PWM signalwith desired characteristics. For further information regarding PWM signalgeneration with ATMEGA16 consult the ATMEGA16 data sheet.

Table 3.8: Timer/Counter0 Control Register (TCCR0)

Bit 7 6 5 4 3 2 1 0

Name FOC0 WGM00 COM01 COM00 WGM01 CS02 CS01 CS00

Table 3.9: TCCR0 : Clock Select Bit Description

CS02 CS01 CS00 Prescalar Timer/Counter frequency

0 0 0 Timer/Counter stopped

0 0 1 1 CPU frequency/1

0 1 0 8 CPU frequency/8

0 1 1 64 CPU frequency/64

1 0 0 256 CPU frequency/256

1 0 1 1024 CPU frequency/1024

1 1 0 External clock on pin T0 (falling edge)

1 1 1 External clock on pin T0 (rising edge)

Table 3.10: TCCR0 : Waveform Generation Mode Bit Description

WGM01 WGM00 Mode of operation

0 0 Normal

0 1 Phase correct PWM

1 0 CTC

1 1 Fast PWM

38

Page 43: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Table 3.11: TCCR0 : Compare Output Mode for Fast PWM Bit Description

COM01 COM00 Description

0 0 Normal port operation, OC0 disconnected.

0 1 Reserved

1 0 Non-inverting mode

1 1 Inverting mode

PWMSetDutyCycle

The PWMSetIGBTDutyCycle and PWMSetACS800DutyCycle functions set theduty cycle of the PWM signals output from the MCU. It inputs a 0-100integer value corresponding to a 0-100% PWM duty cycle.

To understand how these functions are implemented one has to understandhow the Timer/Counters operate to generate a PWM signal output. Timer/-Counters can be used for several purposes and hence can be set up to run ina number of different manners depending on the desired outcome. All thisis explained in great detail in the ATMEGA16 data sheet6. However, forthe purpose of this system, given that the 8-bit Timer/Counter0 has beensetup to produce a 500 Hz, Fast PWM, non-inverting output signal by thePWMInit function explained in the previous section, the following applies:

• The counter associated with Timer/Counter0, stored in register TCNT0,will continously count from 0 to 255 with a time period of 2ms. SeeFigure 3.23.

• The Output Compare Register OCR0 associated with Timer/Counter0can be set to a value between 0 and 255.

• The PWM signal, output on the PB3 (OC0) pin, will follow the valueof the Timer Overflow Flag TOV0 associated with Timer/Counter0.When TOV0=1 a 5V output will be produced and when TOV0=0 a0V output will be produced.

• Each time the value of TCNT0 matches the value of OCR0 it willtrigger an interrupt: "output compare match" which clears (cleared to0) the flag TOV0.

• Further, each time the counter TCNT0 restarts (goes from 255 to 0)the flag TOV0 will be set (set to 1).

6www.atmel.com/atmel/acrobat/doc2466.pdf

39

Page 44: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

• Consequently a desired PWM duty cycle (0-100%) can be obtained bysetting the OCR0 register to a value (0-255) according to the simplerelation:

OCR0 = duty cycle ∗ 255/100

5 V

0 V

PWM

TCNT0

0

255

0 1 2 3 4 5 6time[ms]

1

0

TOV0

191

TCNT0=OCR0, TOV0 CLEARED TO 0

TCNT0 RESTARTS, TOV0 SET TO 1

OCR0

Figure 3.23: PWM duty cycle set to 75% by setting OCR0 register to 191

3.4.3 ADC library

This library contains functions for analog to digital conversion. ADC al-lows the digitally operating MCU to read external analog signals. In thissystem ADC is used to read the generator voltage and current measuredby the voltage transducer and current transducer components described insections 3.3.6 and 3.3.7.

The ATMEGA16 ADC module has eight input channels for ADC conversion,pins 33-40 labeled ADC0-ADC7. It also includes a separate supply voltage,pin 30 labeled AVCC, and a reference voltage, pin 32 labeled AREF. TheADC module pins are shown in Figure 3.24 below, with the pins used in thissystem highlighted.

40

Page 45: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

40

39

38

37

36

35

34

33

32

31

30

29

28

27

26

25

24

23

22

21

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

ATMEGA1616PU

PA0 (ADC0)PA1 (ADC1)PA2 (ADC2)

AREFGNDAVCC

PA3 (ADC3)PA4 (ADC4)PA5 (ADC5)PA6 (ADC6)PA7 (ADC7)

ADC INPUTCHANNELS

ADC REFERENCEVOLTAGE

ADC POWERSUPPLY

ADC PINCONNECTIONS

Figure 3.24: ATMEGA16 ADC input pins

The ADC module converts an analog input voltage to a 10-bit digitalvalue, and consequently the ADC channels has a maximum 10-bit resolu-tion. The input voltage will be approximated with a digital value between0000000000bin = 0dec and 1111111111bin = 1024dec.

The ADC module can handle input voltages in the range from 0V to 5V .However, to get maximum resolution in the conversion results, the ADC ref-erence voltage should be set to the expected maximal input voltage. To clar-ify, an input voltage of 0V will produce the digital value 0000000000bin = 0dec

and an input voltage that equals the reference voltage will produce the dig-ital value 1111111111bin = 1024dec.

There are two ways to set the reference voltage as explained below.

• Set ADC reference voltage by connecting the AREF pin (pin 32) onthe ATMEGA16 to a desired voltage level.

• Set ADC reference voltage to either match the voltage of the AVCC pin(pin 40) or to an internal voltage 2.56V by setting the Reference bitsREFS1 and REFS0 in the ADMUX register explained in Table 3.14below. (These options require an external capacitor connected at theAREF pin but can improve noise immunity.)

In this system the reference voltage was set to AVCC (5V) by setting theReference bits REFS1=0 and REFS0=1 bits in the ADMUX register. The

41

Page 46: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

voltage transducer and current transducer components producing the ADCinput voltages were set up to operate in the range 0V to 5V .

The ADC module operates using an ADC clock. The ADC clock frequencyshould be set in the range 50kHz to 200kHz to get the maximum 10-bitresolution. A normal ADC conversion takes approximately 13 ADC clockcycles. However, the first conversion after the ADC module is enabled re-quires 25 ADC clock cycles in order to initialize the analog circuitry.

The ADC input channel (0-7) to read from is selected by setting the AnalogChannel and Gain Selection Bits MUX4, MUX3, MUX2, MUX1 and MUX0as explained in Table 3.13.

There is much to say about the ATMEGA16 ADC module that lies out-side the scope of this system. To further investigate the many features ofthe ADC module consult the ATMEGA16 data sheet7.

Table 3.12: ADC Multiplexer Selection Register (ADMUX)

Bit 7 6 5 4 3 2 1 0

Name REFS1 REFS0 ADLAR MUX4 MUX3 MUX2 MUX1 MUX0

Table 3.13: ADMUX : Input channel selection Bit Description

MUX4 MUX3 MUX2 MUX1 MUX0 Input channel

0 0 0 0 0 pin 40 - PA0 (ADC0)

0 0 0 0 1 pin 39 - PA1 (ADC1)

0 0 0 1 0 pin 38 - PA2 (ADC2)

0 0 0 1 1 pin 37 - PA3 (ADC3)

0 0 1 0 0 pin 36 - PA4 (ADC4)

0 0 1 0 1 pin 35 - PA5 (ADC5)

0 0 1 1 0 pin 34 - PA6 (ADC6)

0 0 1 1 1 pin 33 - PA7 (ADC7)

7www.atmel.com/atmel/acrobat/doc2466.pdf

42

Page 47: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Table 3.14: ADMUX : Voltage Reference Bit Description

REFS1 REFS0 Reference voltage

0 0 AREF pin, internal reference 2.56 V turned off.

0 1 AVCC pin (requires external capacitor at AREF pin)

1 0 Reserved

1 1 Internal reference 2.56 V (requires external capacitor at AREF pin)

ADCInit

The ADCInit function enables the ADC and sets the ADC clock frequency.The function is implemented by setting the bits of the ADC Control andStatus Register (ADCSRA) and the ADC Multiplexer Selection Register(ADMUX). An explanation of the setting and functionality of each bit isgiven below.

• The ADC module is enabled by setting the ADC Enable bit ADEN=1in the ADCSRA register.

• The ADC clock freqency is set to 125kHz by setting the ADC Prescalerbits ADPS2=1, ADPS1=1 and ADPS0=0 in the ADCSRA register,yielding the prescaler factor 64. The ADC clock frequency is given bythe following relation:

fADC =fCPU

prescaler

fCPU = 8MHz, prescaler = 64 −→ fADC = 125kHz

ADCRead

The ADCRead function reads an analog voltage from one of the ADC inputchannels and converts it to a digital value. It inputs an integer 0-7 cor-responding to the ADC input channel to read from and outputs the ADCconversion result. The function implementation is explained below.

• To make sure that the input is valid, i.e. a 0-7 integer value corre-sponding to an ADC input channel. the input variable is multipliedwith a binary mask 00000111bin .

• The ADC input channel is set by setting the MUX4-MUX0 bits in theADMUX register as described in Table 3.13.

• A single conversion is started by setting the ADC Start Conversion bitADSC=1 in the ADCSRA register. This bit stays high as long as the

43

Page 48: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

conversion is in progress. When a conversion is complete the ADSCbit is automatically cleared and the ADC Interrupt Flag ADIF is set.

• A while loop prevents the program execution from continuing until theADIF flag is set.

• The ADIF Flag is cleared. Note: This is done by writing a logical oneto the ADIF register.

• The conversion result stored in the ADC register is returned. (TheADC register is actually a compound of two 8-bit registers ADCL andADCH to fit the 10-bit result). The result is given by:

ADC =Vin ∗ 1024

Vin

3.4.4 USART library

This library contains functions for the communication between MCU andPC-application. The communication interface used is commonly known asRS-232 and the ATMEGA16 module for handling this is called UniversalSynchronous and Asynchronous serial Receiver and Transmitter (USART).

The ATMEGA16 USART module has a receiver input, pin 14 labeled RXD,and a transmitter output, pin 15 labeled TXD. The USART module pins areshown in Figure 3.25 below.

40

39

38

37

36

35

34

33

32

31

30

29

28

27

26

25

24

23

22

21

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

ATMEGA1616PU

USART PINCONNECTIONS

(RXD) PD0(TXD) PD1

RECEIVE

TRANSMIT

Figure 3.25: ATMEGA16 USART pins

44

Page 49: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

USARTInit

The USARTInit function initializes the USART module. The function isimplemented by setting the bits of the USART Control and Status Registers(UCSRB and UCSRC) and the USART Baud Rate Registers (UBRRH andUBRRL). An explanation of the setting and functionality of each bit is givenbelow.

• The Baud rate is set to 19200bps given the MCU clock frequency8MHz by setting the UBBRL register to 25. (See Table 70 in AT-MEGA16 data sheet).

• The registers are set up for write access to the 16-bit register UCSRCby setting the USART Register Select bit URSEL=1 in the UCSRCregister. (See page 162 in ATMEGA16 data sheet).

• The mode of operation is set to asynchronous mode by clearing theUSART Mode Select bit UMSEL=0 in the UCSRC register.

• The parity mode is set to no parity by clearing the USART ParityMode bits UPM1=0 and UPM0=0 in the UCSRC register.

• The number of stop bits is set to 1 by setting the Stop Bit Selectbit USBS=0 in the UCSRC register. (Either one or two stop bits ispossible).

• The character size is set to 8 bits by setting the USART Character SiZebits UCSZ2=1, UCSZ2=1 and UCSZ2=0 in the UCSRB and UCSRCregisters. (See Table 66 in ATMEGA16 data sheet).

• The receiver is enabled by setting the RX ENable bit RXEN=1 in theUCSRB register.

• The transmitter is enabled by setting the TX ENable bit TXEN=1 inthe UCSRB register.

• The receive complete interrupt is enabled by setting the USART RXComplete Interrupt Enable bit RXCIE=1 in the UCSRB register. Thisinterrupt will trigger every time a new data character is received indi-cated by the Receive Complete Flag RXC in the UCSRA register beingset (set to 1).

• The Global Interrupt Flag SREG is set by the sei() command.

USARTWriteChar

The USARTWriteChar function transmits a single character by use of theUSART module. The function takes a char variable as input parameter.

45

Page 50: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

• Before sending the data it is necessary to make sure that the transimit-ter is ready. This is indicated by the UDRE bit in the UCSRA registerbeing set.

• The data is then sent by simply writing the input data to the UDRregister

USARTWriteString

The USARTWriteString function is simply an extension of the previous USARTWriteCharfunction that allows for transmission of a character string instead of a singlecharacter. It takes a string as input and transmits this string to the USARTbuffer by iteratively calling the USARTWriteChar function.

3.4.5 Load control library

This library contains functions for the load control of the turbine. The sys-tem can be set to keep a fixed DC voltage level by calling the voltageControlfunction, a fixed rotational speed by calling the rotSpeedControl functionor to keep a fixed tip speed ratio by calling the tipSpeedControl function.It is also possible to simply set a desired IGBT duty cycle by calling thedutyCycleControl function.

The load control library uses the functions of the PID library and PWMlibrary to calculate and set the PWM duty cycle output to the IGBT. Eachfunction inputs a data structure containing data measurements and a de-sired reference value. The functions are implemented to be called itera-tively updating the PWM duty cycle to keep the desired reference each timethey are called. The duty cycle is calculated by calling the PIDController

function with measurement and reference values as input parameters. ThePWMSetIGBTDutyCycle function is then called to set the PWM duty cycle.When the MCU program is started the loadControlInit function is called.It sets the system in a default mode of Duty cycle control with the dutycycle 10%.

3.4.6 PID library

A discrete PID controller was implemented based on the approximations de-scribed in section 2.7. The PID controller is implemented in three functions,a function PIDInit that initialises the controller, a function PIDController

that calculates the control signal and a function PIDResetIntegrator thatresets the integral sum.

The PIDController function inputs the desired reference and the output

46

Page 51: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

value of the process it should control, and returns a control signal. In this sys-tem the reference value is a desired voltage, rotational speed or tip speed ratiothat the control system should keep. The control signal is the PWM dutycycle output to the IGBT. The principal structure of the PIDController

function can be described as follows:

1. Calculate the process error e(t) = r(t) − y(t).

Error = reference - processValue

2. Calculate the proportional term Kpe(t).

PTerm=Kp*error

3. Add the current error to the sum of errors∑n

k=0 e(k).

Error += sumError

4. Calculate the integral term Ki

∑nk=0 e(k).

ITerm=Ki*sumError

5. Calculate the derivative term Kd(y(n) − y(n − 1)).

DTerm=Kd*(lastProcessValue - processValue)

6. Save current process value as the last process value.

lastProcessValue = processValue

7. Return the control signal u(n) = Kpe(n) + Ki

∑nk=0 e(k) + Kd(y(n) −

y(n − 1)).

return PTerm + ITerm + DTerm

From the source code of the PIDController function in the appendixit is evident that some further functionality was implemented. First, thecontrol signal has to be limited by the maximal size of the 16-bit integerused. Second, to prevent integral windup due to saturation of the controlsignal the error is limited.

47

Page 52: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

3.4.7 Motor control library

This library contains code for control of the motor. It consists of two func-tions, a function motorControlInit for initialising motor control and a func-tion setMotorTorque that sets the torque output on the generator by themotor.

The torque output from the motor is determined by the duty cycle outputfrom the MCU to the ACS800. The ACS800 will control the motor to outputa torque of 0-100% of the motor’s nominal torque corresponding to a 0-100%PWM duty cycle. The nominal torque of the motor used in the experimentalsetup is 12900 Nm. For example a 75% duty cycle of the PWM output tothe ACS800 will yield a torque on the generator axis of 12900*0.75=9675 Nm.

The torque is calculated from the simulated power captured by the turbineand the rotational speed of the generator. The relation is given by:

Torque =Pturbine

Rot.speed∗2π60

(3.2)

3.4.8 Main program

The main program refers to the source file that holds the main-function ofthe MCU software. The main-function runs an endless loop through a se-quence of function calls defining the principal structure of the program.

Main function loop:

1. readMeasurementData. This function reads the inputs from the ADCand calculates the voltage, current, rotational speed, tip speed ratioand power.

2. sendUSARTDataPackage. Sends the system data to the PC-application.

3. setMotorTorque. Sets the torque output from the motor on the gen-erator.

4. runControlAlg. Runs the control algorithm and thus updates the dutycycle of the IGBT.

5. printDataOnLCD. Prints system data on the LCD display

The main program also holds an ISR (interrupt service routine) that willbe called every time that a data byte is received from the PC-application.The ISR stores the recieved data in a buffer as a sequence of ASCII charac-ters. When a complete package is received the ISR calls the readUSARTDataPackage

48

Page 53: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

function and empties the buffer.

The readUSARTDataPackage function parses the data in the buffer and inter-prets it. The data packages received from the PC-application are formattedas a character followed by a numerical value. The character tells the receiv-ing interpreter what data the package contains. For example the package"T2.65" tells the interpreter to change the current control algorithm to Tip

speed control and set the reference tip speed ratio to 2.65. The package"v1.05" means that the current water speed should be set to 1.05m/s. A listof the different data packages that can be received from the PC-applicationis given below.

Table 3.15: Received USART data package signatures

Variable Character code

Turbine power P

Water speed v

Start motor m

Duty cycle control D

Voltage control V

Rotational speed control R

Tip speed control T

49

Page 54: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

3.5 PC-application software

The PC-application software is implemented in Java as a Windows 32-bitJava-application. It is developed using the Java IDE from Eclipse8. Theclasses for communication between the PC-application and the MCU areimplemented using an open source library for serial communication9.

The PC-application allows the system operator to monitor the state of thesystem and set the system control parameters. It communicates with theMCU through the serial communication interface RS-232. When connected,the PC-application will continuously receive system data from the MCU anddisplay this data graphically in real-time. Data is plotted in eight graphsshowing: water speed, load voltage, load current, IGBT duty cycle, rota-tional speed, tip speed ratio, load power and turbine power. Figures 3.26- 3.28 shows screenshots of the PC-application. Through the graphical userinterface the system operator can choose to set which control algorithm torun on the MCU. The PC-application also contains functionality for loggingthe data received from the MCU. The log will be saved in a format that caneasily be exported to MATLAB.

In the experimental setup some further functionality for controlling the mo-tor was built into the PC-application software. This functionality was de-scribed in detail in section 3.2.1.

8www.eclipse.org9http://users.frii.com/jarvi/rxtx/download.html

50

Page 55: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Figure 3.26: Screenshot from the PC-application showing an overview of theGUI

51

Page 56: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Figure 3.27: Screenshot from the PC-application showing the plots on theleft side of the GUI

52

Page 57: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Figure 3.28: Screenshot from the PC-application showing the plots on theright side of the GUI

53

Page 58: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

3.5.1 Software architecture

Since it is not the aim of this thesis to examine Java GUI programming thesoftware for the PC-application will not be explained in detail. This wouldmostly be an examination of the Java Swing library for GUI programming.However, the basic architecture of the program is presented below.

The software is implemented in seven Java classes. Two classes RS232Connectionand CommPortReceiver handle communication between PC-application andMCU. Further, there are two classes GraphPanel and TipSpeedGraph re-sponsible for plotting the data. A the class DataBuffer holds the dataplotted in the graphs. A class ProgramPanel is responsible for most of thefunctionality in the program. It holds, among others, an object of the classRS232Connection and six objects of the type GraphPanel. Finally, a classControlProgram holds the ProgramPanel and executes the main-method.

54

Page 59: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Figure 3.29: PC-application class diagram

55

Page 60: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Chapter 4

Results

The result of this thesis work is presented through data produced from threedifferent test runs of the developed system. Each test run aims to show theperformance of the system running with a specific control algorithm. In thefirst test run the system was run to keep a fixed DC voltage level, in thesecond test run the system was run to keep a fixed turbine rotational speedand in the third test run the system was run to keep a fixed tip speed ratio.

The water speed data used as system input are based on measurements madewith an ADCP at the site in Söderfors where the marine current project atUppsala University plans to launch their marine current power plant.

The results of each test run are presented in four plots showing an extractof data that were sampled with the systems logging function during a 20second time period. The first two plots show the system inputs, the simu-lated water speed and the mechanical power put on the generator axis bythe motor. This mechanical input power should be regarded as the powercaptured by the turbine as explained in section 3.4. The third plot showsthe output electrical power absorbed in the resistive DC-load. Finally thefourth plot shows measurements of the parameter that the system aims tocontrol in relation to the selected reference.

4.1 Voltage control

In the first test run the system was operating with the control algorithm thataims to keep a fixed DC voltage level. The plot sequence begins when thesystem is running with a reference voltage of 150 V and after approximately10 seconds the reference was changed to 220 V. The plot at the bottomshows that the measured voltage follows selected reference and when thereference is changed the voltage overshoots slightly before it settles in to thenew reference. See Figure 4.1.

56

Page 61: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

0 2 4 6 8 10 12 14 16 18 200.9

1

1.1

1.2Simulated water speed

[m/s

]

0 2 4 6 8 10 12 14 16 18 202000

3000

4000

5000

6000Mechanical power put on generator axis

[W]

0 2 4 6 8 10 12 14 16 18 200

1000

2000

3000

4000Absorbed electrical power

[W]

0 2 4 6 8 10 12 14 16 18 20140

160

180

200

220

240

260Voltage (between DC terminals)

[V]

[s]

Measured voltageReference voltage

Figure 4.1: Data sampled from the system while operating to control theDC voltage level

4.2 Rotational speed control

In the second test run the system was operating with the control algorithmthat aims to keep a fixed rotational speed of the turbine. In section 2.4it was shown that the DC-voltage of a PM generator is proportional toits rotational speed. Thus, controlling the rotational speed is essentiallythe same as controlling the generator DC-voltage. The rotational speed

57

Page 62: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

control simply allows the system operator to choose a reference measured inrpm instead of a DC-voltage. The plot sequence begins when the system isrunning with a reference rotational speed of 8 rpm and after approximately 10seconds the reference was changed to 12 rpm. The plot at the bottom showsthat the measured rotational speed follows selected reference and when thereference is changed the rotational speed overshoots slightly before it settlesin to the new reference. See Figure 4.2.

0 2 4 6 8 10 12 14 16 18 200.8

0.9

1

1.1

1.2Simulated water speed

[m/s

]

0 2 4 6 8 10 12 14 16 18 202000

4000

6000

8000Mechanical power put on generator axis

[W]

0 2 4 6 8 10 12 14 16 18 200

1000

2000

3000

4000Absorbed electrical power

[W]

0 2 4 6 8 10 12 14 16 18 206

8

10

12

14Turbine rotational speed

[rpm

]

[s]

Measured rotation speedReference rotation speed

Figure 4.2: Data sampled from the system while operating to control therotational speed of the turbine

58

Page 63: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

4.3 Tip speed ratio control

In the third test run the system was operating with the control algorithmthat aims to keep a fixed tip speed ratio. The plot sequence begins whenthe system is running with a reference tip speed ratio of 2.6 and after ap-proximately 10 seconds the reference was changed to 3.6. The plot at thebottom shows that the measured tip speed ratio follows selected referenceand when the reference is changed the tip speed ratio overshoots slightlybefore it settles in to the new reference. See Figure 4.3.

59

Page 64: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

0 2 4 6 8 10 12 14 16 18 200.8

0.9

1

1.1

1.2Simulated water speed

[m/s

]

0 2 4 6 8 10 12 14 16 18 202000

4000

6000

8000Mechanical power put on generator axis

[W]

0 2 4 6 8 10 12 14 16 18 200

1000

2000

3000

4000Absorbed electrical power

[W]

0 2 4 6 8 10 12 14 16 18 202.5

3

3.5

4

[s]

Tip speed ratio

Measured TSR

Reference TSR

Figure 4.3: Data sampled from the system while operating to control the tipspeed ratio

4.4 MPPT

Some crude attempts were made to implement an alternative control algo-rithm based on the theory of the MPPT algorithm described in section 2.5.However, these attempts were unsuccessful. In spite of the apparently simpletheory, implementation of the MPPT presented some difficulties in practise.When test runs were made using the MPPT algorithm to control the gen-

60

Page 65: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

erator the algorithm could not successfully find the maximum power point.Due to the limited time frame of this thesis work, the MPPT algorithm hadto be left out in favour of getting the rest of the system working.

61

Page 66: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Chapter 5

Discussion and conclusions

Overall the design and implementation of the control system has been suc-cessful. With exception of the MPPT the system meets the requirementsthat were outlined in the project specification and test runs indicate thatthe performance of the system is acceptable.

Unsuccessful attempts were made to implement an MPPT-algorithm. Inspite of the apparently simple theory, implementation of the MPPT pre-sented some difficulties in practise. However, I still believe that the MPPTis an interesting control regime in marine current energy conversion systems.The relatively slow changes in speed in marine currents in comparison towind implies that MPPT would be a feasible strategy. The MPPT has theadvantage that it does not require knowledge of the Cp(λ) function of theturbine or measuring of the water speed. Further, the MPPT would alsoinclude the efficiency of the generator when optimising the rotational speedof the turbine. This is not considered by the current control system.

The parameters of the PID regulator has a significant impact on the per-formance of the control system. For future development of the system itwould be interesting to implement functionality for continuously updatingthe PID-parameters to match marine current conditions. In the current sys-tem these parameters were determined manually and set as constants in theMCU software. The parameters were set with the aim to obtain a decentperformance in the marine current conditions expected at the test site inSöderfors. However, this is not an optimal solution.

The computational speed of the microcontroller will affect the speed of thePID-regulator and as a consequence the frequency with which the IGBTduty cycle is updated. In general the speed of the control system relates tothe system’s ability to cope with rapid changes in water speed while keepingdown overshoots and oscillatory behaviour in the output voltage.

62

Page 67: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

In the current system setup the motor control system has been runningon the same microcontroller as the passive stall control system. This is nota preferable solution even for testing the system. The motor control systemdemands a large portion of the computational power of the microcontrollerand thus slows down the passive stall control system significantly. Hence, abetter solution would be to keep these systems running on separate micro-controllers.

Further improvements could be made by implementing the PWM signaloutput to the IGBT using the 16-bit Timer/Counter1 instead of the cur-rent 8-bit Timer/Counter0. This would increase the resolution with whichthe duty cycle can be set greatly and thus improve the performance of thecontrol system.

In real-time systems, such as this, timing and synchronisation is of greatimportance. When implementing a real-time system one often uses timersto make sure that each function call occurs at the exact right time (to thelevel of clock cycles). Looking at the source code of the main-function of theMCU software in the Appendix reveals that this program is not perfectlytimed. For instance, the time that it takes for the MCU to perform oneloop though the main-function will vary slighly depending on the outcomeof some if-statements. This will probably not affect the performance of thesystem significantly. However, a more professional approach would be to usetimers to control the function calls in the main-function.

63

Page 68: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

References

[1] Optimal Control of Wind Energy Systems. Springer-Verlag London Lim-ited, 2008.

[2] Torkel Glad and Lennart Ljung. Reglerteknik - Grundläggande Teori.Studentlitteratur, 1981.

[3] K. Nilsson. Low speed generators for marine current power conversion.Lic.Thesis, September 2005.

[4] Carl Nordling and Jonny Österman. Physics Handbook for Science andEngineering. Studentlitteratur, 2004.

[5] I. Schiemenz and M. Stiebler. Control of a permanent magnet syn-chronous generator used in a variable speed wind energy system. InElectric Machines and Drives Conference, 2001. IEMDC 2001. IEEEInternational.

[6] T. L. Skvarenina. The power electronics handbook. CRC Press, 2002.

[7] Karin Thomas. Low speed energy conversion from marine currents. Com-prehensive Summaries of Dissertions from the Faculty of Science andTechnology 287, ISBN 978-91-554-7063-0, 2008.

64

Page 69: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

Appendix

The following section shows the source code of the MCU software.

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ main . c ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

#include <avr / i o . h>#include <avr / de lay . h>#include <f loat . h>#include <avr / in t e r rup t . h>#include <std i o . h>#include <s t d l i b . h>#include <s t r i n g . h>#include "ADC. h"#include "USART. h"#include " l oad con t r o l . h"#include " motorcontro l . h"#include " l cd . h"

/∗ === GLOBALA VARIABLER ================================= ∗/

char r ece iv edDataBu f f e r [ 2 0 ] ;SYS_DATA sys_data ;MOTOR_DATA motor_data ;

/∗ === FUNKTIONER ======================================== ∗/

void readMeasurementData(SYS_DATA ∗data , MOTOR_DATA ∗motor_data)

int16_t adc0 = ADCRead ( 0 ) ;int16_t adc1 = ADCRead ( 1 ) ;int16_t adc2 = ADCRead ( 2 ) ;data−>vol tage=adc0 ∗0 . 360 ; // [V]data−>curren t=(adc2−adc1 ) ∗ 0 . 0 9 7 ; // [A]data−>loadpower=data−>vol tage ∗data−>curren t ; // [W]data−>rotSpeed=data−>vol tage ∗0 . 051 ; // [ rpm ]i f ( motor_data−>waterVeloc i ty >0)

data−>tipSpeed=(data−>rotSpeed/60∗2∗3.14159∗motor_data−>turb ineRadius )/motor_data−>waterVe loc i ty ;

else

data−>tipSpeed=−1;

65

Page 70: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

void readUSARTDataPackage (SYS_DATA ∗data , MOTOR_DATA ∗motor_data)

i f ( r ece iv edDataBu f f e r [0]== ’P ’ ) motor_data−>turbinePower=s t r t od ( r ece iv edDataBu f f e r+1,NULL) ;

else i f ( r ece iv edDataBu f f e r [0]== ’v ’ ) motor_data−>waterVe loc i ty=s t r t od ( r ece iv edDataBu f f e r+1,NULL) ;

else i f ( r ece iv edDataBu f f e r [0]== ’m’ ) motor_data−>startMotor=ato i ( r ece iv edDataBu f f e r +1);

else data−>cont ro lA lg=rece iv edDataBu f f e r [ 0 ] ;data−>r e f e r e n c e=s t r t od ( r ece iv edDataBu f f e r+1,NULL) ;

void sendUSARTDataPackage(SYS_DATA ∗data , MOTOR_DATA ∗motor_data)

char package [ 1 0 0 ] ;s p r i n t f ( package ,

"%c%.2 f v%.2 f c%.2 f d%.2 f t%.2 f r%.2 f p%.2 f m%d\n" ,data−>contro lAlg ,data−>re f e r en c e ,data−>voltage ,data−>current ,data−>dutyCycle ,data−>tipSpeed ,data−>rotSpeed ,data−>loadpower ,motor_data−>startMotor ) ;

USARTWriteString ( package ) ;

void runControlAlg (SYS_DATA ∗data )

i f ( data−>cont ro lA lg == ’D’ ) dutyCycleControl ( data ) ;

else i f ( data−>cont ro lA lg == ’V ’ ) vo l tageCont ro l ( data ) ;

else i f ( data−>cont ro lA lg == ’R ’ ) rotSpeedContro l ( data ) ;

else i f ( data−>cont ro lA lg == ’T ’ ) t ipSpeedContro l ( data ) ;

void printDataOnLCD (SYS_DATA ∗data , MOTOR_DATA ∗motor_data)

char vo l t ag eS t r i n g [ 1 5 ] ;char cu r r en tS t r i n g [ 1 5 ] ;char t ipSpeedSt r ing [ 1 5 ] ;char dutyStr ing [ 1 5 ] ;s p r i n t f ( vo l tageS t r ing , "U=%.2fV" , data−>vol tage ) ;s p r i n t f ( cu r r en tS t r ing , " I=%.2fA" , data−>curren t ) ;

66

Page 71: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

s p r i n t f ( t ipSpeedStr ing , " t=%.2 f " , data−>tipSpeed ) ;s p r i n t f ( dutyString , "D=%.0 f " , data−>dutyCycle ) ;LCDClear ( ) ;LCDWriteStringXY(0 ,0 , v o l t ag eS t r i n g ) ;LCDWriteStringXY(10 ,0 , cu r r en tS t r i n g ) ;LCDWriteStringXY(0 ,1 , t ipSpeedSt r ing ) ;LCDWriteStringXY(10 ,1 , dutyStr ing ) ;

/∗ === INTERRUPT SERVICE ROUTINES ========================== ∗/

ISR(USART_RXC_vect)

char temp ;int i =0;

temp=UDR; // Read re c e i v ed data from UDR r e g i s t e r .

while ( r ece iv edDataBu f f e r [ i ] != ’ \0 ’ ) // Find end o f b u f f e ri++;

rece iv edDataBu f f e r [ i ]=temp ; // Save data at end o f b u f f e rr ece iv edDataBu f f e r [ i +1]= ’ \0 ’ ; // Terminate b u f f e r

i f ( temp==’ \n ’ ) // I f end o f packager ece iv edDataBu f f e r [ i ]= ’ \0 ’ ; // Remove ’\n ’ char

readUSARTDataPackage(&sys_data , &motor_data ) ;r e ce iv edDataBu f f e r [0 ]= ’ \0 ’ ; // Empty data b u f f e r

/∗ === MAIN ================================================ ∗/

int main (void )

PWMInit ( ) ;USARTInit ( ) ;ADCInit ( ) ;l o adCon t r o l I n i t (&sys_data ) ;motorContro l In i t (&motor_data ) ;InitLCD(LS_BLINK) ;

while (1 ) readMeasurementData(&sys_data , &motor_data ) ;sendUSARTDataPackage(&sys_data , &motor_data ) ;setMotorTorque(&sys_data , &motor_data ) ;runControlAlg(&sys_data ) ;printDataOnLCD(&sys_data , &motor_data ) ;_delay_ms ( 1 0 ) ;

return 0 ;

67

Page 72: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ADC. c ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

#include "ADC. h"#include <avr / i o . h>#include <avr / de lay . h>

void ADCInit ( )

/∗ ADC Mu l t i p l e x e r Se l e c t i on Reg i s te r (ADMUX)∗ ===========================================∗ See d e t a i l s in p .217 o f ATMEGA16 data sh e e t∗ −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−

∗ Bit 7 , REFS1 : Vol tage Reference Se l e c t i on∗ Bit 6 , REFS0 : Vol tage Reference Se l e c t i on∗ Bit 5 , ADLAR : Le f t Adjust Resu l t∗ Bit 4 , MUX3 : Analog channel and Gain s e l e c t∗ Bit 3 , MUX3 : Analog channel and Gain s e l e c t∗ Bit 2 , MUX2 : Analog channel and Gain s e l e c t∗ Bit 1 , MUX1 : Analog channel and Gain s e l e c t∗ Bit 0 , MUX0 : Analog channel and Gain s e l e c t∗/ADMUX=0b01000000 ; // Set r e f e r ence v o l t a g e to AVCC

/∗ ADC Sta tus and Contro l Reg i s t e r A (ADCSRA)∗ ===========================================

∗ See d e t a i l s in p .219 o f ATMEGA16 data sh e e t∗ −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−

∗ Bit 7 , ADEN : ADC Enable∗ Bit 6 , ADSC : ADC Sta r t Conversion∗ Bit 5 , ADATE : ADC Auto Trigger Enable∗ Bit 4 , ADIF : ADC In t e r rup t Flag∗ Bit 3 , ADIE : ADC In t e r rup t Enable∗ Bit 2 , ADPS2 : ADC Presca l e r s e l e c t∗ Bit 1 , ADPS1 : ADC Presca l e r s e l e c t∗ Bit 0 , ADPS0 : ADC Presca l e r s e l e c t∗/ADCSRA=0b10000110 ; // Enable ADC and s e t p r e s ca l e r 64

// f_CPU=8MHz => f_adc=125 kHZ

uint16_t ADCRead( uint8_t inputChannel )

/∗ ADC Mu l t i p l e x e r Se l e c t i on Reg i s te r (ADMUX)∗ ===========================================∗ See d e t a i l s in p .217 o f ATMEGA16 data sh e e t∗ −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−

∗ Bit 7 , REFS1 : Vol tage Reference Se l e c t i on∗ Bit 6 , REFS0 : Vol tage Reference Se l e c t i on∗ Bit 5 , ADLAR : Le f t Adjust Resu l t∗ Bit 4 , MUX3 : Analog channel and Gain s e l e c t∗ Bit 3 , MUX3 : Analog channel and Gain s e l e c t∗ Bit 2 , MUX2 : Analog channel and Gain s e l e c t∗ Bit 1 , MUX1 : Analog channel and Gain s e l e c t

68

Page 73: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

∗ Bit 0 , MUX0 : Analog channel and Gain s e l e c t

∗ ADC Sta tus and Contro l Reg i s t e r A (ADCSRA)∗ ==========================================∗ See d e t a i l s in p .219 o f ATMEGA16 data sh e e t∗ −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−

∗ Bit 7 , ADEN : ADC Enable∗ Bit 6 , ADSC : ADC Sta r t Conversion∗ Bit 5 , ADATE : ADC Auto Trigger Enable∗ Bit 4 , ADIF : ADC In t e r rup t Flag∗ Bit 3 , ADIE : ADC In t e r r p t Enable∗ Bit 2 , ADPS2 : ADC Presca l e r s e l e c t∗ Bit 1 , ADPS1 : ADC Presca l e r s e l e c t∗ Bit 0 , ADPS0 : ADC Presca l e r s e l e c t∗/

// Make sure inputChannel i s 0−7inputChannel&=0b00000111 ;

// Clear inpu t channelADMUX=0b01000000 ;

// Set inpu t channelADMUX|= inputChannel ;

// S ta r t convers ionADCSRA|=(1<<ADSC) ;

// Wait f o r convers ion to completewhile ( ! (ADCSRA & (1<<ADIF) ) ) ;

//Clear ADIF by wr i t i n g a l o g i c a l one to i tADCSRA|=(1<<ADIF) ;

//Return convers ion r e s u l treturn (ADC) ;

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ADC. h ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

#ifndef ADC_H_#define ADC_H_

#include <avr / i o . h>

void ADCInit ( ) ;uint16_t ADCRead( uint8_t ch ) ;

#endif /∗ ADC_H_ ∗/

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ PWM. c ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

#include <avr / i o . h>

69

Page 74: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

#include <u t i l / de lay . h>#include " l cd . h"

void PWMInit ( )

/∗ Timer/Counter0 Contro l Reg i s t e r (TCCR0)∗ ==========================================∗ See d e t a i l s in p .83 o f ATMEGA16 data sh e e t∗ −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−

∗ Bit 7 , FOC0 : Force Output Compare∗ Bit 6 , WGM00 : Waveform Generation Mode∗ Bit 5 , COM01 : Compare Output Mode∗ Bit 4 , COM00 : Compare Output Mode∗ Bit 3 , WGM01 : Waveform Generation Mode∗ Bit 2 , CS02 : Clock S e l e c t∗ Bit 1 , CS01 : Clock S e l e c t∗ Bit 0 , CS00 : Clock S e l e c t∗/// Set Timer/Counters to genera te Fast PWM with p r e s ca l e r 64TCCR0|=0b01101011 ;TCCR2|=0b01101011 ; //

DDRB|=0b00001000 ; // Set PB3 (OC0) as output .DDRD|=0b10000000 ; // Set PD7 (OC2) as output .

void PWMSetIGBTDutyCycle( int dutyCycle )

OCR0=dutyCycle ∗255/100;void PWMSetACS800DutyCycle ( int dutyCycle )

OCR2=dutyCycle ∗255/100;

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ PWM. h ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/#ifndef PWM_H_#define PWM_H_

void PWMInit ( ) ;void PWMSetIGBTDutyCycle( int dutyCycle ) ;void PWMSetACS800DutyCycle ( int dutyCycle ) ;

#endif /∗ PWM_H_ ∗/

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ USART. c ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/#include "USART. h"#include <avr / i o . h>#include <avr / s l e ep . h>#include <avr / in t e r rup t . h>

void USARTInit ( )

// Set Baud ra te 19200 bps @ f_CPU=8 MHz

70

Page 75: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

// ( See ATMEGA16 data sh e e t Table 70)UBRRL = 25 ;

/∗ USART Contro l And Sta tus Reg i s te r C (UCSRC)∗ ===========================================∗ See d e t a i l s in p .166 o f ATMEGA16 data sh e e t∗ −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−

∗ Bit 7 , URSEL : USART Reg i s te r S e l e c t b i t∗ Bit 6 , UMSEL : USART Mode S e l e c t∗ Bit 5 , UPM1 : Par i ty Mode∗ Bit 4 , UPM0 : Par i ty Mode∗ Bit 3 , USBS : Stop Bi t S e l e c t∗ Bit 2 , UCSZ1 : USART Character s i z e∗ Bit 1 , UCSZ0 : USART Character s i z e∗ Bit 0 , UCPOL : Clock Po l a r i t y∗/UCSRC=0b10000110 ; // Set Frame Format

// − Asynchronous mode// − No Par i ty

// − 1 s top b i t// − 8− b i t charac ter s i z e

/∗ USART Contro l And Sta tus Reg i s te r B (UCSRB)∗ ===============================================∗ See d e t a i l s in p .165 o f ATMEGA16 data sh e e t∗ −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−

∗ Bit 7 , RXCIE : RX Complete I n t e r rup t Enable∗ Bit 6 , TXCIE : TX Complete I n t e r rup t Enable∗ Bit 5 , UDRIE : Data Reg i s te r Empty I n t e r rup t Enable∗ Bit 4 , RXEN : RX ENable∗ Bit 3 , TXEN : TX ENable∗ Bit 2 , UCSZ2 : Character S i ze∗ Bit 1 , RXB8 : Receive Data Bi t 8∗ Bit 0 , TXB8 : Transmit Data Bi t 8∗/UCSRB=(1<<RXEN)|(1<<TXEN)|(1<<RXCIE) ;

s e i ( ) ; //Enable g l o b a l i n t e r r u p t s

void USARTWriteChar( char data )

/∗ Wait u n t i l the t r an sm i t t e r i s ready . This i s∗ i n d i ca t ed by the UDRE−b i t in the UCSRA r e g i s t e r∗ be ing s e t .∗/while ( ! (UCSRA & (1<<UDRE) ) )

/∗ Now wri te the data to USART bu f f e r ∗/UDR=data ;

void USARTWriteString ( char s t r [ ] )

71

Page 76: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

int i =0;

while ( s t r [ i ] != ’ \0 ’ ) USARTWriteChar( s t r [ i ] ) ;i++;

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ USART. h ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/#ifndef USART_H_#define USART_H_

void USARTInit ( ) ;void USARTWriteChar( char data ) ;void USARTWriteString ( char s t r [ ] ) ;

#endif

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ l o adcon t ro l . c ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/#include " l oad con t r o l . h"#include "PWM. h"#include "PID . h"

struct PID_DATA pidData ;

void l o adCon t r o l I n i t (SYS_DATA ∗data )

data−>cont ro lA lg=’D ’ ;data−>r e f e r e n c e =10;// Set PID parametersdata−>kp=104;data−>ki =13;data−>kd=2;PIDInit ( data−>kp , data−>ki , data−>kd , &pidData ) ;

void dutyCycleControl (SYS_DATA ∗data )

data−>dutyCycle=data−>r e f e r e n c e ;PWMSetIGBTDutyCycle( data−>dutyCycle ) ;

void vo l tageCont ro l (SYS_DATA ∗data )

data−>dutyCycle=50−PIDControl ler ( data−>re f e r en c e ,data−>voltage ,&pidData ) ;

i f ( data−>dutyCycle >100) data−>dutyCycle =100;

else i f ( data−>dutyCycle<0) data−>dutyCycle =0;

PWMSetIGBTDutyCycle( data−>dutyCycle ) ;

72

Page 77: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

void rotSpeedContro l (SYS_DATA ∗data )

data−>dutyCycle=50−PIDControl ler ( data−>r e f e r e n c e ∗22 ,data−>rotSpeed ∗22 ,&pidData ) ;

i f ( data−>dutyCycle >100) data−>dutyCycle =100;

else i f ( data−>dutyCycle<0) data−>dutyCycle =0;

PWMSetIGBTDutyCycle( data−>dutyCycle ) ;

void t ipSpeedContro l (SYS_DATA ∗data )

data−>dutyCycle=50−PIDControl ler ( data−>r e f e r e n c e ∗50 ,data−>tipSpeed ∗50 ,&pidData ) ;

i f ( data−>dutyCycle >100) data−>dutyCycle =100;

else i f ( data−>dutyCycle<0) data−>dutyCycle =0;

PWMSetIGBTDutyCycle( data−>dutyCycle ) ;

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ l o adcon t ro l . h ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/#ifndef LOADCONTROL_H_#define LOADCONTROL_H_#include "PID . h"

typedef struct

char cont ro lA lg ;double r e f e r e n c e ;double dutyCycle ;double vo l tage ;double cu r r en t ;double t ipSpeed ;double rotSpeed ;double loadpower ;int kp ;int k i ;int kd ;

SYS_DATA;

void l o adCon t r o l I n i t (SYS_DATA ∗data ) ;void dutyCycleControl (SYS_DATA ∗data ) ;void vo l tageCont ro l (SYS_DATA ∗data ) ;void rotSpeedContro l (SYS_DATA ∗data ) ;void t ipSpeedContro l (SYS_DATA ∗data ) ;#endif

73

Page 78: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ PID. c ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

#include "PID . h"#include " s td in t . h"

void PIDInit ( int16_t Kp, int16_t Ki , int16_t Kd, struct PID_DATA ∗pid )

pid−>sumError = 0 ;pid−>las tProce s sVa lue = 0 ;pid−>Kp = Kp;pid−>Ki = Ki ;pid−>Kd = Kd;pid−>maxError = MAX_INT / ( pid−>Kp + 1 ) ;pid−>maxSumError = MAX_I_TERM / ( pid−>Ki + 1 ) ;

int16_t PIDControl ler ( int16_t r e f e r en c e ,int16_t processValue ,

struct PID_DATA ∗pid_st )

int16_t er ror , PTerm , DTerm;int32_t Iterm , ret , temp ;

// Ca l cu l a te errore r r o r = r e f e r e n c e − processValue ;

// Ca l cu l a te and l im i t p−termi f ( e r r o r > pid_st−>maxError )

PTerm = MAX_INT;else i f ( e r r o r < −pid_st−>maxError )

PTerm = −MAX_INT;else

PTerm = pid_st−>Kp∗ e r r o r ;

// Ca l cu l a te i−term and l im i t i n t e g r a l sumtemp = pid_st−>sumError + e r r o r ;i f ( temp > pid_st−>maxSumError)

ITerm = MAX_I_TERM;pid_st−>sumError = pid_st−>maxSumError ;

else i f ( temp < −pid_st−>maxSumError)

ITerm = −MAX_I_TERM;pid_st−>sumError = −pid_st−>maxSumError ;

else

pid_st−>sumError = temp ;Iterm = pid_st−>Ki∗pid_st−>sumError ;

// Ca l cu l a te d−termDTerm = pid_st−>Kd∗( pid_st−>las tProce s sVa lue−processValue ) ;

74

Page 79: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

pid_st−>las tProce s sVa lue = processValue ;

r e t = (PTerm + Iterm + DTerm) / SCALING_FACTOR;i f ( r e t > MAX_INT)

r e t = MAX_INT;else i f ( r e t < −MAX_INT)

r e t = −MAX_INT;

return ( ( int16_t ) r e t ) ;

void PIDReset Integrator ( pidData_t ∗pid_st )

// Reset i n t e g r a l sumpid_st−>sumError = 0 ;

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ PID. h ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

#ifndef PID_H#define PID_H

#include " s td in t . h"

#define SCALING_FACTOR 128

typedef struct PID_DATAint16_t las tProce s sVa lue ;int32_t sumError ;int16_t Kp;int16_t Ki ;int16_t Kd;int16_t maxError ;int32_t maxSumError ;

pidData_t ;

#define MAX_INT INT16_MAX#define MAX_LONG INT32_MAX#define MAX_I_TERM (MAX_LONG / 2)#define FALSE 0#define TRUE 1

void PIDInit ( int16_t Kp, int16_t Ki , int16_t Kd, struct PID_DATA ∗pid ) ;int16_t PIDControl ler ( int16_t r e f e r en c e , int16_t processValue , struct PID_DATA ∗pid_st ) ;void PIDReset Integrator ( pidData_t ∗pid_st ) ;

#endif

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ motorcontro l . c ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

#include " l oad con t r o l . h"

75

Page 80: Control of marine current energy conversion system345686/FULLTEXT01.pdf · Control of marine current energy conversion system Erik Nyhlén This thesis involves the development of

#include " motorcontro l . h"#include "PWM. h"

void motorContro l In it (MOTOR_DATA ∗motor_data)

motor_data−>turb ineRadius=3; // [m]motor_data−>waterVe loc i ty=0;motor_data−>nominalTorque =12900; // [Nm]motor_data−>startMotor=0; // S ta r t motor o f fmotor_data−>startMotorTorque=12900/10;

void setMotorTorque (SYS_DATA ∗ sys_data , MOTOR_DATA ∗motor_data)

double motorTorque ;double startMotorTorque ;double turbineTorque ;startMotorTorque = motor_data−>startMotor

∗ motor_data−>startMotorTorque ;i f ( sys_data−>rotSpeed >0.01)

turbineTorque=motor_data−>turbinePower/( sys_data−>rotSpeed

/60∗2∗3 .14159 ) ;

else // Prevent d i v i s i o n by zero errorturbineTorque =0;

motorTorque=startMotorTorque+turbineTorque ;PWMSetACS800DutyCycle ( ( motorTorque

/motor_data−>nominalTorque )∗100) ;

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ motorcontro l . h ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/#ifndef MOTORCONTROL_H_#define MOTORCONTROL_H_

typedef struct

double waterVe loc i ty ;double turbinePower ;double turb ineRadius ;double nominalTorque ;double startMotorTorque ;int startMotor ;

MOTOR_DATA;

void motorContro l In it (MOTOR_DATA ∗motor_data ) ;void setMotorTorque (SYS_DATA ∗ sys_data , MOTOR_DATA ∗motor_data ) ;

#endif

76