Development of a Supervisory Control and Data Acquisition Program

advertisement

3.3.5

Development of a Supervisory Control and Data Acquisition Program

The general block diagram shown in Figure 2.6, as previously explained, is used as a mathematical tool; a tool which aids in the design of an appropriate control strategy designed to drive the system response to a given input in accordance with some predetermined performance criteria. Using a mathematical model derived from the block diagram, the response of the actual system can be predicted by using the system transfer function derived from the block diagram to solve for the controlled variable as a function of time. The block diagram is used for this purpose, and as stated before, is not a blueprint which describes in detail every activity or component within the entire control system. The actual structure of a closed-loop control system represented by a block diagram requires a mechanical or electrical infrastructure in order to be implemented. The overall control of the process may require the processing of discrete inputs and outputs, storage and presentation of data, monitoring of levels, sounding of alarms, scheduling events, and numerous other activities. In addition to controlling the continuous process, a computer controller has an ability which a purely analog controller does not have; that is, it is capable of supervising and controlling all related process activities, both discrete and analog, and reporting important system status information to an operator or technician. The computer program presented in Appendix G performs the function of both comparator and compensator. The remaining blocks of the general closed-loop diagram are represented by the CSD hardware. This program and hardware represent the simplest physical form of implementation of the block diagram since no other functions are performed or elements involved other than those seen in the block diagram. These elements alone are capable of implementing closed-loop control of air temperature.

However, as an educational device, the CSD is required to perform additional tasks outside of maintaining a set-point. It must also perform the extraneous tasks mentioned earlier such as data presentation, event scheduling, etc..

Therefore it is necessary to develop a supervisory control and data acquisition

(SCADA) program capable of performing these tasks. This program acts as a master program, and the control program already seen is relegated to the role of a sub-routine to be called by the master SCADA program.

Introduction To LabVIEW

The software application program LabVIEW was developed by the National

Instruments

company for the purpose of turning an ordinary personal computer into a powerful data acquisition device. A personal computer (PC) is capable of performing many of the same functions as the programmable logic controller (PLC) which was discussed earlier. As previously explained, the architecture of a PC and a

PLC are nearly the same. The main difference between the two devices is that the

PLC has been designed specifically to work in an industrial environment and to interface with a multitude of sensors and machinery in order to control a process, whereas the PC has been designed primarily to interact with only a limited number of

73

peripheral devices; devices such as a keyboard or mouse which generate an output from a human operator’s touch. However, with appropriate I/O hardware and software the PC has the potential to be used for process control. Among other things, the National Instruments company creates the hardware and software used to transform a PC into a process control device. When used for process control, the PC is capable of; acquiring measurement data from sensors, performing mathematical operations on the data, storing and retrieving data, making decisions and calculating appropriate control action based on the data, and outputting a control signal which can be used to physically control a process.

Most electrical sensors are not made to be connected directly to a PC, and most

PC’s do not have a dedicated port reserved for sensor input. Also, the typical PC has not been designed to provide the power output needed to control many types of actuators. The special input/output hardware created by National Instruments has been designed to condition sensor input signals so that they may be used by a PC, and likewise to alter the PC’s output signal to a level capable of manipulating an actuator which requires a higher level of input voltage and current than the PC alone is capable of providing.

During the hardware selection phase of the CSD design process, the initial desire was to purchase the National Instruments input/output hardware and LabVIEW software. It was desired to use these products to allow a PC to act as the computer controller for the CSD. Unfortunately, it was discovered that the cost of the necessary I/O hardware offered by National Instruments was beyond the budgetary constraints initially proposed for this project. If this had not been the case, the PC alone could have served as the controller for the CSD, and there would have been no need for the Basic Stamp micro-controller. However, it was determined that the

LabVIEW software, which could be obtained for a reasonable cost, could still be used to benefit the project. The remainder of this section will describe how LabVIEW was used as a partner to the BASIC Stamp micro-controller to create the functionality designed into the CSD.

The LabVIEW Structure

LabVIEW is a development environment designed to allow a programmer to intuitively create computer programs using a software language called “G”. G is a real programming language with capabilities similar to other languages such as C,

Fortran, Basic, etc. The big difference is that G , unlike these other languages, is graphical in nature rather than text based. The logic and data flow through a program written in G is easy to understand because functions and subroutines are in blockdiagram form and connected by “wires” which carry data throughout the program.

