intelligent magnetic field controller based on suitable ......intelligent magnetic field controller...

80
INTELLIGENT MAGNETIC FIELD CONTROLLER BASED ON SUITABLE MICROCONTROLLER PLATFORM A dissertation submitted to the University of Manchester for the degree of Master of Science in the Faculty of Science and Engineering 2016 Clement Adedeji Department of Computer Science

Upload: others

Post on 17-Mar-2020

16 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

INTELLIGENT MAGNETIC FIELD CONTROLLER

BASED ON SUITABLE MICROCONTROLLER

PLATFORM

A dissertation submitted to the University of Manchester for the degree of Master of

Science in the Faculty of Science and Engineering

2016

Clement Adedeji

Department of Computer Science

Page 2: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

1

Contents LIST OF FIGURES ...................................................................................................................................... 3

ABSTRACT ................................................................................................................................................ 5

DECLARATION ......................................................................................................................................... 6

INTELLECTUAL PROPERTY STATEMENT................................................................................................... 6

ACKNOWLEDGEMENTS ........................................................................................................................... 7

1. INTRODUCTION ............................................................................................................................... 8

1.1 Aims and Objectives ................................................................................................................ 9

1.2 Deliverables ........................................................................................................................... 11

1.3 Structure of Report ............................................................................................................... 11

2. BACKGROUND ............................................................................................................................... 12

2.1 Control Theory ...................................................................................................................... 12

2.1.1 Open and Closed Loop Control Systems ....................................................................... 14

2.1.2 Transfer functions ......................................................................................................... 14

2.1.3 Controlling Dynamic Systems- Process Controllers ...................................................... 16

2.1.4 Tuning of Controller Parameters .................................................................................. 23

2.2 Microcontroller and Hardware ............................................................................................. 25

2.2.1 Microcontroller Boards ................................................................................................. 26

2.2.2 Project Microcontroller Requirements ......................................................................... 28

2.2.3 Microcontroller Boards Comparison ............................................................................. 28

2.2.4 Complete Microcontroller Setup .................................................................................. 30

3. METHODOLOGY, HARDWARE AND SOFTWARE COMPONENTS ................................................... 32

3.1 Input- User defined value and Gauss meter interaction ...................................................... 33

3.2 Controller and Power supply ................................................................................................ 35

3.2.1 Power Supply Communication ...................................................................................... 35

3.2.2 PID Design and Tuning .................................................................................................. 38

3.3 Output of Electromagnet ...................................................................................................... 44

3.4 Frameworks used for Software Development ...................................................................... 46

3.4.1 Software Development on Visual Studio ...................................................................... 47

3.4.2 Software Development on the Arduino ........................................................................ 48

3.4.3 Overall Software Analysis ............................................................................................. 50

4. IMPLEMENTATION ........................................................................................................................ 52

4.1 Implementation in Standard C on Visual Studio ................................................................... 52

4.1.1 Communication with Gauss meter ............................................................................... 52

4.1.2 Communication with Kepco- GPIB instrument control ................................................. 55

4.2 Transfer function and Tuning parameters ............................................................................ 58

Page 3: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

2

4.3 Fully integrated system and PID Implementation using standard C ..................................... 59

4.4 Arduino Implementation ...................................................................................................... 62

5. TESTING AND RESULTS .................................................................................................................. 67

5.1 Software Testing and Evaluation .......................................................................................... 67

5.2 Instruments Communication Response ................................................................................ 68

5.2.1 Gauss meter communication ........................................................................................ 68

5.2.2 Kepco Power supply communication ............................................................................ 69

5.2.3 Kepco and Gauss meter combined communication ..................................................... 70

5.3 PID Results using Manual Tuning .......................................................................................... 72

6. CONCLUSION AND FUTURE WORK ............................................................................................... 76

6.1 Future Work .......................................................................................................................... 77

7. REFERENCES .................................................................................................................................. 78

Word Count: 18,477 words

Page 4: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

3

LIST OF FIGURES

Figure 1.1-Control System Interaction .................................................................................................. 10

Figure 2.1: Open loop control adapted from [25] ................................................................................ 14

Figure 2.2: Closed loop control adapted from [25] .............................................................................. 14

Figure 2.3: Negative feedback system adapted from [6] ..................................................................... 15

Figure 2.4: Derivative control taken from [6] ....................................................................................... 17

Figure 2.5: PD control taken from [6] ................................................................................................... 18

Figure 2.6: Integral controller output taken from [6] ........................................................................... 19

Figure 2.7: PI control output taken from [6] ........................................................................................ 19

Figure 2.8: PID block diagram taken from [26] ..................................................................................... 20

Figure 2.9:Step input ............................................................................................................................ 21

Figure 2.10-: PD controller response to step input .............................................................................. 22

Figure 2.11-: P controller response to step input ................................................................................. 22

Figure 2.12-: PID controller response to step input ............................................................................. 22

Figure 2.13-: PI controller response to step input ................................................................................ 22

Figure 2.14: Zeigler-Nichols open loop method replotted from [6] ..................................................... 24

Figure 2.15: Some of the boards in the Arduino range (a) Uno (b) Mega- taken from [20] ................ 26

Figure 2.16: Raspberry PI 3 model B taken from [24] .......................................................................... 27

Figure 2.17:Sparkfun USB host shield for Arduino ............................................................................... 30

Figure 2.18: LCD keypad shield ............................................................................................................. 30

Figure 2.19: Microcontroller full setup using Arduino and components ............................................. 30

Figure 3.1: Major project parts ............................................................................................................. 32

Figure 3.2:Lakeshore 425 Gauss meter- front and rear view with connected probe.......................... 35

Figure 3.3:Kepco power supply front view and rear view showing GPIB USB connection .................. 35

Figure 3.4: Power supply communication process ............................................................................... 36

Figure 3.5: Block diagram representation of whole system ................................................................. 38

Figure 3.6: System's step response showing parameters derivation taken from [27] ......................... 40

Figure 3.7-Step response of Example system taken from [19]. (a) Is the systems output and (b) is the

process input ......................................................................................................................................... 41

Figure 3.8:Tuning equations using Zeigler Nichols open loop method ................................................ 42

Figure 3.9: MATLAB code to simulate Tuning adapted from [20] ........................................................ 43

Figure 3.10: Auto tuning of sample transfer function .......................................................................... 44

Figure 3.11: Electromagnet with its power cables ............................................................................... 45

Figure 3.12: Hall sensor probe setup to get the field measurement ................................................... 45

Figure 3.13: Microsoft Visual studio community 2015 Development environment ............................ 47

Figure 3.14:Arduino Development Environment ................................................................................. 48

Figure 3.15:Software Flow of System ................................................................................................... 50

Figure 4.1: Needed header files for Gauss meter communication ...................................................... 53

Figure 4.2: Variable initialisation and port opening adapted from [28] ............................................... 53

Figure 4.3: Gauss meter settings .......................................................................................................... 54

Figure 4.4: Writing to COM port ........................................................................................................... 54

Figure 4.5: Monitoring data from Gauss meter & reading it with error checking- adapted from [28] 55

Figure 4.6: Headers for Kepco setup .................................................................................................... 56

Figure 4.7: Initialisation, opening device I/O and error checking adapted from [29] .......................... 57

Figure 4.8: Writing voltage value to Kepco and requesting the value back adapted from [29] .......... 58

Figure 4.9: The Complete System setup ............................................................................................... 59

Figure 4.10: Combining software parts in PID loop .............................................................................. 60

Figure 4.11: PID loop implementation code snippet ............................................................................ 61

Page 5: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

4

Figure 4.12: Writing PID value to power supply and getting time taken ............................................. 62

Figure 4.13: Arduino USB host shield ................................................................................................... 63

Figure 4.14- D-link USB hub .................................................................................................................. 64

Figure 4.15-Microcontroller setup ........................................................................................................ 64

Figure 4.16-Detecting devices connected to USB hub taken from [30] ............................................... 64

Figure 4.17: LCD keypad shield for user interaction ............................................................................. 65

Figure 4.18: Getting set point from keypad shield ............................................................................... 66

Figure 4.19: PID loop on the Arduino ................................................................................................... 66

Figure 5.1: Identification query to Gauss meter and response received ............................................. 68

Figure 5.2: Gauss meter reading and value received by program ........................................................ 69

Figure 5.3: Kepco Identification received from device ......................................................................... 69

Figure 5.4: Kepco voltage set remotely and printed by program ......................................................... 70

Figure 5.5: Value of 15V set to Kepco producing a field of 0.038T as shown on Gauss meter ............ 71

Figure 5.6: Received values of the Kepco and Gauss meter ................................................................. 71

Figure 5.7: Data from the program run without PID ............................................................................ 73

Figure 5.8: System's response without PID with set point at 0.015T ................................................... 73

Figure 5.9: Program output with PID .................................................................................................... 74

Figure 5.10: PID System's response with better response and little steady state error for a set point

of 0.015T ............................................................................................................................................... 74

Figure 5.11: Comparing system's response with and without the PID action for a set point of 0.015T.

.............................................................................................................................................................. 75

Page 6: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

5

ABSTRACT

The use of intelligent controllers is widespread and used for various purposes ranging from

straightforward applications like temperature control to more complex applications such as

cruise control in cars or aeroplanes. Primarily, intelligent controllers ensure the stability of

the system they are concerned with and give corrective action so as to keep the system

output as close as possible to the set point/reference input despite any disturbances.

The design of an intelligent controller has to take into account many factors. These factors

include the hardware on which the controller would be implemented, the type of controller

that is needed, the mathematical model of the controller and the tuning techniques.

This project implements one such type of intelligent controller which specifically controls

the field of an electromagnet by adjusting the current supplied to the coils of the

electromagnet. The work reported in this dissertation covers the different stages of

implementation from the needed background knowledge in control theory to the

considerations for the microcontroller and then communication with the power supply and

magnetic field (Hall) sensor. The controller implemented is a PID controller so the tuning

technique used is also covered.

The implementation of the system was first done on the computer and then work was done

to move it onto the microcontroller which was the Arduino. Assembly of the system

hardware was straightforward as they are standalone components but there was a lot of

work involved in establishing communication between the magnetic field sensor, power

supply and the computer especially because the hardware laboratory equipment that was

used needed some significant low-level programming effort.

The system was tested for performance and efficiency at different levels and demonstrated

the needed functionality.

Page 7: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

6

DECLARATION

This dissertation is my original work unless referenced clearly to the contrary, and no

portion of the work referred to in the dissertation has been submitted in support of an

application for another degree or qualification of this or any other university or other

institute of learning.

INTELLECTUAL PROPERTY STATEMENT

I. The author of this dissertation (including any appendices and/or schedules to this

dissertation) owns certain copyright or related rights in it (the “Copyright”) and s/he

has given The University of Manchester certain rights to use such Copyright,

including for administrative purposes.

II. Copies of this dissertation, either in full or in extracts and whether in hard or

electronic copy, may be made only in accordance with the Copyright, Designs and

Patents Act 1988 (as amended) and regulations issued under it or, where

appropriate, in accordance with licensing agreements which the University has

entered into. This page must form part of any such copies made.

III. The ownership of certain Copyright, patents, designs, trademarks and other

intellectual property (the “Intellectual Property”) and any reproductions of copyright

works in the dissertation, for example graphs and tables (“Reproductions”), which

may be described in this dissertation, may not be owned by the author and may be

owned by third parties. Such Intellectual Property and Reproductions cannot and

must not be made available for use without the prior written permission of the

owner(s) of the relevant Intellectual Property and/or Reproductions.

IV. Further information on the conditions under which disclosure, publication and

commercialisation of this dissertation, the Copyright and any Intellectual Property

and/or Reproductions described in it may take place is available in the University IP