LabVIEW is based on the concept of the virtual instrument (VI) . The objective in virtual instrumentation is to use a general purpose computer to mimic a real

74

instrument’s control and display, but with the added versatility that comes with software. Instead of buying a strip-chart-recorder, oscilloscope, and spectrum analyzer, for example, a high-performance digital-to-analog converter and LabVIEW can be used to simulate any or all of these instruments. The VI concept is so fundamental to the way LabVIEW works that the programs written in LabVIEW are called VIs . Simple instruments (sub VIs) are used to build more complex instruments just as subprograms are used to build a more complex main program in a conventional programming language.

The construction of a VI or sub VI consists of two parts, each of which is built on a separate window when using LabVIEW for Windows

. One half of the VI is a graphical user interface which contains input and output controls. These controls imitate familiar input/output devices such as buttons, switches, LED’s, strip-charts, meters, and numerous other instrument controls commonly seen in an industrial or laboratory setting. This virtual control panel acts as the interface between the human operator and the window which makes up the other half of the VI; that is, the program written in the language G. The program written in G may utilize the commonly seen structures and operations which other popular languages offer, including; loops, counters, logic, and arithmetic operations just to name a few. The difference is that these structures and operations are represented graphically as icons and symbols.

When the program is run, the user may input information to the program by clicking a mouse on a control located on the control panel. Depending on the nature of the input, it will be used as data and/or to direct the flow of information through the program. Output from the program may then be sent back to the control panel for display. In this way, the VI front panel acts as an intuitive and easy way for a human to interact with a computer program which requires human input. Figure 3.23 shows a very simple VI which was written to illustrate the appearance and construction of a simple working program. Figure 3.24 shows the virtual control panel which accepts inputs from the operator. The program requires three inputs. Two of the inputs are numbers which are set by either rotating a dial with a mouse or typing in a number to a standard numeric input. The other required input is a switch that can be toggled to control whether the second number is subtracted or added to the first. The inputs are delivered to the actual program contained in the program window (Figure 3.23). Here the program reads the two numbers and the status of the switch. The boxes in the programming window are labeled to show which box corresponds to which control on the front panel. These boxes are considered sources when transmitting data to the front panel for display, or as sinks when receiving user-entered data from the front panel. For this example program, the numbers and a switch status from the front panel are correspondingly passed to the blocks on the programming panel which have the same name, and the results of the calculations performed by the program are passed back to the front panel for display. The numeric inputs on the programming panel are wired to icons which represent the operations of addition and subtraction.

The switch input is wired to a logical operator which sends the results of the addition on to the display if the switch status is “true”. If the switch status is “false”, then the results of the subtraction are sent to the display. All of these functions are

75

encompassed in a While Loop (shown as a surrounding arrow). This causes the program to execute as long as the Boolean value wired to the yellow box is “true”.

Figure 3.25 shows the result of running the program with the switch set to “subtract”.

Figure 3.26 shows the results of running the program with the switch set to “add”.

Figure 3.23

Example “G” Program

76

Figure 3.24

VI Control Panel

Figure 3.25

Program Results—Subtract 2 nd

Number from 1 st

77

Figure 3.26

First and Second Number Added

Although this program has nothing to do with the CSD SCADA program, it does illustrate to the unfamiliar reader how a computer program is built in LabVIEW using the concept of the VI.

The CSD SCADA program which was created using LabVIEW is considerably more involved than the simple example program shown above. Rather than giving a detailed explanation of the intricacies of this program, a brief overview of the primary functions and operation will be presented in words, along with a program flowchart.

The reader who is interested in learning more about the details of the program (or who may wish to modify the program for the purpose of improving the CSD’s performance) may want to view the more detailed program documentation presented in Appendix F.

78

Overview of the CSD Supervisory Control and Data Acquisition (SCADA)

Program

A SCADA program was developed for the purpose of satisfying requirements needed to implement the goals proposed for the CSD, namely:

§

The CSD should be able to demonstrate full PID control

§

The materials to construct the CSD should be affordable

§

The CSD should utilize a graphical user interface which allows students to view and compare past and present data as well as system control and status parameters

§

The CSD should be easy to use; it should be an automated device

The use of a Stamp micro-controller (which is under $100.00) serves as the I/O interface between the PC and the process sensor and actuator. The virtues of the Stamp are; low cost, ability to acquire a digitized temperature measurement from a sensor, and ability to generate a control signal. The vices of the Stamp are its lack of computational power due to fixed point arithmetic and inadequate memory. Also, the arithmetic order of operations (left to right) makes the coding of complicated mathematical expressions very cumbersome. As noted earlier, the editor software which is supplied by the Parallax company for programming the Stamp and displaying data is incapable of presenting data in graphical form. Lastly, changes in control parameters such as PID gains require that the DOS PBASIC program be re-downloaded each time a parameter is changed. The

SCADA program was designed to take advantage of the Stamp’s virtues and compensate for its deficiencies.

LabVIEW has the ability to exchange data with the Stamp through the PC serial port using the RS-232 communication standard. RS-232 is one of the most common standards, and is supported by almost all computer systems and most serial instruments

(such as the BASIC Stamp). LabVIEW has several built in functions which make reading data from, and sending data to the selected PC serial port very easy. Likewise, the Stamp has built in PBASIC instructions which makes reading and writing serial data from any of its general I/O pins very simple. This ability which LabVIEW has to exchange data serially with the Stamp means that the Stamp has the ability to replace the expensive

National Instruments I/O hardware which would have prevented the use of LabVIEW. In turn, this allows the Stamp microcontroller to make use of LabVIEW’s superior computational and memory capacity to perform functions which it cannot. In addition, the graphical language of LabVIEW makes the programming task easier than would have otherwise been the case, even if the Stamp did have the capability to perform complicated arithmetic and display data graphically. Also, the LabVIEW VI control panel is a perfect solution for how to easily create a graphical user interface between the human operator and the CSD hardware. A GUI can easily be created which can display measured temperature, disturbance conditions, PID parameters, controller output, etc. in a very

79

attractive and intuitive manner. Logic is capable of being built into the SCADA program which can completely automate every aspect of the demonstration, thus allowing the

CSD to be easy to learn, operate and use.

With the use of a SCADA program, two computer programs are needed to implement the function of the computer controller. One of these programs is a DOS text-based program written in PBASIC and downloaded to the Stamp. This program is very similar to the example control program shown previously. The other program is the master SCADA program written in the LabVIEW environment using the G language. The Stamp program communicates directly with the Stamp microprocessor and the LabVIEW program communicates directly with the PC’s CPU. Data is sent to and received from the PC serial port via a cable carrying an RS-232 compatible signal. Since each program is controlled by a separate microprocessor, the controller for the CSD actually consists of two separate computers which work as a team to accomplish the control tasks. The

Stamp program performs the duties of; acquiring and digitizing the analog temperature sensor input, sending this data to the PC serial port, collecting the controller output value data from the serial port, and generating a control signal at its output pin which modulates the power output of the light bulb. The LabVIEW SCADA program performs the duties of collecting temperature data from the PC serial port, acquiring administrative control parameters entered by the user, calculating the appropriate controller output for each consecutive sampling interval, sending the calculation results and fan speed (disturbance status) to the PC serial port, displaying data graphically in various formats, and controlling the flow of data in order to perform all extraneous actions needed to automate the demonstration.

Although a lot goes on inside of each program, the amount of data transfer taking place between the programs is relatively small. This is illustrated in Figure 3.27.

80

LABVIEW

SCADA

Program

STAMP

Program

Receives : Controller Output

Fan Speed

Loop Trigger

Data transmitted serially through an RS-232 Link

Sends : Digitized Temperature

Measurement

Sends: Controller Output

Fanspeed

Loop Trigger

Receives: Digitized Temperature

Measurement

Figure 3.27

The SCADA Program is Actually Two Programs

Details of the Supervisory Control And Data Acquisition (SCADA) Program

As mentioned earlier, the control system architecture known as S upervisory C ontrol

A nd D ata A cquisition (SCADA), is a hierarchy. At the bottom of this hierarchy stands the data acquisition features used to take measurements of process variables. The low end of the hierarchy is also where the control signal is generated. In the middle is the data processing functions. Here, data is processed which is passed from both the low level and top level. At the top level are the supervisory features such as the user interface, trending, report generation, and so on.

In industry, control architectures can be broadly categorized as either a DCS , SCADA , or

SLC system. DCS stands for Distributed Control System and is reserved for the largest control systems and utilizes a large network of controllers with many inputs. The

SCADA system takes the medium ground, and can be used for small to medium sized networked control. S ingleL oop C ontrol (SLC) is reserved for the smallest of operations of one or two controlled variables. A Single-Loop Controller can be used to implement