Policy (see http://documents.manchester.ac.uk/display.aspx?DocID=24420), in any

relevant Dissertation restriction declarations deposited in the University Library, and

The University Library’s regulations.

Page 8: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

7

ACKNOWLEDGEMENTS

I thank God Almighty for seeing me through and granting me the opportunity and needed

abilities.

Much gratitude to my supervisor Prof. Thomas Thompson. You have been very instrumental

to the realisation of this project. Your support, constructive criticism and guidance are so

wonderful, and not to mention the speed at which you give feedback. I cannot thank you

enough.

Also to Craig Barton, I extend my gratitude and really appreciate your help with technical

difficulties and your constant follow-up to ensure I was making progress. I cannot forget

your assistance.

To my wonderful parents Mr and Mrs Adedeji, I appreciate your continued love, support,

understanding and prayers; can fully say it is what has kept and brought me this far.

My amazing brothers and sister – Rotimi, Yemisi and Tobi, your help, encouragements and

prayers are greatly appreciated, means a lot and was a real pillar of support. Love you all to

bits.

Finally, to all my friends and particularly Jemima and Sunesh. You were extremely helpful

and available during the project implementation, kept spurring me on and helping me and

indeed made the whole experience memorable, I appreciate you all. Even if I cannot

mention all your names but I have all of you in mind. God bless.

Page 9: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

8

1. INTRODUCTION

The first recorded occurrence of magnetism was made by the Chinese in 2637 BC [1].

Emperor Hoang-Ti was reputed to have a chariot figurehead that pointed south regardless

of the chariot’s direction. This was what developed into the compass. The magnet was

produced from an ore called Magnesian stone which gave birth to the name magnet [1].

Magnets are ubiquitous and are key to the functioning of many devices and industrial

processes. Some of their applications are listed below to mention a few:

Magnetic resonance imaging in healthcare.

Maglev trains for transportation- they operate on magnetism and have no wheels as

the train ‘floats’ on the track due to repulsion and thus removes friction.

Many rotating systems work on the magnetism principle- normally one magnetic

field trying to align with another cause the rotation.

High-powered magnets are used in ports to move containers.

Data storage- in hard disk drives (HDDs), the magnetic material called the platter

holds data.

There are two types of magnets named permanent and temporary magnets. The difference

between these two types of magnets is in the duration of how long they retain their

magnetism. Permanent magnets retain their magnetism after the magnetic field applied to

the material has been removed but temporary magnets do not retain their magnetism.

Temporary magnets are easy to control as they can be easily switched on and off and this is

what applies to electromagnets. A phenomenon discovered by Oersted in Copenhagen in

1820 revealed that when current passes through a conducting material it gives a magnetic

field and the field can be made stronger by winding the conductor into a coil [1]. This

phenomenon is what is referred to as electromagnetism.

Electromagnets are used in a vast range of applications like motors in electrics fans,

blenders etc. The more current supplied to the motor coils, the more the induced

magnetism which can then control the speed of the rotation. Such applications of

electromagnets clearly show that there is a pressing need to control the fields of these

electromagnets in order for them to operate as desired and this can be done manually or

automatically.

Page 10: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

9

In the world of today, automatic control is desired and more efficient in the sense that it can

make changes as and when needed and this is called automation. Automatic control is when

a system is intelligent enough to perform operations in the sequence required and control

the outputs to the desired values. The need and demand for controls in many systems of

today without human intervention is ever increasing. This has led to the incorporation of

automation and control engineering in many systems such as production lines, temperature

controllers etc. This is done in order to meet the demand for automation due to its

numerous benefits that include manpower saving, accuracy, energy efficiency etc.

Control systems have been used for over 2000 years with water clocks being one of the

earliest examples [2]. Generally, the control mechanisms role in a system is to automate

some process or to regulate a condition at a desired state or value as requested by the user.

The efficiency of a control system is measured by the following characteristics:

Stability- When the system has no oscillations

Zero steady-state error- When the system finally settles, there should be no error

meaning there is no difference between the reference input and output.

Quick response time- Time taken to get to the reference value should be minimal i.e.

little dead time.

1.1 Aims and Objectives

The main aim of this project is to implement an intelligent magnetic field controller that

possesses the characteristics of an efficient control system with the use of a microcontroller.

It is focused on building a standalone control system that interacts with a computer through

the microcontroller to control the magnetic field of an electromagnet. This is done by

regulating the current from a power supply in response to the magnetic field measured by a

Gauss meter. It will allow for a user to enter a desired magnetic field and then the control

system responds by providing the needed current to generate the field and then notifies the

computer once the desired field has been achieved.

This type of standalone control system is effective and also a very suitable alternative to

expensive off the shelf controllers which can then be customised to the specific application.

Also, since it is standalone, it can be incorporated into different systems, adapt and re-

implement the same control action like in a temperature control for example.

Page 11: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

10

Figure 1.1-Control System Interaction

Objectives

Explore microcontrollers and determine a suitable one for this application.

Find out about different controller types.

Assemble the hardware components- the microcontroller, power supply and,

magnetic field sensor that is linked to hall measurement.

Mathematically model the control process.

Software Implementation of control action- program where the microcontroller is

the centre of communication and interacts with the rest of the hardware as shown in

figure 1.1.

Page 12: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

11

1.2 Deliverables

The main deliverable will be a working standalone intelligent controller on the

microcontroller. However, there are a couple of other deliverables that build up in order to

meet the main deliverable:

Selection of a suitable microcontroller.

Communication between the microcontroller and power supply.

Communication between microcontroller and Gauss meter (hall sensor).

Effective control action to meet the application needs.

Standalone functionality.

1.3 Structure of Report

This report covers a lot of details that were involved in working on this project and is

structured thus:

Section 2- This section covers the background information that is fundamental to

understand the project context. The areas discussed in this section are control theory which

includes the open and closed loop systems, transfer functions, type of controllers and

tuning. Also, the details of how a microcontroller was selected are covered here as various

options were considered.

Section 3- This section describes the methodology used, the hardware and software

components. This includes a detailed explanation of the major project areas, the transfer

functions and tuning techniques. Also covered is the breakdown of the software

development with the power supply, sensor and analysis of the complexities faced. Details

about the electromagnet are also covered here.

Section 4- This section covers the implementation of the processes introduced in section 3

including the two-stage implementation, the system identification, the tuning and the

control action.

Section 5- This section details the testing of the system at various levels and the system as a

whole. The results obtained are also presented here.

Section 6- This section discusses the future works and improvements that can be made

given additional time and then concludes the entire project.

Page 13: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

12

2. BACKGROUND

From the project aim which is to implement the controller, it is pertinent to have a thorough

understanding of the principles of control in order to implement the control action. Also,

since the microcontroller is the final platform on which the control action is implemented, it

was very necessary that thorough consideration was given to the various microcontroller

options.

Hence, this section is split into two areas to cover the areas mentioned above. The first

section contains detailed information about control theory. It also details the types of

controllers which are the Proportional (P), Proportional Integral (PI), Proportional-Derivative

(PD) and Proportional Integral Derivative (PID) controllers. Following which PID tuning is

then discussed.

The second section of this chapter describes the research undertaken into the available

microcontrollers which include the major considerations and how the final choice was

made. The other hardware parts used to complete the setup are also described.

2.1 Control Theory

A system can be defined as an environment that enforces a relationship between a set of

variables [3, 4]. It is the arrangement of parts to work together within a boundary so as to

give some output that can be obtained for a particular input [5]. Systems are split into two

categories; they can either be static or dynamic. A system is said to be static when the

output depends solely on the input at the present time.

On the other hand, systems that change with time are called dynamic [3, 4]. In other words,

their output depends not only on present input but also on other inputs which could be

delayed or advanced signals. Dynamic systems are best analysed using mathematical

equations so as to see how the output of the system responds to its input/initial condition.

As this project is a dynamic system, it needs to be considered in terms of control theory.

This (control theory) is a branch of engineering and mathematics that is concerned with the

behaviour and response of dynamic systems to inputs and also how feedback can contribute

to the system’s output. Control theory aims to bring stability to a system since it is often

disturbed by random elements.

Page 14: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

13

The aims of control theory can be broken down into the following areas:

1. Control of a variable to meet a required value- Typical example of this is to maintain

the temperature of a room at a set value by setting the thermostat of an air

conditioner/heater [6].

2. Control of event sequence- This is typified in washing machines where the selections

set a sequence of events to occur [6]. An example is if whites are being washed and

then a washing cycle appropriate to whites is followed, which could include soaking,

then heat the water, adding soap etc.

3. Control occurrence of an event or not- Following the washing machine example, the

safety door lock feature of the washer prevents the operation from commencing if

the door is not safely locked [6].

In control theory, systems form either an open loop system or a closed loop system. In open

loop systems, the output has no impact on the control action because the controller does

not get any feedback from the output. However, in closed loop systems, the output is

measured and the controller gets this feedback from the output at the input for

comparison. Feedback refers to the means through which a signal that relates to the desired

condition being obtained is returned to modify the input signal [5]. In a negative feedback

system, this output value is subtracted from the input reference value and produces what is

called the error signal. The error signal is then passed to the controller which works towards

ensuring this error signal is reduced or eliminated. The absence of feedback in open loop

systems makes them less efficient for accurate control applications. Hence to control a

system precisely, negative feedback is required [5].

Systems that have one input and output are referred to as a SISO (Single Input Single

Output) while systems that contain multiple inputs and outputs are referred to as MIMO

(Multiple Input Multiple Outputs)

Page 15: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

14

Figure 2.1: Open loop control adapted from [25]

Figure 2.2: Closed loop control adapted from [25]

2.1.1 Open and Closed Loop Control Systems

Block diagrams are used in control theory to represent a system’s structure. Figure 2.1

shows a generalised representation of an open loop controller and Figure 2.2 shows that of

a closed loop controller.

To put these types of systems into context, consider the heating of a room done in two

ways. In open loop control systems, the heating element is switched on till the required

temperature is reached. Thus the room temperature is only controlled by the initial decision

of turning on the heater and no further changes are made. So if the room temperature

drops for some reason such as the opening of a window, no adjustments will be made since

no information is fed back to the heating element.

In a closed loop control system, there would be a measurement of the room temperature

using a sensor to monitor the actual temperature which will be compared with the desired

temperature. Hence if there is a disparity, the heating element can be switched on or off so

as to regulate the temperature at the desired value.

2.1.2 Transfer functions

As mentioned in the introduction to control theory, mathematical equations are used to

show the relationship between the system output and input. In dynamic systems, to show

the input and output relationship as a time function, the mathematical equations are usually

Page 16: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

15

Figure 2.3: Negative feedback system adapted from [6]

differential equations. However, to reduce the complexity of the relationship, the

differential equations are written in a different form by making use of Laplace transform.

This is very important for gaining an understanding of the system’s input and output

relationship as it gets more complex when the system has more than one element due to

the combination of each element’s differential equations.

The ratio of the output to the input is called the gain but when the differential functions are

transformed with Laplace, it takes the functions to the S-domain and the ratio is now

termed the transfer function [6]. The rules for transforming into the S-domain are

summarised as follows:

1. Firstly, for identification, a variable that is a function of time is indicated by putting a

t in brackets in front of the variable. An Example is a voltage as a time function- V(t).

When transformed to the S-domain, the change is indicated by replacing the t with s

so voltage becomes V(s). [6]

2. A constant remains unchanged. Consider 4V, as a time function it is 4V(t) and in S-

domain 4V(s).

3. The first derivative of a function (dv/dt) becomes sV(s), second derivative (d2v/dt2)

becomes s2V(s) and nth derivative (dnv/dtn) becomes snV(s).

4. Integral of ∫vdt is given as 1

𝑠𝑉(𝑠)

Consequent of the above, G = 𝑜𝑢𝑡𝑝𝑢𝑡(𝑌)

𝑖𝑛𝑝𝑢𝑡(𝑋) → Transfer function(S) =

𝑌(𝑠)

𝑋(𝑠) (2.1)

Consider Figure 2.2 that is a negative feedback system since the output is subtracted from

the input; the transfer function is gotten by first redrawing the block diagram as shown in

Figure 2.3.

Page 17: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

16

Starting with G(S) = 𝑌(𝑠)

𝑋(𝑠)−𝐻(𝑠)𝑌(𝑠) then rearranging to get output/input gives the transfer

function as shown in equation 2.2

Transfer function = 𝒀(𝒔)

𝑿(𝒔) =

𝑮(𝒔)

𝟏+𝑮(𝒔)𝑯(𝒔) (2.2)

G(s) – This is the output transfer function of the controller

H(s) – This is the transfer function in the feedback path

Deriving transfer functions can be complex as stated earlier especially for systems with

multiple elements and higher order differential equations. This is because the method used

in this approach is to model the elements of the system mathematically based on their

characteristics and then take the Laplace transforms before being able to obtain the transfer

function. However, another approach can be followed to get the transfer function that

involves less mathematical analysis. This approach involves checking the input-output

description of a system against a table of all possible responses [7]. It provides a particular

input such as step input for example and depending on the type of output obtained, the

transfer function can be gotten.

2.1.3 Controlling Dynamic Systems- Process Controllers

In dynamic systems, the error signal is passed to the controller in order to modify the

systems output. Dynamic systems use closed loop control as they are intelligent enough to

react to a change. This reaction is only possible when the system is monitoring the output

which is the case when the output is fed back to the input. Open loop systems do not have

such functionality and so from this point forward, the control system being referred to is the

closed loop system.

Process controllers are the components of the control system that take the error signal (the

difference between desired value and actual/feedback value) as input and give an output

signal to modify the output of the system [5].

There are different process controllers with diverse benefits for specific applications. The

most basic process controller is an on-off device (essentially a switch) that turns on a

correcting device when an error signal is detected and turns off this device once the error

has been corrected [6]. This type of controller is clearly inefficient and has limitations, as it

will have major time lags and oscillations. Other process controllers that are more efficient

Page 18: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

17

Figure 2.4: Derivative control taken from [6]

exist in which the PID controller stands out. It is a combination of proportional, integral and

differential action. Before discussing in detail the action of the PID controller, it is pertinent

to understand the action of the standalone controllers.

2.1.3.1 Proportional Control

This type of control makes the controller output proportional to the size of the error signal.

Mathematically, this can be expressed as given in equation 2.3

Controller output = KP × Controller input (2.3)

Where KP is a constant value that is called the gain.

There is a steady state error in all proportional controllers [5]. So, proportional controllers

are used when an acceptable steady and transient state response can be gotten by just

setting the gain to be large enough to reduce the steady state error without the need for

dynamic compensation [8]. However, as the gain gets larger, there is more chance of system

oscillation as oscillations occur as a result of time lags in a system. So a larger gain implies

more control action for an error which could cause an overshoot and oscillation.

An example of when proportional control is used is in an amplifier as it gives an output that

is proportional to the input’s size.

2.1.3.2 Derivative and Proportional Derivative Control

The derivative control is such that the change in the output of the controller is proportional

to the rate of change of the error signal with time.

Mathematically, this is expressed as given in equation 2.4

Output of D controller = KD × 𝒅𝒆(𝒕)

𝒅𝒕(rate of change of error) (2.4)

Where KD is the constant known as derivative time [6].

Figure 2.4 shows the constant response gotten at the output for a

constant rate of change of error. Thus, from this relationship, it can

be inferred that when the error signal changes the output at the

control will be large thus making this control suitable to give a

better transient response.

However, derivative controllers are usually combined with other

Page 19: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

18

Figure 2.5: PD control taken from [6]

modes of controllers as they have poor steady state response on a standalone basis.

This problem with derivative control is why it is combined with proportional control. The

output of this controller is then the sum of the output of the proportional and derivative of

the error signal.

This is mathematically expressed as

Output of PD controller = (KP × error) + (KD × rate of change of error); (2.5)

where KP and KD are the proportional and derivative constant respectively.

Rearranging equation 2.5 gives equation 2.6:

Output of PD controller = KP (error + (TD × rate of change of error)) (2.6)

Where, TD = 𝐾𝐷

𝐾𝑃 (2.7)

TD is referred to as the derivative action time [6].

Figure 2.5 shows the output of the proportional derivative control.

The initial spike in the control output is due to the derivative action

and then the following gradual change is because of the

proportional action. As a result, this controller has fast transient

response compared to just proportional control but steady state

error will still be required in order to handle constant input change.

2.1.3.3 Integral and Proportional Integral control

The integral control is of the form whereby the output of the controller is proportional to

the integral of the error signal. Integral control is also referred to as reset controller as it can

return a controlled variable to its set point after a disturbance [9].

Mathematically this is expressed as

Output of Integral controller = KI × integral control (2.8)

Where KI is the constant of integration.

Page 20: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

19

Figure 2.7: PI control output taken from [6]

Figure 2.6: Integral controller output taken

from [6]

Figure 2.6 shows the output of the Integral controller. The area under

the graph at time t is the value of the integral at t. So the output of

the controller is directly proportional to the area under the error

graph between 0 and t. Hence, as t increases, the area increases

which leads to an increase in the controller output [6]. Therefore,

integral control can be restated by saying; the rate of controller

output change is directly proportional to the error.

Like the Derivative controller, the integral controller is not used alone as

it can make the system unstable due to slow error response [9]. Because of this, it is

combined with the proportional controller.

The output of this controller is the sum of the output of the proportional and integral of the

error signal.

Output of PI controller = (KP × error) + (KI × integral of error with time) (2.9)

Where KP and KI are proportional and integral control constants respectively.

Rearranging equation 2.9 gives equation 2.10:

Output of PI controller = KP (error + 𝟏

𝑻𝑰error integral) (2.10)

Where, TI = 𝐾𝑃

𝐾𝐼 (2.11)

TI is referred to as the integral action time [6].

Figure 2.7 shows the output of the PI controller. The main

advantage of the PI controller is shown here as it can eliminate

steady state error due to the integral action of the controller that

gives an output even when the error is zero. This is because the

controller output is the sum of the area all the way to zero and as

such when the error is zero, the output of the controller at this

time is due to the sum of the previous errors.

Page 21: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

20

Figure 2.8: PID block diagram taken from [26]

2.1.3.4 PID Control

PID controllers are the most widely used type of process controllers. As mentioned earlier,

PID is a combination of proportional, integral and differential control actions which makes it

be referred to as the three-mode controller. From the discussions on each of the controller

types, it is observed that each type of controller has its own limitation so therefore the PID

aims at combining the advantages of each of the controllers and thereby eliminating their

limitations. PID is a controller that has no steady state error, increases system stability and

gives a better transient response.

As PID is a combination of three actions, the output of the PID is a sum of its three modes

and is mathematically expressed as:

Output of PID controller = (KP × error) + (KI × integral of error with time) + (KD × rate of change of error)

(2.12)

Where KP, KI and KD are the constants of proportionality, integration and differentiation

respectively.

Rearranging equation 2.11 gives equation 2.12

Output of PID controller = KP (error + 𝟏

𝑻𝑰error integral + (TD × rate of change of error)) (2.13)

Where TD and TI remain as defined above in equations 2.7 and 2.11.

Figure 2.8 depicts a PID controller structure.

Page 22: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

21

Figure 2.9:Step input

When designing a controller, the values of KP, KI and KD need to be selected and also the

appropriate control modes to be used must be identified that is, if to use proportional

control, proportional plus derivative, proportional plus integral or proportional plus integral

plus derivative control. The proportional controller is responsible for handling the current

error values and this is just as described in the proportional control where the error is

multiplied by the proportional gain. The integral controller handles past error values by

noting the output and applying a stronger action as the error builds in time. This is done by

multiplying the integral control constant KI with the integration of the error. The differential

controller predicts the error as it handles the rate of change of error and is done by

multiplying the derivative time KD with the differentiation of the error.

All these are shown in the standard form of the PID output in equation 2.12 above and

Figure 2.8. These parameters are important as they determine the system’s response to a

change in the set value, how quickly it responds to this change, settling time and occurrence

of steady state error or not.

A typical test signal- the step input is applied to the different controllers and the output is

shown in Figure 2.9. A step input is a sudden change to a set value.

Page 23: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

22

From Figure 2.10 it is seen that with the proportional controller, there are lots of

oscillations, high overshoots and long settling time. The system can be said to be under

damped at this state.

Figure 2.11 shows the response of the PD controller with a better transient response and

hence fewer oscillations, reduced peak overshoot and faster settling time. Here the system

can be said to have less under-damping.

The PI controller in Figure 2.12 has no steady state error, little overshoot and better settling

time. The system is said to be critically damped here.

Figure 2.13: PID controller response to step input Figure 2.12: PI controller response to step input

Figure 2.10: P controller response to step input Figure 2.11: PD controller response to step input

Page 24: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

23

The PID controller as shown in Figure 2.13 gives the best response as it has no oscillations,

no overshoot, no steady state error and good settling time. This is due to the derivative

action that makes it have a better transient response and integral action thus it eliminating

steady-state error. The system is over damped.

2.1.4 Tuning of Controller Parameters

The term tuning refers to the processes used in selecting the best control settings and

modes, which involves whether to use Proportional control, PI control, PD control or PID

control in order to get the desired performance [6]. This is important because it determines

the reaction of the system to a disturbance, its speed of response to changes, the time it

takes to settle down when a change occurs and also the occurrence of a steady state error

or not.

Various techniques can be used for tuning such as Tyreus-Luyben method, Automatic tuning

(Autotune) using software packages like MATLAB, Cohen-coon method, manual tuning, etc.

[10]. Nevertheless, two techniques that are widely used are the process reaction method

and ultimate cycle method which are both by Zeigler-Nichols. These two methods are

explored in detail as they can be used in many systems and have a lot of detail for their

implementation. Other tuning methods like the Auto tuning and Manual tuning which are

more straightforward are later considered in the PID design in sections 3.2.2.2 and 3.2.2.3

[6].

2.1.4.1 Process reaction method

This method is also called the open loop Zeigler-Nichols because the measurements made

are taken during an open loop control system test (no feedback) so as not to allow any

control action. This method is based on the system’s step response as the test signal is a

step signal and the method used here is the same as that used to obtain the transfer

function with a step response as described in section 3.2.2.1. The output response of the

controlled variable expressed as a percentage of the full range to the step input is what is

monitored and then plotted as the variable against time [5]. The graph obtained as shown in

Figure 2.14 is referred to as the process reaction curve. The parameters of the PID are

gotten from the systems response by reading the dead time or lag L and the value of T

which effectively deals with the rate of slope as shown in Figure 2.14. The Control

parameters are then gotten according to Table 1 criteria as specified by Ziegler and Nichols

Page 25: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

24

Figure 2.10: Zeigler-Nichols open loop method replotted from [6]

where K is the output change. More details on K, T and L are given in section 3.2.2.1. The

basis of this criteria is to obtain the closed loop response for the system as it shows a

quarter amplitude decay which basically is the system’s amplitude response decaying with

time such that the amplitude decreases by a quarter on each oscillation.

2.1.4.2 Ultimate cycle tuning method

This method, which is also the closed loop Zeigler-Nichols tuning method, first turns off the

integral and differential mode leaving only the proportional mode. The proportional

constant KP is initially set at a low value and then slowly increased until oscillations begin to

occur in the controlled variable. The value of KP when sustained oscillations occur is noted

Type of

Controller

KP TI TD

P 1

𝐾 𝑥

𝑇

𝐿

∞ 0

PI 0.9

𝐾 𝑥

𝑇

𝐿

3.3L 0

PID 1.2

𝐾 𝑥

𝑇

𝐿

2L 0.5L

Table 1: Open loop Zeigler-Nichols PID tuning table taken from [11]

Page 26: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

25

(call KU) and the corresponding oscillation time TU is measured. Consequently, using Table 2,

the control parameters can be calculated.

This tuning method is suited for high order systems with transfer functions of cubic and

higher degrees [5].

Type of Controller KP TI TD

P KU/2

PI KU/2.2 TU/1.2

PID KU/1.7 TU/2 TU/8

Table 2:Closed loop Zeigler-Nichols PID tuning table taken from [6]

This subsection of the background chapter has given a detailed background of control

theory that includes the transfer functions and the different controllers used in dynamic

systems. The methods of tuning the PID have also been discussed. In the next subsection of

the background chapter, the microcontroller and hardware are discussed.

2.2 Microcontroller and Hardware

Recall that the entire system structure is shown in Figure 1.1 and emphasizes the

microcontroller as the centre of the hardware connections/interaction. The rest of the

hardware are independent components that fit together easily through the available USB

connections and are listed below:

Computer-Dell OptiPlex

Power supply – Kepco BOP 20-20m: Bipolar power supply with 400W, ±20V DC

range, a maximum current of ±10A and USB interface.

Gauss meter - Lakeshore 425: Has a field range of 350mG to 350kG with LCD display

and USB interface.

Small Display screen (see Complete Microcontroller Setup later) - shows the process

for user interaction.

Page 27: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

26

Figure 2.11: Some of the boards in the Arduino range (a) Uno (b) Mega- taken from [20]

As the microcontroller is a very important hardware component at the end level, very

careful consideration had to be taken into account when deciding on which is most

appropriate for use.

2.2.1 Microcontroller Boards

Microcontrollers can be defined as special purpose computers that handle a specific

function. A microcontroller is built on an integrated circuit that has its own memory,

input/output interface, and processor. Generally, microcontrollers are embedded in systems

to control a process by taking the input from the device they are to control and then

sending signals to the other components associated with this device in the system [12]. A

very useful property of microcontrollers is that they are standalone components that can be

incorporated in various systems once they are programmed with the necessary

functionality. Applications of microcontrollers are numerous including use in televisions,

microwave ovens, engine controls in automobiles and much more.

Microcontrollers are widely used and as such, there are a number of microcontroller boards

available in the market such as the Texas Instruments Launchpad, Intel Galileo development

board and BeagleBone black development board to mention a few. However, for this

project, having preliminary looked at the various microcontrollers, the Raspberry pi and

Arduino were of most significant interest because of their robust features which are

discussed further.

2.2.1.1 Arduino Microcontroller

The Arduino is efficient for receiving data from sensors and interpreting them to give the

desired action. There is, however, a range of Arduino microcontroller boards such as the

Leonardo, Mega, and Uno to mention a few. Figure 2.15 shows two of the boards in the

Arduino range.

Page 28: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

27

Figure 2.12: Raspberry PI 3 model B taken from [24]

Arduino boards are programmed using the Arduino programming language that is based on

the concept of Wiring (an open source electronic prototyping platform) which is effectively C

language and the Arduino Development environment which is based on Processing [13]. It is

cross-platform and runs on Windows, Macintosh, and Linux. Arduino has 3 memory banks

which are the Flash memory where programs developed on the Arduino are stored, SRAM

(Static Random Access Memory) and EEPROM (Electrically Erasable Programmable Read

Only Memory). The flash and EEPROM retain information after power is turned off and are

non-a volatile unlike the SRAM [14].

2.2.1.2 Raspberry Pi

The raspberry pi is a small credit card sized computer that has all the functionality of an

actual computer. There are about four (4) models out and the raspberry pi 3 model B is the

latest release which is shown in Figure 2.16.

Raspberry pi runs on Linux environment and promotes python as its major programming

language. It comes with a slot for micro SD memory card and there is the RAM which is

volatile memory.

Page 29: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

28

2.2.2 Project Microcontroller Requirements

Looking at the properties of both the Arduino and Raspberry pi, they both have desirable

features; therefore, to make a choice, the needed requirements of the hardware for this

project had to be identified. These are:

Three USB ports for easy interface with other system components

A familiar and understandable programming language with useful libraries.

Components that can easily interface with the microcontroller like a mini screen

Quick Boot time.

The power ratings.

Ease of conversion from analogue to digital.

2.2.3 Microcontroller Boards Comparison

Consequent to the above features, the Arduino and Raspberry pi were compared as shown

in Table 3 to get the final selection. The ticks represent where one feature is preferable to

the other and the crosses represent the less desirable features.

Page 30: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

29

ARDUINO RASPBERRY PI

Programmable microcontroller Full operating system

Only does what it has been

programmed to do and designed for

reading data from sensors, computing

the data and output it to attached LCD

screens hence quicker

× Handles numerous functions like HDMI,

Ethernet and can be used as a computer

so could be slower

Quick boot up time. Takes about 8-10

seconds on the average

× Takes longer to boot as it is effectively a

computer. Raspberry pi 3 boots in about

21 seconds

Programmed in C × Promotes python as the main

programming language but supports

other languages

× Arduino Uno- uses ATmega328P which

is an 8-bit microcontroller

Raspberry pi 3 uses 64-bit quad-core

ARMv8 CPU. More computing power

Better for hardware projects and

applications

× More software based projects than

hardware

Many useful libraries for hardware and

electronics like motors, LCD etc.

× Libraries better suited to software

implementations

A Large number of I/O pins for

connections and analog inputs with

PWM outputs. Arduino Uno has 14

digital I/O pins

Also has a large number of pins for I/O.

40 GPIO pins

× Different shields available for added

functionality e.g. USB shields, internet

shields etc.

All ports built in and not much can be

added. Has 4 USB ports,

Table 3: Arduino and Raspberry pi comparison

After considering the factors needed for the project and comparing it with the features

provided by these two boards, the Arduino was chosen as it met the requirements better.

More specifically, the Arduino Uno as shown in Figure 2.15a.

Page 31: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

30

Figure 2.15: Microcontroller full setup using Arduino and components

Figure 2.13:Sparkfun USB host shield for Arduino

Figure 2.14: LCD keypad shield

2.2.4 Complete Microcontroller Setup

To give the additional USB ports needed, it was initially decided that two of the USB shield

shown in Figure 2.17 would be used. These USB shields are manufactured by Sparkfun. In

addition, a screen that interfaces easily with the Arduino was selected. This is the Arduino

LCD keypad shield shown in Figure 2.18

Due to the easy interface of the Arduino, these components are connected by mounting on

the Arduino through the pins.

Figure 2.19 shows the full setup of the microcontroller.

Page 32: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

31

The Arduino board can be powered either by the USB connection to the computer or by a

dedicated power supply. A dedicated power supply is used here in order to eliminate any

possibility of distortion to the running of the process by power interferences. The USB and

LCD screen shields take their power from the Arduino board once they are

connected/mounted as shown in Figure 2.19.

The details of the hardware have been discussed in detail especially the microcontroller.

This was necessary, as it is the major component to successfully implement the PID action.

With proper project breakdown that includes the appropriate decision on the needed

hardware and details on control theory, the methodology which is the next step is discussed

next in section 3.

Page 33: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

32

Input- user defined field and field value from

Gauss meter

Controller-power supply

control

Output- field of electromagnet

Figure 3.1: Major project parts

3. METHODOLOGY, HARDWARE AND SOFTWARE COMPONENTS

The overall system design is depicted in Figure 1.1. In order to get a fully functional system,

many design decisions for both hardware and software had to be made along with a well-

planned methodology. This chapter details the methodology and also introduces the

hardware components.

Section 2.2 in the background chapter has already detailed one of the very important design

decisions which was the microcontroller platform on which the PID controller would be

implemented. This was a very important decision; however, the design and method for the

rest of the system are also critical to the success of the system.

There are three major parts of the control system:

1. Input- get the user desired field and actual field reading from the Gauss meter.

2. Controller- implement PID control action based on the error signal between desired

and actual field so as to set the power supply accordingly.

3. Output- electromagnet to give the desired field and maintain the field till a new field

requested.

Page 34: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

33

3.1 Input- User defined value and Gauss meter interaction

It has already been established that the input is the user defined/desired field as well as the

Gauss meter input. The user input is straightforward to obtain as this is entered in the

computer or selected from the display.

The Gauss meter communication is the major task in getting the input. The Lakeshore

425(the Gauss meter used, as introduced in Microcontroller and Hardware ) has a USB

interface for communication which provides a common USB A-type to B-type connectors

and thus serial communication is used [15]. This involves using the COM port and sending

message strings.

The Lakeshore comes with an instrument communication utility which is a GUI (Graphical

User Interface) that allows for queries to be sent and messages to be received from the

instrument. However, this has limited use as it cannot be incorporated directly into the C

code written for the Arduino. Thus a C-language communication process is needed as

below:

Connect Lakeshore using USB interface

Install the device driver

Get the COM port from the device manager

Write and Read from COM port using available functions to send and receive

message strings

Close COM port

Before any development for communication with the Lakeshore, certain important settings

and factors need to be satisfied and taken into account in order for communication to be

established. Firstly, there are specific configuration parameters that must be strictly

followed and these are detailed in Table 4.

Page 35: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

34

Table 4: Communication port configuration for Lakeshore 425 Gauss meter taken from [15]

The baud rate is the speed at which information is transmitted between the devices and the

parity is for error checking.

Secondly, the character format has been changed for the Lakeshore compared to the

standard ASCII format. The smallest piece of data that is transmitted by the Lakeshore is a

character and two additional bits have been added to the normal eight bits thus making

each character 10 bits long. As seen from Table 4, a start and stop bit are the additional bits

which are added to be able to allow consecutive characters to be synchronised [15]. Seven

(7) bits are for data and one bit is used for parity check which all together gives the 10bits.

When sending and receiving data, each message string that is transmitted needs to be

terminated with a carriage return and line feed. The full lists of queries that can be sent and

the type of response received back as messages are all detailed in [15]. However, the major

queries of interest are the ‘*IDN?’ and ‘RDGFIELD?’ which are for device identification and

field readings respectively. The Identification query is used as a basic test to ensure

messages are correctly received from the Lakeshore and the field reading query is clearly

the most important query as that gives the field reading of the electromagnet. There is a

probe that senses the magnetic field which is connected to the Lakeshore and thus gives the

needed reading. The setup of the Lakeshore together with the connected probe and USB

serial connection are shown below in Figure 3.2.

Configuration Parameter Setting

Baud rate 57,600

Data bits 7

Start bits 1

Stop bits 1

Parity Odd

Flow control None

Handshaking None

Page 36: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

35

Figure 3.2:Lakeshore 425 Gauss meter- front and rear view with connected probe

Figure 3.3:Kepco power supply front view and rear view showing GPIB USB connection

When the input(s) has been gotten successfully, the next thing is the power supply

communication and design of the PID.

3.2 Controller and Power supply Having received the input, there is very likely going to be a difference between the user

defined field and the actual field (the error signal) which is the basis of the control. For this

control to occur, the power supply needs to be adjusted and this can only be done when

communication with the power supply has been established. Therefore, this is the first thing

considered here which is then followed by the PID design.

3.2.1 Power Supply Communication

The Kepco Bipolar power supply uses a GPIB-USB connection and this interface is what is

used for communication. Figure 3.3 shows the Kepco power supply used and the GPIB to

USB interface.

Page 37: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

36

Computer USB-GPIB connection

BIT 4886 interface

card

Kepco power supply

Figure 3.4: Power supply communication process

GPIB is the short form for General Purpose Interface Bus. GPIB was first developed in the

1960s by Hewlett-Packard and they called it the HP-IB which they made for the purpose of

controlling their programmable instruments [16]. The need for high-speed interface

communication between devices and controllers made the GPIB popular when digital

controllers and programmable equipment became available. The IEEE standard built on this

and created a protocol from which many manufacturers share a common communication

protocol called the IEEE 488.1. This standard was later enhanced as IEEE 488.2 that defines

common code set and interface capabilities [16].

The IEEE 488.2 specification added the SCPI- Standard Commands for Programmable

Instruments in 1990 [16] which are the commands that are specific for instruments. This

ensures the system compatibility with instruments and makes a uniform command set for

every instrument that is compliant with SCPI.

The Kepco is SCPI compliant and thus the command set of the SCPI is used in the device

programming to establish communication. The commands of the SCPI are defined in

headers such as the gpib and ni488 header files and the appropriate header will need to be

included in the C program developed in order to access the functionality.

The way the Kepco is able to be programmed to send and receive control message strings is

through a digital interface card which is the BIT 4886 card that is inbuilt into the power

supply. This provides the necessary platform for commands in forms of SCPI strings within

the required programming language (C) to be sent to the power supply, perform the needed

action and control the Kepco remotely. The details of the interface card for communicating

with the host computer are given in [17].

Therefore, the process for communication to the power supply from the

computer/microcontroller is given in Figure 3.4.

Page 38: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

37

The process for sending and receiving data from the Kepco from a developed program are:

Connect power supply using the GPIB-USB cable to selected port.

Install the necessary drivers- the GPIB used here is from National Instruments thus

the GPIB driver and Measurement & Automation Explorer(MAX) needs to be

installed. This is needed as it finds the connected instruments, gives the needed

handles to access them in order for them to be programmed and allows for

interactive control to test for communication. The Virtual Instrument Software

Architecture(VISA) is also the standard for programming and troubleshooting GPIB

system interfaces. It gives the necessary interface for programming between the

hardware and other development environments such as C, LABVIEW and

LabWindows/CVI. The VISA also comes with software libraries and interactive

utilities.

Add the header files (the visa header file is used), to access GPIB and SCPI

functionality like the ni488.2 header file and perform device I/O.

Use the device I/O routines (such as viWrite, viRead) to hide GPIB complexities.

Set the device address to listen and send. Like with the Lakeshore, there are control

messages from the controller to the power supply and response from the power

supply. The messages sent also have to be terminated using the line feed/new line.

Set the operating parameter- this controls the output and initially is set to zero. The

voltage and current limits are not remotely controllable [17].

The GPIB interface provides high communication rate, therefore the BAUD rate is

115200.

The steps above summarise the process for the communication with the Kepco. Again, there

is a list of commands that can be sent to the Kepco which is detailed in the Kepco

documentation for this power supply [17]. Test command for identification ‘*IDN?’ is used

to ensure communication is functional. Using the ‘VOLT’ and ‘CURR’ commands sets both

the voltage and current values respectively and should be done in a single command.

When using the VOLT and CURR commands for setting, it is important to note that the

interface card controls the Kepco through two channels which are the main channel and the

limit channel [17] where the main channel is set by the mode of operation. The operating

Page 39: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

38

Figure 3.5: Block diagram representation of whole system

mode is set by flipping the switch as highlighted in Figure 3.3 to either the current or voltage

mode as desired.

If the operating mode is in voltage, then sending VOLT and CURR sets the main channel and

limit value respectively. For example, if ‘VOLT 10; CURR 5’ is the message sent when in

voltage mode, then the voltage value is set to 10V and the current limit is set to 5A. The

opposite is the case if the operating mode is current.

Having established communication with the power supply, the full setup for the controller is

ready as both instruments (Gauss meter and power supply) are able to send and receive

messages, so the PID action is now needed.

3.2.2 PID Design and Tuning

Once the error signal (which is the difference between the set point and current state) is

detected, the PID would be triggered so the PID should give a fast and precise response as

needed.

The first point of call in the design of the PID is to model the system using block diagrams.

This clearly identifies the input and outputs and further allows for the closed loop transfer

function to be derived. This is given in Figure 3.5 which is a model of the system using the

hardware components and shows the closed loop system.

Figure 3.5 clearly visualises the control system process. From section 2.1.2, the general form

of a transfer function is derived and given in equation 2.2. Transfer functions are made up

of a numerator and denominator in the s-domain. The loop of this system starts with the

input which is the difference between the desired and actual field and is passed to the PID

Page 40: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

39

controller. The output of the controller is then the input value that is given to the power

supply so as to set the current and voltage to provide the desired field. The new current sets

the electromagnet to give the new field reading. This new field reading is now measured

again by the Gauss meter and subtracted from the set point at the input and this is

continuous so as to regulate the field value.

The tuning of the controller can be achieved in different ways. Three ways are discussed

here.

3.2.2.1 Tuning by getting Transfer function using Step Response and applying 63.2% method

The transfer function of the process can be obtained by using an empirical method such that

a certain signal such as a step or random signal is applied to the input and then at the

output, the characteristics are gotten [18]. The obtained characteristics are then used to

form the transfer function and get the tuning parameters as given by Zeigler-Nichols open

and closed loop methods in section 2.1.4 and table 1 and 2.

The transfer function of the process is obtained with the step signal through an open loop

experiment [18]. This experiment with the step signal begins with the system being at rest

and then the open loop experiment is carried out. The input signal is suddenly increased

(stepped) to a higher value than its current one and the output gotten is measured along

with other details like the timing. When this data has been obtained, the values can be

plotted and from the graph, the process characteristics are gotten and used in equation 3.1

[18] to give the process transfer function.

G(s) = 𝑲

𝑻𝒔 + 𝟏𝒆−𝑳𝒔 (3.1)

Where K, T and L are the static gain, time constant and dead time/delay time respectively.

Looking at these values more descriptively,

K is the measure of how much change will occur in a process due to the input.

T is the speed of response of the process after the input has been changed.

L gives information about the time taken for the process to begin to respond when a

change to the input has been made.

Page 41: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

40

Figure 3.6: System's step response showing parameters derivation taken from [27]

On getting these values, the transfer function can be gotten from the plot using different

techniques such as the 2-point method, 63.2% with tangent method, and others [18]. Of

these methods, the 63.2% with tangent method is used here.

This method is very widely used with the step response to form a transfer function [18]. The

output of the step response is related to the final steady-state value using equation 3.2 [18]

and the value of 63.2% is also derived from this equation.

𝑦(𝑡)

𝐾𝛥𝑢= 1 − 𝑒−𝑡/𝑇 (3.2)

Where 𝐾𝛥𝑢 is the final steady state value and T is the time constant. This equation gives the

63.2% after a time constant when t = T and thus the response is 1 - 𝑒−1 which evaluates to

0.632 [18]. This is shown graphically in Figure 3.6.

K can be obtained by dividing the final steady state gain by the change in the input to the

process (from its previous value to what is stepped to). From the graph, the value of K

would be K/change in input.

L is gotten by drawing a tangent to the curve from where it starts changing direction

(inflection point) as shown in Figure 3.6. The value of L from the Figure 3.6 is A. The point

where this tangent intersects with the x-axis has to be noted as this is the time it takes for a

significant change to occur at the output [18].

Page 42: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

41

Figure 3.7-Step response of Example system taken from [19]. (a) Is the systems output and (b) is the process input

The value of T is the time taken to reach 63.2% of K after the delay in time. Thus from Figure

3.6, the value of T would be A subtracted from B that is (B – A).

When these values have been obtained, they are substituted into equation 3.1 to give the

transfer function.

An example that used this method is as demonstrated by Bequette in his temperature

controller application in [19] and is shown here. The plot of the system’s step response and

step input is given in Figure 3.7.

The graph in Figure 3.7a is marked up with different colours that represent different

parameters spoken about. The green line marks the point where the system began to

respond to the change. The black horizontal line represents the 63.2% point and the

corresponding time shown by the black vertical line. K is marked using the red line. So using

the principles established above for obtaining the transfer function, K, T and L are gotten by:

K = 𝐹𝑖𝑛𝑎𝑙 𝑠𝑡𝑒𝑎𝑑𝑦 𝑠𝑡𝑎𝑡𝑒−𝐼𝑛𝑖𝑡𝑖𝑎𝑙 𝑠𝑡𝑒𝑎𝑑𝑦 𝑠𝑡𝑎𝑡𝑒

𝑐ℎ𝑎𝑛𝑔𝑒 𝑖𝑛 𝑡ℎ𝑒 𝑖𝑛𝑝𝑢𝑡 =

23−25

10.5−10 = -4

Page 43: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

42

Figure 3.8:Tuning equations using Zeigler Nichols open

loop method

In order to get T, the time at which 63.2% of the output was reached after the delay is

gotten. This is done by 0.632 *(25-23) = -1.3. As the start value of K is 25, this means the

63.2% value is 25 + (-1.3) = 23.7. Therefore, T is the value at 23.7 which is 4.5minutes.

L is the delay in the time it takes for the process to respond. So by inspecting part a and b of

the figure, the input was applied after one minute and it took another minute for the

process to respond. Therefore, L is one minute.

With the values of K, T and L, they can be put in equation 3.1 to give the transfer function

which is: G(s) = −4

2.5𝑠 + 1𝑒−𝑠

The tuning of the system can be done also. With the Zeigler-Nichols open loop method, the

values of K, T and L would be put in the PID equations from table 1 where the other

parameters are all described in Figure 3.8.

This open loop Zeigler-Nichols works for a wide range of systems and is not limited to higher

order systems like the Zeigler-Nichols closed loop method [6].

Using the open-loop tuning along with system identification makes this method applicable

to many types of control systems. Getting the parameters using the open-loop method are

not as direct as the closed loop where the gains are estimated as in manual tuning. This

open loop method implementation is similar to the step response described.

3.2.2.2 Manual Tuning of PID

The tuning parameters can be found by manual tuning. This is a basically a methodological

trial and error process. Usually, the integral and derivative values will initially be set to 0

leaving only proportional action and then the response is plotted. From the plot, it can be

Page 44: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

43

Figure 3.9: MATLAB code to simulate Tuning adapted from [20]

estimated how much integral and derivative action needs to be added because the integral

and derivative action affect the steady state and transient response respectively as detailed

in sections 2.1.3.2 and 2.1.3.3. This is could be a complex process, especially for higher order

systems.

3.2.2.3 Automatic Tuning of PID

Software tools like MATLAB provide a lot of functionality and have many highly optimised

libraries for many processes of which PID control design is one of them. This allows for the

system response to be plotted in a GUI and then the properties can be adjusted.

The process of the auto-tuning in MATLAB needs the transfer function to be known and

entered. On getting the transfer function, the command ‘pidtool’ is used to generate the

response with the tuning parameters. As this is a GUI, the response can be seen and as the

values are adjusted to give the desired response, MATLAB calculates and shows the

associated gains of P, I and D that is producing the displayed response.

An example program for a system and its transfer function as illustrated by a lecture at the

University of Michigan [20] is shown in Figure 3.9.

Page 45: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

44

Figure 3.10: Auto tuning of sample transfer function

On running this program, the response obtained is shown in Figure 3.10.

The ‘response time’ and ‘transient behaviour’ as highlighted can be altered till a satisfactory

plot is obtained. When the transfer function has been obtained, then it can be put into

MATLAB for the auto-tuning to be done. For example, if the output shown in the figure is

satisfactory, then the values of Kp, Ki and Kd are easily noted from the bottom right of the

figure as highlighted on the plot.

3.3 Output of Electromagnet

The result of the PID action sends the needed current to be supplied to the electromagnet

which produces the desired field.

Page 46: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

45

Figure 3.11: Electromagnet with its power cables Figure 3.12: Hall sensor probe setup to get the field measurement

The electromagnet used which is given in Figure 3.11 is powered from the Kepco as

expected. It has its power cables connected to the coils and these wires are then connected

to the power and ground terminals on the power supply. This is how different field values

are gotten by changing the power supply values.

The probe from the Gauss meter measures the field and gives the output to the user and is

setup as shown in Figure 3.12. Recall that it is a closed loop system; therefore the field of

the electromagnet will feedback to the input for comparison to continually monitor and

regulate the field at this value till the input is changed again. This is how the standalone

capability is also achieved as well because, when connected to any system needing a field, it

can provide this control on its own and then alert the rest of the system once it has set the

correct field.

Page 47: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

46

The input, controller and output are all software controlled, therefore it is pertinent to

carefully consider the development procedure for the software to give the needed

functionality and this is covered in section 3.4.

3.4 Frameworks used for Software Development

Sections 3.1, 3.2, and 3.3 give comprehensive details on the methodology and hardware for

the input, controller, and the output respectively.

Implementing all these (getting the input, controller and output) involves using COM ports

for the Gauss meter due to its USB connection and GPIB for the power supply. This takes

major programming effort as development is done at a low level. Working at such low level

would have made direct implementation on the Arduino microcontroller an even more

complicated task. This is because the Arduino does not have many of the robust features of

a full computer. Also, since add-ons are connected to the Arduino to give the additional USB

ports, this makes an indirect communication so therefore, the communication between the

Arduino and the equipment will be in two stages:

Firstly, there will have to be communication between the Arduino and the additional

USB ports. This will initialise the different USB ports and identify the ones on which

the power supply and gauss meter are connected to.

After successfully implementing the first part, the second part is then to begin

communication with both equipment through the USB ports.

This clearly will have some technicalities as the commands sent from the Arduino have to

ensure they are going to the correct port on the USB hub and using the appropriate

commands (serial or GPIB commands) for the device they are talking to. Also, issues like the

Baud rate for the different equipment communication need to be taken into consideration.

Due to all these foreseen technicalities, it was decided that it was best to use a systematic

approach and break down the development into a less complicated process. Therefore, the

implementation of the software started on a Windows based computer. This was done so as

to reduce the complexity of getting a fully functioning system by taking advantage of the

available functionalities of the computer which include COM ports, serial interfaces, robust

software development IDEs and compilers.

Page 48: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

47

Figure 3.13: Microsoft Visual studio community 2015 Development environment

Consequently, the development on the computer was done using Microsoft visual studio

which uses the Microsoft C compiler. C was used because the Arduino is programmed using

C and would therefore, make for easy transition to the Arduino on completion of

development in visual studio as it will only require the use of Arduino syntax to re-

implement the working functionality.

Therefore, section 3.4.1 introduces the software development platform of visual studio and

section 3.4.2 introduces that of the Arduino after which the breakdown of the overall

software control is covered.

The software implementation of the control action is just as crucial and important as the

hardware. Being that this implementation is finally intended to go on the microcontroller

was one of the major reasons a lot of research and time was spent to find a suitable

microcontroller. This was so that a familiar language with many useful libraries and

straightforward interface could be used.

3.4.1 Software Development on Visual Studio

Visual studio supports a range of languages and console applications. As earlier stated, C

was the language used to develop the software. Visual studio 2015 was used for the

development and the IDE is shown in Figure 3.13.

Page 49: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

48

Figure 3.14:Arduino Development Environment

To write C programs using visual studio, two things have to be done:

First, when creating a project, the option of precompiled headers has to be

unchecked.

Then secondly, once the project has been created, in the settings of the project,

navigate to C/C++ then all options. In this directory, under compile as, the project

has to be set to be compiled as C code and then development can continue.

Many helpful libraries are available to be imported on Visual studio and this gives access to

many windows functionalities for creating console applications to support COM port and

USB.

3.4.2 Software Development on the Arduino

Following on from section 2.2.4, the Arduino microcontroller is used and it comes with its

own integrated development environment (IDE) which is shown in Figure 3.14. Full details

about the Arduino which includes its accessories, kits and shields are all available on the

Arduino website given in [20].

Page 50: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

49

The Arduino is programmed in C, supports C++ libraries and header files extension and this

is what the IDE permits for software development in the text area. Programs written

through the Arduino IDE for the board are called sketches and have a file extension- ‘. ino’.

The initial step taken towards the implementation was to become familiar with the Arduino

software development process. To upload sketches to the board, the following procedure is

followed:

Connect Arduino to the computer through USB.

Open the Arduino IDE and select the applicable Arduino board, which is the Uno in

this case.

Get the correct COM port.

Upload the sketch to the board.

The Arduino like many other software development platforms usually requires additional

libraries for most applications. Due to this, the Arduino IDE allows the import of additional

libraries. This is provided by the Import Library menu and when used, it will add #include

statements for as many packages that are imported.

Another useful feature of the Arduino IDE is the serial monitor. This displays the serial data

that is being received by the Arduino board. It requires that the baud rate is set to match

the rate in the setup in ‘Serial.begin’. This is useful because the data being received by the

board can be seen, helps to debug, finds out if the Arduino is actually receiving data and the

type of data that is received so that the needed action can be performed.

The Arduino sketches are stored in flash memory which is non-volatile as stated earlier and

as such stores the last uploaded sketch. This is how the Arduino is able to continue to

perform the same action of the last upload even after switching it off and back on until

another sketch is uploaded to it.

Page 51: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

50

Figure 3.15:Software Flow of System

3.4.3 Overall Software Analysis

In order to meet the aim of this project, the implementation of the PID control action is

necessary. A breakdown of the project into the different stages for implementation from

the software level is done using the flow chart in Figure 3.15 to give the overview of the

system software control.

Get Reference value

The controller is a standalone system, therefore, the only time it has interaction with the

user is when the desired value is to be entered from the computer or through the LCD

keypad shield. When it has completed the control action, it alerts the computer/user that

the process is complete.

There is a set range of desired values that can be entered and this is because of the

limitations of the hardware in the sense that the power supply cannot generate a field that

is out of its supply range. As a result of this, the user interface will alert the user to the range

Page 52: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

51

of values that can be supplied. When the value is entered, it will be stored for comparison

with the current field value.

Measure current field value

On getting the desired value, the next thing will be to start communication between the

Computer/Arduino and the port on which the Gauss meter is connected. Through the serial

connection, the Gauss meter sends the value of the current field due to the initial state of

the power supply.

At this point, a loop will be started as it will be a continuous monitoring process to ensure

stability and the loop will only be broken when the user stops it or requests a new field

strength.

Pass to PID

On getting the measured value, it will be compared to the reference/desired value that was

earlier gotten. The error signal is gotten from this comparison and this activates the PID

controller so as to eliminate this error and also constantly regulate the output as the error

changes.

On activation, the PID action will start and continue till the error is reduced and will also

need to work out the value that needs to be supplied to the Kepco power supply to get the

desired field. The tolerable error range used in this project is ±0.002T.

Adjust Power supply

On completion of the PID action, the power supply will then be adjusted to the appropriate

current for the reference field. Using the GPIB connection, the controller will send a control

message to the Kepco to supply the required current.

When this is done, the new value is compared again to the reference value and ensures the

right accuracy level has been met before confirming the control action is complete. When

there is a further disturbance, the system will again be activated in order to maintain the

output at the reference input.

This section has covered the detailed methodology for the implementation of the controller

and hardware interaction. The next section then shows the applications of these steps to

implement the controller.

Page 53: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

52

4. IMPLEMENTATION

Having made all the important design decisions and with a well-planned methodology, the

step by step implementation built on the processes described in chapter 3 in order to create

a fully working system.

This chapter gives the full details of how the implementation was done at various levels and

then combined to give a fully working system.

From chapter 3, it was decided that the implementation would be better started on a

Windows computer rather than directly on the Arduino. Therefore, the first subsection of

this chapter covers the instrument communication implemented on the Windows computer

using Visual studio.

The next subsection then shows how the transfer function was derived and also gives details

on the values of the tuning parameters.

With the instrument communication and tuning parameters gotten, the next thing was to

combine these parts and implement the PID action which is done in the third subsection.

The fourth subsection then details the process for moving the PID controller onto the

Arduino board.

4.1 Implementation in Standard C on Visual Studio

The implementation in C for communication with the instruments required a very significant

low-level programming effort and took a lot of time to develop the code to give the needed

functionality. Therefore, it was very helpful that the development did not start on the

Arduino as it would have been far more complex since it requires its own microcontroller

commands.

The programs for communication with the Gauss meter and power supply were developed

separately and later integrated together.

4.1.1 Communication with Gauss meter

Communication from the computer to the gauss meter is done through the COM port.

When the Gauss meter was connected to the computer, it was on COM port eight (8) as

gotten from the Device manager.

Page 54: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

53

Figure 4.1: Needed header files for Gauss meter communication

Figure 4.2: Variable initialisation and port opening adapted from [28]

Having located the COM port, the next thing was to open this COM port and send and

receive messages through it. This is a console application as communication is text based.

Setup

When developing the program, Windows operating system has internal functions for

console applications which are useful and are in the windows header file. In addition to the

windows header file, other header files were also added to the program which includes the

string, time and stdlib.

Since queries are sent back and forth using strings, there was the need to add the string

header file. The time header is used for setting timeouts.

Initialisation

The communication port was then opened for communication and stored in an appropriate

variable type. This was done with appropriate error checking.

Page 55: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

54

Figure 4.3: Gauss meter settings

Figure 4.4: Writing to COM port

Handle is the variable type that holds the returned value when the port is opened. The

function CreateFile opens the communication port for the device I/O and the returned value

is stored in the HANDLE. However, notice that the function used is slightly different which is

the CreateFileA. This function has the same functionality as the CreateFile but the ‘A’ is the

ANSI compatible version. If this function is not used in Visual studio, there will be errors and

compilation problems. The comport is set to COM8 and also set to be able to be written to

and read from as seen in Figure 4.2.

Figure 4.3 shows how the settings for the Gauss meter as described in section 3.1 are

implemented in the program. The Lakeshore has four units of measurements which are:

Tesla(T), Gauss(G), Oersted(Oe) and Ampere per meter(A/m). Throughout the

implementation, the unit used is Tesla(T) so all and field readings referred to are in this unit.

Writing to the Serial Port

In order to get the field reading, the appropriate query ‘RDGFIELD?’ needs to be written to

the COM port. This is done using the windows function called the WriteFile which writes to

the port and again error checking is handled.

Reading from the Serial Port

When the setting query has been received by the Gauss meter, it sends back a response

message with the field value which needs to be read and stored. When reading from the

Page 56: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

55

Figure 4.5: Monitoring data from Gauss meter & reading it with error checking- adapted from [28]

COM port, data could just be listened for continuously or an event is setup to listen and

Windows notifies the program when a character is received.

The latter option was used and an event that listened for characters received was used to

wait for data before ReadFile is used to receive the data. This shown in Figure 4.5.

The above procedure achieved effective communication between the Gauss meter and the

computer.

4.1.2 Communication with Kepco- GPIB instrument control

Kepco power supply communication uses GPIB which is high-speed communication

protocol. The GPIB used as earlier stated is from National instruments. Like the Gauss

meter, there is also an interactive GUI utility to ensure communication but this cannot be

directly incorporated into the C code.

LABVIEW (Laboratory Virtual Instrument Engineering Workbench) has been widely used for

the programming of Kepco as it is a National instruments software GUI and it interfaces well

with a wide range of instruments. However, for this system, the C code had to be developed

and this was done as described. There are different headers and functions that could have

been used to communicate the Kepco like the gpib and the ni488.2 headers but the visa.h

was used because the libraries needed for it were available compared to the others.

On importing the visa.h library into the project, the program will not compile as the header

only holds the declaration of the functions of which some are declared as externs. To be

more specific, there would be a linker error because the definitions of the external symbols

Page 57: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

56

Figure 4.6: Headers for Kepco setup

would not be found as they are in an external file. To be able to get past this error, the

visa.lib file also had to be added to the project.

Also, functions like the ‘strcpy’ and ‘strset’ are depreciated in this version of visual studio.

This means that these functions have newer versions and the compiler tries to force the use

of this newer version by causing compile errors even if the old versions are still valid. To

solve the errors that are caused which are due to CRT_SECURE_NO_WARNINGS,

it(_CRT_SECURE_NO_WARNINGS) has to be added to the Preprocessor definitions. The

directory for this is in Visual studio is: Project- Preprocessor- Preprocessor Definitions.

The BIT 4886 card recognises the keyword(s) for programming the Kepco as a ‘parser’ and

these keywords have their own format. Though each keyword has a complete form, the

short form in capital letters is what is needed to send the instructions as used earlier in

section 3.2.1. For example, ‘VOLTage’ and ‘CURRent’ have VOLT and CURR in capital because

they are the keywords that need to be sent to the BIT card.

Setup

The header files used are shown. Again the string header file is needed because the queries

are sent in message forms.

Initialisation

Similar to the Gauss meter but with different command structure, the variables have to be

defined and then a communication handle is opened. Firstly, a default resource manager is

opened after which the handle is opened. The variable holding the returned value of the

handle is of type ViStatus.

The device address of the GPIB instrument has to be set when opening the handle. The

address of the Kepco is ‘6’ by default [17] and this was used. The code fragment for this

variable initialisation and handle opening is shown in Figure 4.7.

Page 58: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

57

Figure 4.7: Initialisation, opening device I/O and error checking adapted from [29]

Before controlling the Kepco remotely, it is necessary to remember that the limits cannot be

set remotely. Therefore, if limits need to be used, they would have been set with the

physical instrument controls on the device. Also, it is very necessary to ensure that the

current supplied to the electromagnet is manually set to zero before entering remote mode

so as to prevent disruption to data and damage to the equipment.

Writing to and reading from the Kepco

Having successfully added the lib file, and initialised the port, writing and reading from the

port is now possible using the keywords. Unlike the COM port communication, there is no

need for waiting for an event as the GPIB handles such situations adequately.

The functions ViWrite and ViRead are used for writing and reading respectively to the GPIB

interface. The string copy function (strcpy) sets the string into the variable which is then

passed to the write function. The voltage and current setting are specified explicitly as

queries and set the Kepco precisely.

Page 59: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

58

Figure 4.8: Writing voltage value to Kepco and requesting the value back adapted from [29]

After successfully developing this code which took a lot of development time, the Kepco

was remotely controlled using this program. The next section shows the implementation of

the transfer function and tuning of the PID parameters.

4.2 Transfer function and Tuning parameters

Following on from the methodology section, manual tuning was used to obtain the gains of

PID controller. This was done because the other methods required the transfer function to

first be derived before any further steps can be taken to get the gains.

Getting the transfer function will involve system identification techniques and one of them

was discussed with the step response and 63.2% tangent method. There are other such

system identification methods which could also involve the mathematical derivation of the

system. This will involve getting a current and magnetic field relationship such as

H = 𝑁

𝐿𝐼 (4.1)

Page 60: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

59

Figure 4.9: The Complete System setup

Where H is the magnetic field strength

N is the number of turns of the coil of the electromagnet

L is the length of the conductor

I is the current supplied

This equation will then be represented as a continuous function of time. The Laplace

transform will then be taken in order to put it in the S-domain and represent as the ratio of

the output to the input to give the transfer function as detailed in section 2.1.2.

Within the timeframe available for this project, implementing this and testing it to ensure its

functionality was not feasible and this applies to the other methods as well.

Consequently, the manual tuning started off with a set value for 𝐾𝑃 and the response was

recorded and plotted. Based on this response, values for integral and derivative action were

added till a satisfactory response was gotten. Once this was gotten, then the output of the

PID could be calculated using equation 2.12.

4.3 Fully integrated system and PID Implementation using standard C

With all the separate parts fully implemented including the tuning parameters, these project

portions had to be integrated together to implement the final working system. The full

setup of the hardware system is shown in Figure 4.9.

Page 61: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

60

Figure 4.10: Combining software parts in PID loop

Integrating the software of the different parts had to be done carefully to produce a fully

working system. The process through which this was done was broken down and analysed

through the flow chart as described in Figure 4.10.

From Figure 4.10, there were several variables needed to hold the set point, field and tuning

parameters and these were created. Now this PID loop had to be implemented to run

continuously as is clear from the flow chart. This was done using a while loop to keep the

process running.

Inside the while loop, the PID action was implemented and the code snippet is shown in

Figure 4.11. While the set point remains the same, the controller continues to regulate this

field value.

Page 62: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

61

Figure 4.11: PID loop implementation code snippet

With the set point at a certain field value, the actual field will have to be read in order to be

able to calculate the error. The communication with the Gauss meter implemented in

section 4.1.1 has been put in a function called ReadGaussmeter. The character array that is

holding the data read from the gauss meter has to be converted to a floating point number

before being returned. On receiving the gauss meter reading which is the actual field, the

error can be calculated. There are two additional error variables added which are the total

error and previous error. These errors take care of the integral and differential actions of

the PID respectively. This is because the total error is needed for the integral action as it is

corrective from the present point all the way to the start. The derivative variable needs the

previous error in order to try and make a prediction of what type of errors could occur

based on past error rate.

Once these are done, the various values for P, I and D are calculated by multiplying the

errors with the tuning parameters. The value of the PID according to equation 2.12 is the

sum of the three control actions.

Page 63: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

62

Figure 4.12: Writing PID value to power supply and getting time taken

This value of the PID is then passed to the power supply so as to produce the needed

current to give the desired field. Also a clock is used to time the process to record the time

taken for the system to produce the new field. The implementation of the PID calculation

and timing are shown in Figure 4.12.

4.4 Arduino Implementation

With implementation completed on the windows based computer, the control action

implementation on the Arduino microcontroller could now be done more straightforwardly.

Section 2.2.4 already covered the setup of the Arduino microcontroller with the additional

shields used. Major time was spent on getting the Sparkfun USB shields to work with the

Arduino Uno. This took a lot of time because there were hidden issues both technically and

from the manufacturers of the USB shield.

The first step was to start communication with the Arduino using only one USB shield and

then later both. However, there was no connection detected between the USB shield and

the Arduino and it was not software related. After much testing, research and problem

solving, it was realised that there was an issue from the manufacturers. The problem was

that the digital pin 7 on the shield that should have been connected to the RESET pin had

not been connected [21]. Though Sparkfun claimed to have rectified this issue, there was no

Page 64: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

63

Figure 4.13: Arduino USB host shield

connection until a solution was done. Therefore, to rectify this problem, a jumper wire was

connected between these two pins which are pin 7 and the reset pin. Once this was done,

the code uploaded properly and was able to detect devices connected to the USB hub.

Despite this working, it meant that some major rewiring would need to be done to allow for

another shield to be connected on top of the first one and then the keypad shield. This was

not feasible and also using two USB shields did not work out well. Therefore, at this point,

the USB shield was changed to another USB shield made by Arduino which is shown in

Figure 4.13

In order to be able to use the keypad shield and correct the non-working of two shields

mounted on each other, the implementation was changed to use the Arduino USB host

shield with a USB hub. The USB hub is shown in Figure 4.14 and the full setup of the

microcontroller is now as shown in Figure 4.15. With the full setup, the USB hub is

connected to the USB host shield.

Page 65: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

64

Figure 4.14- D-link USB hub Figure 4.15-Microcontroller setup

Figure 4.16-Detecting devices connected to USB hub taken from [30]

The software developed for this setup was in two stages. First, the Arduino had to be able to

initialise the USB hub through the host shield so that connected devices can be detected.

When this was done, it was then to implement the PID action on the Arduino.

Arduino and USB hub interaction

Building on the USB 2.0 Host library, this software prints an identifier for each device that is

connected to the hub. This is the basic test to ensure that the devices are detected.

The usbhub header file has to be added to the folder directory. From Figure 4.16, the more

devices that are added, the more Hub instances would need to be created. Here only two

Page 66: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

65

Figure 4.17: LCD keypad shield for user interaction

instances are created because only two devices would be connected to it. On successful

initialisation of the devices on the hub, the next thing is to incorporate the code developed

on the Windows computer on the Arduino.

PID control on Arduino

The implementation on the Arduino will require importing the headers used to start

communication for both devices individually. The headers used and imported are therefore

the visa, windows and string header file.

Using the LCD display screen gives a more user-friendly interaction thus, it was included in

the implementation. The LCD keypad shield used, has four buttons which allow four

selections to be made. Consequently, the field values produced at 5V, 10V,15V and 20V

which are 0.010T, 0.024T, 0.037T and 0.050T respectively were the options displayed on the

screen and is shown in Figure 4.17.

Establishing communication with the equipment used the same protocols as on the

Windows computer so the important issue here was ensuring the USB hub was linked

properly to the equipment. Once this was done, the set point values were set based on the

keypad shield selection. This was done as shown in Figure 4.18.

Page 67: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

66

Figure 4.18: Getting set point from keypad shield

Figure 4.19: PID loop on the Arduino

This method of getting the set point was one of the major changes for the Arduino

implementation compared to the windows computer. After getting the set point, the gauss

meter reading needed to be obtained from the hub port it is connected to.

On getting this reading, the error could be calculated and passed to the instance of PID class

that was created. This PID instance computes the PID value and returns the needed output

and since the tuning has been done already, the values for 𝐾𝑝, 𝐾𝐼, 𝐾𝐷 are already known and

are reused.

This output value is then sent to the Hub port connected to the Kepco in order to set the

voltage accordingly to give the needed field. Figure 4.19 shows a snippet of the code.

This control procedure continues running until it is stopped by the user.

This section covered the implementation details of the various development stages and

processes involved. The results obtained are given in Section 5.

Page 68: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

67

5. TESTING AND RESULTS

A lot of work had gone into the implementation of the system as it is a large project with

many individual parts, sub-systems and topics that had to be understood, built and tested to

make up the full working system. This section covers the testing and evaluation of the

various subsystems and the system as a whole. Section 5.1 gives a breakdown of the test

procedure and the following sections give the results of the tests as described.

5.1 Software Testing and Evaluation

To test the software of the entire system and ensure correct working of every part, the

following areas need to be checked and evaluated.

The test criteria include the following:

The control action of the PID- This needs to be tested by simulation before

implementation to ensure the performance of the controller and that the tuning is

done optimally. This involves testing with various parameters and plotting the graphs

to view the response. MATLAB is efficient for such simulation.

Arduino and USB shield interaction- This is necessary to ensure that there is actual

communication between these boards before actually connecting the intended

devices. Testing of this will involve connecting the boards and trying test devices

such as flash drives, mouse etc.

Arduino and LCD Screen- Output of messages to the screen and how choices are

made with the keypad buttons.

Arduino, power supply, and Gauss meter- This is to ensure there is communication

between the Arduino, the power supply and gauss meter. A handshake should be

established so that the Arduino can send a prompt to both connected hardware and

get a response signal back from both of them. This is a major test and backbone for

every other communication.

Computer, power supply and Gauss meter- ensure there is communication between

computer and rest of the hardware. Test the working of the PID control action on the

computer before trying implementation on Arduino.

PID implemented on Arduino- repeat same test performed on the control action on

the computer on the Arduino.

Page 69: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

68

Figure 5.1: Identification query to Gauss meter and response received

The areas for testing after implementation in order to ensure correct functionality includes

both hardware and software. As stated earlier, the next subsections now cover details on

each individual area mentioned here.

5.2 Instruments Communication Response

Following on from the implementation, this section shows the instruments responding to

the queries sent to them and sending back the readings.

5.2.1 Gauss meter communication

The initial test message sent to the Lakeshore was the identification query. This sent back

the model of the equipment. The response received by the program is shown in Figure 5.1

With the identification response obtained, the sending and receiving were confirmed

working. Thereafter, the query for field readings was sent to get values. The value on the

Gauss meter and that received in the program are shown in Figure 5.2.

Page 70: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

69

Figure 5.2: Gauss meter reading and value received by program

Figure 5.3: Kepco Identification received from device

5.2.2 Kepco Power supply communication

The same identification test was used to confirm communication from the Kepco. This also

sent back the model of the equipment and is as shown in Figure 5.3.

After the identification, the next test was to set the power supply voltage and also read back

the voltage. This is shown in Figure 5.4. Notice that the format of the readings sent by the

Kepco are in powers of ten. So a value of 15V is received as 1.499E1.

Page 71: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

70

Figure 5.4: Kepco voltage set remotely and printed by program

5.2.3 Kepco and Gauss meter combined communication

Having tested both the individual equipment, it was pertinent to test the combined

software implementation and see the field value produced as a result of the power supply

setting. The figure shows the value of 15V set to the Kepco and the field generated which

was 0.038T; values which correspond to the ones read into the program. It is necessary to

note that the field values might change slightly depending on the distance of the probe to

the electromagnet.

Page 72: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

71

Figure 5.5: Value of 15V set to Kepco producing a field of 0.038T as shown on Gauss meter

Figure 5.6: Received values of the Kepco and Gauss meter

The values read in by the program corresponds to these values on the instruments as

shown.

Page 73: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

72

This communication of both equipment setting and receiving was pivotal to the PID action.

5.3 PID Results using Manual Tuning

The developed programme for the PID action has been discussed in section 0. Manual

tuning was used and the results are presented here.

The data sets gotten from the PID action are printed showing the field produced, the time

taken to set each intermediary field and then the overall time taken to go from one field

value to the set value.

The magnetic field changes each time a voltage is supplied therefore an approximate

calculation was done to find out by how much the magnetic field changes for each volt

applied.

This was done by setting the voltage to 10V initially and waiting for a steady state value

which was obtained as 0.024T. After this initial steady state, the supply voltage was stepped

to 15V and again the steady state field value was recorded which was 0.037T. Using these

values, the change in the magnetic field per voltage was calculated as shown below.

𝐶ℎ𝑎𝑛𝑔𝑒 𝑖𝑛 𝑚𝑎𝑔𝑛𝑒𝑡𝑖𝑐 𝑓𝑖𝑒𝑙𝑑

𝐶ℎ𝑎𝑛𝑔𝑒 𝑖𝑛 𝑣𝑜𝑙𝑡𝑎𝑔𝑒 =

0.037−0.024

15−10 = 0.0026T/V

Note that this value could change depending on the distance of the sensor to the

electromagnet.

The results presented here start by showing the printed data in the program followed by the

plots of the system response with and without PID action.

The system response was first done without PID action using a set point of 0.015T and the

system started from rest. The voltage value was increased by the smallest possible value.

The Kepco power supply’s calibration moves in steps of 1V so the smallest possible change

between two values that can be set with noticeable change is 0.5V.

Now, the output from the program and the graph are shown in Figure 5.7 and Figure 5.8

respectively.

Page 74: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

73

-0.002

0

0.002

0.004

0.006

0.008

0.01

0.012

0.014

0.016

0.018

0 2 4 6 8 10 12 14

Fie

ld(T

esl

a)

Time(seconds)

SYSTEM'S RESPONSE WITHOUT PID

Figure 5.7: Data from the program run without PID

Figure 5.8: System's response without PID with set point at 0.015T

The results show a total time of about 12.44s with oscillation, overshoot and settled at

0.014 giving a steady state error. This response time is not as bad as it is still fairly fast but

can be improved.

Page 75: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

74

Figure 5.9: Program output with PID

0

0.002

0.004

0.006

0.008

0.01

0.012

0.014

0.016

0.018

0 1 2 3 4 5 6 7

Fie

ld(T

esl

a)

Time(seconds)

System's Response with PID

Figure 5.10: PID System's response with better response and little steady state error for a set point of 0.015T

Next, the tuning parameters were tried and this started with only proportional action. The

final tuning parameters obtained from the manual tuning that gave a satisfactory response

are:

𝐾𝑃 : 200

𝐾𝐼 : 15

𝐾𝐷 : 3.0

The set point was again 0.015T and using these values, the response time was faster, less

oscillation but a little steady state error and this was due to the loop boundaries used. These

loop boundary was not changed so that accurate comparison could be done between the

response with and without the PID. The total time taken is shown in Figure 5.9 and the

plotted response is shown in Figure 5.10.

Comparing both graphs is one figure is done in Figure 5.11 . The changes are more easily

seen in this graph.

Page 76: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

75

-0.002

0

0.002

0.004

0.006

0.008

0.01

0.012

0.014

0.016

0.018

0 2 4 6 8 10 12 14

Fie

ld(T

esl

a)

Time(seconds)

Systems response with and without PID

Figure 5.11: Comparing system's response with and without the PID action for a set point of 0.015T.

The difference in rise time is clear, with the PID action added to the system. The final steady

state value is also much closer to the set point compared to the other system. The reason

why this has better response has already been discussed earlier. The proportional constant

makes movement to the set point faster and is proportional to the error. The integral value

reduces the steady state error by bringing the field reading close to the set point as the

proportional action alone will cause overshoot. Therefore, the integral action is responsible

for pulling the field slowly to the set point. The derivative action slows down the speed of

correction on approaching the set point.

This section has given the results from the different stages of the project and how they were

obtained. The next section summarises the whole project and discusses additional

improvements.

Page 77: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

76

6. CONCLUSION AND FUTURE WORK This project was a large one that brought together many areas and aimed at combining

these various areas into a portable solution. Many of the individual areas had a very

significant depth that had to be understood in order to make progress on the project while

new areas unfolded in the course of the implementation.

The project began with clearly defining the aim and objectives of the project and then the

deliverables. The overall aim was to implement a standalone controller on a

microcontroller. Since this was the task, it was necessary to break down the project into

smaller constituent parts, solve each part and then combine it into a working solution.

As with any other project, extensive background research was carried out into major topics

such as control theory, microcontrollers and device programming.

The material on control theory provided the needed information to implement the

controller from a theoretical point of view and understand the needed action that was to be

built. The tuning of the PID and the method suitable to this application was also covered in

this material. In the course of designing the controller, system identification occurred which

is basically how the type of system being dealt with can be modelled to get its mathematical

representation.

Moving on to the implementation, lots of time was spent because of the technicality of the

work involved. The Gauss meter communication had subtleties like the fact that its

character format had been changed and more bits had been added to the character format.

Furthermore, the windows function for opening communication with the device had to be

ANSI version else the port would not be opened.

The Power supply also had a whole lot of issues around it. Though GPIB programming is

popular, finding the libraries specific to this instrument to allow for a C implementation was

tough as usually, applications like LABVIEW are used effectively for such. The compiler for

these programs also has to be good and recognise the various windows functions used.

Using the NI488.2 header communications did not work for this project as the needed

object file and DLL (Dynamic Linked Libraries) could not be found. The communication was

finally established using VISA commands to write and read from the Kepco.

Page 78: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

77

The implementation was done in two phases, firstly on the computer and then onto the

Arduino. This helped simplify the implementation a bit as the use of the computer is a

familiar environment.

Also when starting implementation on the Arduino, there was no handshake between the

Arduino and the shields that were first used. This was a manufacturer’s error which took lots

of time to resolve. The board was eventually changed and a USB hub was used for the

implementation. With the Arduino, the size of the code also has to be considered as it takes

a maximum of about 2Mb.

After implementation, testing of the various parts was necessary in order to show the

working of the various aspects and how well the system works.

Implementing a magnetic field controller is certainly a worthwhile project that will find use

in many applications.

6.1 Future Work

Though a lot of effort had been put into this project, there are still some additions that can

be made to the project to further improve the functionality of the controller.

The first major addition would be the full implementation of the controller on the Arduino

board. The code has already been developed to an advanced level with the USB hub, USB

shield and the Keypad shield as shown in the implementation, but this needs to be tested

extensively to ensure proper working. The Arduino has its own PID library which makes the

implementation more straightforward as the needed parameters are already available.

In addition, different tuning methods of the parameters should be explored. Apart from

being cumbersome for higher order system, manual tuning might not give precise values.

Therefore, other tuning methods like the step response with Zeigler-Nichols and Automatic

tuning can be implemented and compared to that of the manual tuning parameters.

A final suggestion for the improvement of this project would be to make the

implementation more generic. This is in the sense that, the COM port communication uses

windows functions and routines such as WriteFile. Therefore, if this controller were to be

used on a non-Windows operating system, then communication would need to be reworked

to use the functions provided by that operating systems.

Page 79: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

78

7. REFERENCES

[1] E. Hughes, Hughes Electrical and Electronic Technology, Essex: Pearson Education Limited, 2002.

[2] S. Bennett, “A Brief History of Automatic Control,” 02 June 1996. [Online]. Available:

http://ieeecss.org/CSM/library/1996/june1996/02-HistoryofAutoCtrl.pdf. [Accessed 27 July

2016].