PID and on/off control, but it often lacks the ability to store and present data. The implementation of SLC was discussed in Section 3.3.2. The SLC computer program is

81

shown in Appendix G. By modifying this SLC program just slightly, the SLC program can be used to perform the low level functions of a SCADA architecture hierarchy—that is, data acquisition and control signal generation. This is what is referred to in Figure 3.27

as the Stamp Program . The remainder of this section will be used to describe the details of the computer program written in LabVIEW which was design to perform the functions of middle and top levels of the SCADA architecture.

The SCADA program flowchart is shown in Appendix A. The flow charts which show the structures of the AUTMOMATE THE OPEN-LOOP PROCESS subroutine, and the

AUTOMATE THE CLOSED-LOOP PROCESS subroutine, are also presented.

Program Summary

In words, the primary functions of the SCADA program are; obtain the digitized temperature from the serial port, read control parameters from the front panel; store and display temperature history data, calculate the error and corresponding controller output, store and display controller output history, control demonstration run time, send data to the serial port which indicates a change in fan speed, send controller output data to the serial port, send messages to the control panel notifying when a disturbance has been activated or de-activated and/or closed-loop control has been activated or de-activated, or when open-loop control has been activated or de-activated. In addition, the program allows the user the choice of using averaged or non-averaged temperature data for both display and for use in the controller output calculations. The virtual control-panel which was designed for the CSD is shown in Figure 3.28 below. It represents the humanmachine interface (HMI) between the operator and the CSD. With the use of a projector, the image of the control panel may be projected onto a large screen so that it can be easily seen by a large group of people. The control panel allows the students to see temperature and controller history data, system mode and disturbance status information, and setpoint and system control parameters at a glance.

82

Figure 3.28

CSD Control Panel

83

Figure 3.29

Main Program

The main program which was written in the G language is presented above in Figure

3.29. A floppy disk has been included with this report which will allow the interested reader to see the code more clearly, since it is difficult to see the details of the program in print form. The programming window which is shown in Figure 3.29 shows the main program; however, the program in its entirety is hidden from view in several layers beneath this window. The main program is itself a VI, and each of the colored squares are sub-VIs which may be called by the main VI. Each sub-VI has its own front panel and programming window, just like the main program. However, the front panel for the sub-

VIs in this program do not require any input from the human operator. Instead, the inputs to the sub-VIs are the outputs from other sub-VIs. The front-panel and programming window of each sub-VI can be seen by double clicking on the box representing the sub_VI. A detailed explanation of the purpose and structure of each of the main program’s sub-VIs would be outside of the scope of this report. Many of these sub-VIs are responsible for data manipulation, storage, and administrative tasks which are necessary for program operation, but not directly related to the study of control systems.

For those who may be interested, program documentation has been included in Appendix.

F which gives a brief description of each sub-VI. Also, Appendix F includes views of the main program which cannot be seen in 3.29.

84

Although the details of the SCADA program’s sub-VIs will not be discussed, there is a sub-VI within the program which deserves additional attention. An illustration of this sub-VI is shown below in Figure 3.30.

Figure 3.30

PID Sub-Routine

Figure 3.30 represents the G code for the sub-VI which is entitled “PID Drive”. It is represented as a block in the main program. A picture of this block, along with an illustration of the sub-VI inputs and outputs is given below.

This sub-VI receives seven inputs and delivers one output. The block receives the value for the measured air temperature which has been collected at the serial port and formatted by another sub-VI. When the measured temperature value is received at the serial port, it is an integer. After formatting, the integer is transformed into a floating point number

85

which represents air temperature at a resolution of 1/100 th

of a degree. The PID Drive sub-VI also receives three additional floating point numbers; a set-point, a proportional gain, and a count variable. The other three inputs are Boolean; that is, they can assume the value of either true or false. The Boolean variables are changed by toggling switches on the control panel which turn the integral and derivative contributions of the PID compensator algorithm either on or off, as well as the integral wind-up function which will be described in a moment. All of these inputs are transferred from the main VI to the

PID Drive sub-VI control panel (not shown) and then sent from the front panel to the sub-VI program as shown in Figure 3.30. As soon as all of these data values are received by the PID Drive program, the calculation of the controller output begins. This routine is executed once per sample period.

First, the routine calculates the contribution due to the proportional gain. This calculation is performed in exactly the same way as in the example control program discussed earlier. However, in this case the error is a floating point number, rather than an integer.