[3] M. D. M. A. D. G. Verghese, “Dynamic Systems and Control,” Massachusetts Institute of

Technology, 2003. [Online]. Available:

http://dspace.mit.edu/bitstream/handle/1721.1/74611/6-241-fall-2003/contents/lecture-

notes/chapter_6.pdf. [Accessed 07th April 2016].

[4] M. D. M. A. D. G. Verghese, “Dynamic Systems and Control,” Massachusetts Institute of

Technology, 2003. [Online]. Available:

http://dspace.mit.edu/bitstream/handle/1721.1/74611/6-241-fall-2003/contents/lecture-

notes/chapter_1.pdf. [Accessed 07th April 2016].

[5] W. Bolton, Second Edition- Instrumentation and Control Systems, Oxford: Elsevier Ltd, 2015.

[6] W. Bolton, Instrumentation and Control Systems, Oxford: Newnes:Elsevier Ltd, 2004.

[7] Murray, “Caltech- Transfer Functions,” [Online]. Available:

http://www.cds.caltech.edu/~murray/courses/cds101/fa04/caltech/am04_ch6-3nov04.pdf.

[Accessed 08 April 2016].

[8] C. L. a. R. D. H. Phillips, Feedback Control Systems, Englewood Cliffs, NJ:Prentice Hall, 1988.