The significance of this has already been discussed. Next, the measured temperature is subtracted from the user-defined set-point. Finally, the result of this calculation is multiplied by the selected Proportional gain. The user has a choice of four gain values to select from. These four values were selected in order to yield a system response which would clearly demonstrate the affect that a change in the Proportional gain can have on the response. The result is then ready to be added to the results of the Integral and

Derivative contributions. This procedure can be easily identified in the PID Drive VI.

Next, the Integral contribution is calculated. This procedure takes place in the conditional (true/false) frame which is attached to the green I Gain On/Off box. The small loop which is located on the left side of the True frame is responsible for storing both the current error measurement, and the error measurement from the previous sample.

The two error values are then used to calculate an approximation of the area underneath the error curve over the sampling period of

∆ t. The approximation is calculated using the trapezoidal rule. The trapezoidal rule for approximating an integral can be explained in terms of the figure below for an arbitrary continuous function f(x) (Thomas, Jr. 216).

y

P n-1

P n

P

0

P

1

P

2 y

0 y

1 y

2 y n-1 y n x n-1 b x a x1 x2

Figure 3.31

Sum of areas of trapezoids approximates area under the curve.

86

b

For example, suppose that the definite integral

a f(x)dx is to be evaluated as shown in

Figure. 3.31. The interval of a

≤ x

≤ b can be divided into n subintervals, each of length

∆ x = ( b a )/ n . Then, x

1

= a +

∆ x , x

2

= a + 2

∆ x , . . . , x n-1

= a + (n – 1)

∆ x between x

0

= a and x n

= b.

The integral from a to b is just the sum of the integrals from a to x

1

, from x

1

to x

2

, etc., and finally, the integral from x n-1

to b ; b x

1 x

2 b

∫ a f(x)dx =

∫ a f(x)dx +

∫ x

1 f(x)dx + . . . +

∫ x n-1 f(x)dx

=

∑ n

k = 1 x k-1 x k f(x)dx

The integral over the first subinterval is now approximated by the area of a trapezoid equal to (1/2)[ y

0

+ y

1

]

∆ x ; over the second subinterval by the area of a trapezoid equal to

(1/2)[ y

1

+ y

2

]

∆ x ; and so on.

b

Therefore, the trapezoidal rule is: To estimate the definite integral

∫ a f(x)dx , use the trapezoidal approximation T given by

T = (1/2)[ y

0

+ y

1

]

∆ x + (1/2)[ y

1

+ y

2

]

∆ x + . . .

+ (1/2)[ y n-2

+ y n-1

]

∆ x + (1/2)[ y n-1

+ y n

]

∆ x where, y

0

= f(x

0

) , y

1

= f(x

1

) , . . . , y n-1

= f(x n-1

) , y n

= f(x n

)

When this rule is used to calculate the integral of the error, f(x n error for the n th

) represents the measured

sample. In addition,

∆ x represent the sample time. The sample rate was arbitrarily chosen to be 3 samples per second. Therefore the function f(x n

) can be specified as the error function E(t n

) , and

∆ x replaced with

∆ t which is approximately equal to (1/3) second. The word approximately is used because the duration of the sample period can vary with time throughout the data acquisition process. The reason for

87

this has to do with the fact the Stamp (which continually executes a loop as it acquires each successive temperature measurement) is not a real-time device and therefore performs arithmetic calculations at different speeds. Since each instruction in the loop is performed sequentially, the time which it takes to execute a loop is affected by the time it takes to perform calculations (such as converting a binary temperature into a decimal temperature). The actual variation in the sample time was estimated to be on the order of a few milliseconds. The CSD process involves heat transfer, and therefore the controlled variable of temperature changes slowly with time. That being the case, the approximation of

∆ t as a constant was assumed. For a fast process, this assumption may not be advisable. The exact affect of this variation in sample time on the control of the process is estimated to be small. However, for future students who may wish to try to optimize the performance of the CSD, additional hardware (an external timer) can be added which will ensure that the program loop will execute in equal intervals of time.

For more information on where to purchase the required hardware, contact the Parallax

Company’s web site.

Let’s return now to the explanation of the routine used to calculate the integral of the error. The current error is added to the previous error and the sum is multiplied by the numbers 0.33 and 0.5. The number 0.33 represents the sample time

∆ t, and 0.5 is the ½ used in the trapezoidal area equation.

Next, the result of this calculation is multiplied by the term 1/

ττ

I

where

ττ

I is called the

‘reset time’ in seconds. Reset time is the time required for the integral contribution of the

PI controller to duplicate the effect of the proportional contribution acting on a step input.

The Integral Gain is equivalent to the proportional gain multiplied by 1/

ττ

I

. This relationship is easily seen in the equation below which again, represents the mathematical expression of all three terms of the PID compensator.

m(t) = K e(t) + c

τ

1

I

0 t

e ( t ) dt +

τ

d de(t) dt

+ m s

The 1/

ττ

I

value can be seen in the PID Drive sub-VI to be equal to a value of either 1 or

1/20, depending on whether or not the wind-up button is pushed. It is obvious that the

Integral Gain is dependent on the Proportional gain, since the integral gain is the product of the Proportional gain and 1/

ττ

I

. Since there are four different proportional gain values to choose from, as well as two choices for the 1/

ττ

I

term, this means that there are eight different combinations to choose from in selecting the PI compensator (see Table 3.3).

These numbers were chosen by experimenting with the CSD response to a step input until results were achieved which clearly represented the type of response required to illustrate

88

some particular principle of control system theory. Any student who may have an interest in tuning the CSD response using gains which are unavailable as current options may do so by changing the gain values on the PID Drive sub-VI to the desired value(s).

Table 3.3 Available Gain Combinations for the CSD PI Compensator

Proportional Gain Options

Low 10

Medium 50

High 150

M-Stable 1000

1/

ττ

I

High 1

Low 1/20

Integral Gain Options

0.5 10

2.5 50

7.5 150

50 1000

After the trapezoidal approximation of the integral of the error has been calculated and multiplied by the integral gain, the result is stored in memory. The procedure is then repeated for the next sample period and the resulting sum is added to the previous sum.

In this way, a ‘running sum’ is established which updates the product of the integral gain and integral of the error for each successive sample period. Once this product has been calculated for a particular sample, the result is then added to the Proportional contribution

( if PI or PID control is being utilized). If integral control is not being used, the routine simply sends a zero to be added to either the P or PD contribution, whatever the case may be. The variable Count is used to reset the integral of the error to zero after each demonstration run. The routine used for the calculation of the compensator Integral contribution makes no provision to prevent integral wind-up . This is a phenomenon whereby the controller output to the actuator saturates so that further increasing the magnitude of the running sum has no effect. Nevertheless, if there is still a non-zero error in the loop, the magnitude of integrator running sum will continue to increase as the integral increases for each successive sample (or time step). When conditions change, such that the error eventually changes sign, the large magnitude which the integral term will have reached prevents the actuator from responding until the integral term has

‘unwound’. At best, this introduces long time delays, which has a destabilizing effect.

This problem can potentially exist in both analog and digital controllers, but with digital controllers an additional problem can occur whereby the accumulating integral term (if unchecked) may overflow the computer’s memory register and cause the controller

89

output to swing suddenly from full positive to full negative (or vice-versa). When using digital controller which has a small memory storage register (such as the BASIC Stamp), the overflow of the register due to wind-up is a likely possibility if no programming code is implemented to prevent it. In this case, no provisions where taken to prevent wind-up.

In fact, it is one of the concepts which the CSD has been designed to demonstrate. By pushing the wind-up button on the front panel so that it reads ‘ ON’ , a large integral gain is used to calculate the compensator integral term. No code has been created to limit the value of the running sum, although code has been created to limit the value of the variable DRIVE to be between 0 and 100%. The memory register of the PC (where

LabVIEW stores data) has a much larger number storage capacity than the BASIC

Stamp. The PC memory register is capable of storing floating point numbers having a magnitude as large as 1.7x10

308

, whereas the Stamp can store integer numbers only, and having a magnitude of no greater than 65,536. With the wind-up button turned to ‘ ON’ , the integral sum in the PC register gets very large in a short time, although the PC register is never in any danger of overflowing, since it has such a large capacity. With a large value for the integral term accumulating in the register, and with the controller output value of DRIVE being limited, the conditions for integral wind-up are realized. The response characteristics of the wind-up effect will be discussed in a subsequent section.

The final operation which the PID Drive sub-VI performs is the calculation of the controller output contribution which is due to compensator’s Derivative term. The routine uses a simple numerical algorithm in order to calculate the derivative of the error.