[9] Electrical4u, “Types of Controllers|Proportional Integral and Derivative Controllers,” 2016.

[Online]. Available: http://www.electrical4u.com/types-of-controllers-proportional-integral-

derivative-controllers/. [Accessed 11th April 2016].

[10] MTU, “Standard PID tuning methods,” 2 February 2012. [Online]. Available:

www.chem.mtu.edu/~tbco/cm416/tuning_methods.pdf. [Accessed 16 April 2016].

[11] Hansha, “Control Theory-zn open loop,” [Online]. Available:

http://home.hit.no/~hansha/documents/control/theory/zn_open_loop_method.pdf. [Accessed

15 April 2016].

[12] M. Brain, “How Microcontrollers Work,” 2016. [Online]. Available:

http://electronics.howstuffworks.com/microcontroller1.htm. [Accessed 2nd May 2016].

[13] M. Banzi, Getting Started with Arduino, USA: Make:Books a division of O'Reilly Media, Inc, 2012.

[14] “Memory,” Arduino, 2016. [Online]. Available: http://www.arduino.cc/en/Tutorial/Memory.

[Accessed 2nd May 2016].

[15] LakeShore CRYOTRONICS, User's Manual Model 425 Gaussmeter, Ohio: Lakeshore, 2014.

[16] National Instruments, “History of GPIB,” 14th August 2012. [Online]. Available:

Page 80: Intelligent Magnetic Field Controller Based on Suitable ......Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform 5 ABSTRACT The use of intelligent controllers

Intelligent Magnetic Field Controller Based on Suitable Microcontroller Platform

79

http://www.ni.com/white-paper/3419/en/. [Accessed 14th August 2016].

[17] Kepco , Operator Manual BIT 4886 Digital interface card with GPIB and RS232 capability, New

York: KEPCO,INC, 2013.

[18] F. Ioannidis, “Intelligent Controller Based on Raspberry PI,” Manchester, 2014.

[19] B. Bequette, “Process Control: Modelling, Design and Simulation,” Prentice Hall Professional,

2003.

[20] “Arduino Products,” Arduino, 2016. [Online]. Available:

http://www.arduino.cc/en/Main/Products. [Accessed 2nd May 2016].

[21] Sparkfun Electronics, “Sparkfun USB host shield,” 2015. [Online]. Available:

https://www.sparkfun.com/products/9947. [Accessed 28th June 2016].

[22] S. Bennett, “A Brief History of Automatic Control,” 02nd June 1996. [Online]. Available:

http://ieeecss.org/CSM/library/1996/june1996/02-HistoryofAutoCtrl.pdf. [Accessed 17th April

2016].

[23] University of Michigan, “Introduction:PID controller design,” [Online]. Available:

http://ctms.engin.umich.edu/CTMS/index.php?example=Introduction&section=ControlPID.

[Accessed 18th April 2016].

[24] “RASPBERRY PI 3 MODEL B,” Raspberry Pi, [Online]. Available:

https://www.raspberrypi.org/products/raspberry-pi-3-model-b/. [Accessed 2nd May 2016].

[25] J. P. A. E.-N. Gene F.Franklin, Feedback Control of Dynamic Systems, Massachusetts: Addison-

Wesley Publishing, 1991.

[26] Wikipedia, “PID controller,” [Online]. Available: https://en.wikipedia.org/wiki/PID_controller.

[Accessed 15th April 2016].

[27] J. D. a. C. Houpis, Feedback control system analysis and synthesis 2nd edition, New York:

McGraw-Hill, 1966.

[28] xanthium enterprises, “Serial Port Programming using Win32 API,” 7th June 2015. [Online].

Available: http://xanthium.in/Serial-Port-Programming-using-Win32-API. [Accessed 4th August

2016].

[29] National Instruments, NI-VISA.

[30] O. Mazurov, “USB host shield library version 2.0,” 22 June 2011. [Online]. Available:

https://www.circuitsathome.com/mcu/usb-host-shield-library-version-2-0-released. [Accessed

10th July 2016].