The algorithm is an approximation of the limit process used in the analytical definition of the derivative. Given the function f(x) , the derivative of f(x) is defined as

(Thomas, Jr. 30) , f '(x) = limit (

δ x => 0) {[ f(x+

δ x) - f(x) ] /

δ x }.

The approximation of the derivative of f(x) can be expressed as, f '(x)

[ f(x+h ) - f(x) ] / h Equation (3.11) or as, f '(x)

[ f(x) - f(x-h) ] / h . Equation (3.12)

Where h is a small interval in x . Equation (3.12) is the form which is used in the PID

Drive routine to calculate the approximate derivative of the error as a function of time.

This form is known as the ‘backward difference’ method for the approximation of a derivative. Alternately, equation (3.11) represents the ‘forward difference’ method of

90

approximation. In this case, h =

∆ t which represents the sampling period, and f(t +

∆ t) represents the value of the measured temperature at a time in the future. Since the error value cannot be known until it is measured, the forward difference method cannot be used here. The forward difference method is useful for finding the derivative of a mathematical function, but is useless for determining the derivative of a measured value such as error. On the other hand, the backward difference method requires knowledge of the current measured temperature f(t), and the value of the error measurement obtained from the previous sample f(t-

∆ t).

Since both f(t) and f(t-

∆ t) are readily available, the backward difference method is a convenient way to calculate the derivative of the error.

Therefore, this was the method used to calculate the Derivative term contribution of the controller’s output. The G programming code used to implement the backward difference method is shown in Figure 3.30. It is the portion of code located in the conditional frame which is wired to the green D GAIN ON/OFF switch box. This routine subtracts the previous temperature measurement from the current one and divides the difference by the sampling period.

The quotient is then multiplied by the derivative gain, which is equivalent to the product of the proportional gain K c

and the ‘derivative action time’,

τ

d in seconds. The derivative action time is the time by which the output of a PD controller (to a ramp input) is advanced compared with the P term acting alone. Once the derivative contribution for a given sampling period has been calculated, it is then added to the proportional contribution and the integral contribution when integral control has been activated. The resulting sum is then added to the bias value. This value has been selected to be 50 so that the controller output will be 50% when there is zero error. Setting the bias to the mid-point of the actuator’s range allows the actuator to respond to both positive and negative error with equal “travel”. The total sum of (PID + Bias) is then checked to determine whether or not it is a positive number and less than 100(%). If the sum is negative, it is re-assigned the lowest possible controller output value of zero. If the sum is greater than 100, it is re-assigned the highest possible controller output value of 100.

Any sum greater than zero and less than 100 will then have the fractional portion rounded to the nearest integer, and added to the integer portion of the total sum. The result is then sent to the serial port so that it may be collected by the Stamp and stored in the variable

Drive . This value of Drive is what determines the Stamp controller’s output as discussed in section 3.3.3.

As mentioned earlier, the overall computer control program actually consists of two separate programs which work together. The details of the SCADA program have just been discussed. The other computer program in the loop is the Stamp program which is written in the PBASIC language and downloaded to the Stamp’s EEPROM memory.

This program can be found in Appendix H., and is very similar to the example control program discussed earlier. With the background already given, the operation of this program may be easily understood without the need for further discussion here.

The next section will present the procedures for the operation of the CSD, and illustrations of the output of the device as it is run under several different configurations.

91

3.3.6

Setting-Up and Running the Control System Demonstrator

Establishing Communication Between the Stamp and the PC

The setup of the CSD is very simple. A custom cable was constructed which allows the Stamp to be connected directly to the PC’s serial port. The cable is multi-wire and consists of three individual wires surrounded by shielding foil. Each of the three wires is soldered to the appropriate pin of a female DB-9 connector (see Figure 3.32)

1 2 3

Green Wire

22k

White Wire

4

Stamp Output Pin 10

5 black wire

Stamp Vss

Stamp Input Pin 8

Figure 3.32

Serial Cable Construction

The DB-9 connector is then connected to the COM1 (must be COM1) serial port on the back of the PC. The wires on other end of the 3ft cable were stripped, and plugged into the Stamp carrier board input blocks which correspond to the input and output pins specified for use in the PBASIC final control program. Once this was done, both programs were ready to be run.

Each program is under the control of its own independent master loop. This requires the two program loops to be synchronized. For example, when one program sends data, the other must be waiting to collect data and vice versa (see Figure 3.33 below).

92

Overall

Program

Loop

Stamp Program Loop data exchange

SCADA Program Loop

Figure 3.33

Overall Program Loop Structure

The synchronization is achieved by placing a conditional statement in the PBASIC program that halts execution until it receives a signal from the SCADA program that it is ready to receive data. Likewise, the SCADA program continuously reads the serial port for data until something other than 0 is read. A zero at the serial port means that no data has yet been sent by the Stamp. When data (the temperature measurement) is read at the serial port by the SCADA program, it is then processed and information about the system is sent back to the serial port. While the SCADA program is performing its calculations, the Stamp program waits on data to be sent to the serial port. The Stamp program halts execution until new data is detected at the serial port, and then begins a new loop to start the whole process over again.

When the programs are first started it is necessary to run the SCADA program first, and then reset the PBASIC program by pushing the reset button on the Stamp carrier board.

The reason for this is because the PBASIC program will first measure a temperature, send it to the serial port and then wait for a reply from the SCADA program before continuing on. When the SCADA program is first run, it initializes the serial port with a zero and then begins to read the port continuously until a non-zero value is read.

93

If the Stamp program were to be run first, the temperature measurement would be sent to the serial port, and when the SCADA program was run next, it would overwrite the temperature data sitting in the serial port with a zero upon initialization. Then the

SCADA program would read the port. But since the port was just overwritten, the

SCADA program would read a zero. Meanwhile, the Stamp is still waiting for a reply after having already sent its first temperature measurement. The program will wait indefinitely until it receives a reply from the SCADA program. But the SCADA program will never reply because the Stamp program isn’t sending data, and the serial port continues to be read as zero. When this happens, both programs are locked in their own respective ‘holding patterns’, and the program appears to crash. To avoid this situation, it is absolutely necessary to run the SCADA program first, then push the reset button on the Stamp carrier board which resets the control program that is stored in its EEPROM memory. This procedure is analogous to ‘priming the pump’. Once the first data exchange takes place between the programs, synchronization is established and operation is automatic without any further input needed from the user. If the SCADA program is stopped for any reason, the same procedure applies for re-starting the program.

After starting the programs, the first objective was to determine the extent of the variation in the sampling period. Referring again to Figure 3.33, each individual loop takes a certain amount of time to execute. The overall loop time is the sum of the individual loop times, and is equivalent to the sampling time which was referred to as

∆ t in the discussion of the numerical method used to implement Integral and Derivative control. Ideally, the time required for each individual program loop to execute should be constant. When this is the case, the execution time for the overall loop will be constant; the overall loop time being equivalent to the constant

∆ t used in the P and D contribution calculations. However, as mentioned earlier, the loop time for the Stamp program is not constant. The loop time for the SCADA program can be made to be constant, and is done by inserting a pause statement within the program which uses the PC’s internal clock to govern the loop execution. The use of the pause statement ensures that the program continuously executes at equal intervals of time. However, the variability in the

Stamp loop execution time results in some variability of the overall sampling time,

∆ t.

Some temporary code was inserted into the SCADA program in order to measure the variation in

∆ t over a period of approximately two minutes. The results are shown as a histogram in both tabular (Table 3.4) and in graphical form (Figure 3.34).

Table 3.4. Relative Frequency of the Variation in the Sampling Time,

∆ t

∆ t millisec Frequency

330 0

331

332

40

18

333

334

335

336

243

20

39

0

94

300

250

200

150

100

50

0

Histogram of the Variation in the Sample

Time

330 331 332 333 334 335 336 More time (ms) Bin

Figure 3.34

Variation of Sampling Time Over a Two Minute Period

Table 3.4 and Figure 3.34 show the measurement results for 360 samples, collected over a time period of approximately two minutes. From the results, it can be shown that the sample time over a two minute time period was equal to 0.333 seconds approximately

68% of the time. The other 32% of the time, the sampling period was not equal to 0.333

seconds. Once again, the sampling period used in the calculation for the Derivative and

Integral terms of the compensator algorithm was assumed to be a constant of 0.333

seconds. Since the sampling time is equal to this value only 68% of the time, it may appear that the assumption of a constant sampling time is not justified. However, the maximum deviation from the assumed constant for

∆ t is a mere 2 milliseconds. This data supports the previous speculation that the variation in

∆ t is insignificant (at least for a slow process variable such as temperature), and therefore the sampling time can be treated as a constant in the PID algorithm calculations for the determination of the controller output.

95

Download