27
YOKOGAWA TRAINING Section 7. Calculation Functions SECTION 7 CS3000 CALCULATION FUNCTIONS CONTENTS 7. CALCULATION FUNCTIONS .............................................................................. 2 7.1 Calculation Modules .......................................................................................... 2 7.1.1 Calculation Block List................................................................................... 2 7.1.2 Common Specifications ................................................................................ 4 7.1.3 Numerical Calculation Blocks ...................................................................... 5 7.1.4 Arithmetic Function Blocks .......................................................................... 7 7.1.5 Auxiliary Calculation Blocks ...................................................................... 13 7.2 General Purpose Calculations (CALCU) ...................................................... 17 7.2.1 General ........................................................................................................ 17 7.2.2 Program Basics............................................................................................ 18 7.2.3 Declaring and Using Variables ................................................................... 19 7.2.4 Operators ..................................................................................................... 22 7.2.5 Intrinsic Functions ....................................................................................... 23 7.2.6 Control Statements ...................................................................................... 24 TE 33AU1C3-01 7-1

S7 Calculation Functions

Embed Size (px)

Citation preview

Page 1: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

SECTION 7

CS3000

CALCULATION FUNCTIONS

CONTENTS

7. CALCULATION FUNCTIONS ..............................................................................2

7.1 Calculation Modules..........................................................................................2 7.1.1 Calculation Block List...................................................................................2 7.1.2 Common Specifications ................................................................................4 7.1.3 Numerical Calculation Blocks ......................................................................5 7.1.4 Arithmetic Function Blocks ..........................................................................7 7.1.5 Auxiliary Calculation Blocks ......................................................................13

7.2 General Purpose Calculations (CALCU) ......................................................17 7.2.1 General ........................................................................................................17 7.2.2 Program Basics............................................................................................18 7.2.3 Declaring and Using Variables ...................................................................19 7.2.4 Operators .....................................................................................................22 7.2.5 Intrinsic Functions.......................................................................................23 7.2.6 Control Statements ......................................................................................24

TE 33AU1C3-01 7-1

Page 2: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

7. Calculation Functions

7.1 Calculation Modules

7.1.1 Calculation Block List Block Type Model Name Block Name

ADD Addition MUL Multiplication DIV Division

Numerical Calculation

AVE Averaging SQRT Square Root EXP Exponential LAG First-order Lag INTEG Integration LD Derivative RAMP Ramp LDLAG Lead/Lag DLAY Dead Time DLAY-C Dead Time Compensation AVE-M Moving Average AVE-C Cumulative Average FUNC-VAR Variable line-segment function TPCFL Temp & Press Compensation ASTM1 Oil Temp Correction: Old JIS

Analog Calculation

ASTM2 Oil Temp Correction: New JIS AND Logic And OR Logic Or NOT Negation SRS1-S Latch - Set dominant, 1 Output SRS1-R Latch - Reset dominant, 1 Output SRS2-S Latch - Set dominant, 2 Output SRS2-R Latch - Reset dominant, 2 Output WOUT Wipeout OND In-delay timer OFFD Off-delay timer TON Rise trigger TOFF Fall trigger GT Greater than GE Greater than or equal to EQ Equal BAND Bitwise AND BOR Bitwise OR

Logical Operation (1)

BNOT Bitwise NOT

TE 33AU1C3-01 7-2

Page 3: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

CALCU General Purpose Calculation General Purpose

Calculation CALCU-C General Purpose calculation with Character String I/O Trend (2) TR-SS Snapshot Trend

SW-33 3-pole 3-position Selector Switch SW-91 1-pole 9-position Selector Switch DSW-16 Selector Switch for 16-constant Data DSW-16C Selector Switch for 16-constant Character Data DSET Data Set DSET-PVI Data Set with Input Indicator BDSET-1L 1-batch data set block BDSET-1C 1-batch character data set BDSET-2L 2-batch data set block BDSET-2C 2-batch character data set BDA-L Batch data acquisition BDA-C Batch character data acquisition

Auxiliary

ADL Inter-station data link block Note 1: Logical Operation Blocks are identical to Logic Chart elements and are discussed in the sequence section of the manual (8.3). As a rule, logic is not performed using these blocks on a control drawing as they use far more processing power than logic elements in a logic chart. Note 2: The trend block (TR-SS) is not a configurable block as it is set up automatically by the system to handle high speed trend data in the HIS. It is invisible to the user.

Reference: Reference Manual, Section D3

TE 33AU1C3-01 7-3

Page 4: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

7.1.2 Common Specifications The architecture of the calculation block is shown as follows:

As can be seen from the diagram, the I/O terminals link to the data items as follows:

Terminal Data Item IN RV Q01 RV1 Qn RVn OUT CPV J01 CPV1 Jn CPVn

• I/O Signal Processing: Input signal processing is usually only available on the IN terminal, and not the Qn terminals. Therefore, process inputs can only be connected to the IN terminal. To connect process inputs to the Qn terminals, they must be connected via a PVI block. The IN terminal does have a CAL function. • Alarm Processing: Calculations have a very limited range of alarm functions. There is no Hi/Lo alarm processing, and only failure type alarms, such as IOP, and OOP are available. • Mode Status: Calculation blocks do not have a Manual or Cascade function, only Aut or O/S. • Block Timing: As with Sequences, Calculation blocks can be configured for periodic or one-shot execution. If they are configured as one-shot, then they must be activated by a sequence or logic chart.

TE 33AU1C3-01 7-4

Page 5: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

7.1.3 Numerical Calculation Blocks The only real difference between a numerical and an arithmetic calculation block is the data type used. Numerical block data is double precision floating point, and Arithmetic block data is single precision floating point. • Numerical Blocks (ADD, MUL, DIV)

• These three function blocks have the same structure.

• The second input has a bias (BS1) and gain (GN1) on it which are configurable through the tuning panel on the operator display. This enables the second input range to be changed, which can be useful in certain applications. For example:

1. To subtract two inputs, since there is no subtractor module, use

an ADD module and set the gain (GN1) to -1. This makes the second input negative, before adding it to the first input.

2. If the second input is to be a trim on the first input, then the input may have to be converted from 0 - 100% to -50 to 50%. This can be done by setting the bias (BS1) to -50.

TE 33AU1C3-01 7-5

Page 6: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

• Average Block (AVE)

The average block has up to 8 inputs. Specify in the builder the number of inputs (1 - 8) and the block adds the inputs and divides by the number of inputs.

TE 33AU1C3-01 7-6

Page 7: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

7.1.4 Arithmetic Function Blocks The general layout for an arithmetic block is as follows:

• Square Root (SQRT)

RVGAINCPV ×= • Exponential (EXP)

CPV = GAIN x eRV • First-order Lag (LAG)

TiSRVGAINCPV+

×=1

• Derivative Function (LD)

A derivative (Lead) block calculates the rate of change of the input. When the rate of change of the input drops to zero, the output of the LD block decays to zero at a rate set by the D data item in the tuning panel.

• Lead/Lag Function (LDLAG)

This block is a combination of the Lag block and the lead (LD) block. In practice this means that the output reacts initially to the rate of change in the input (Derivative action), and then moves equal the value of the input (Lag action).

TE 33AU1C3-01 7-7

Page 8: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

• Dead Time Function (DLAY)

The dead time block simulates the dead time of a process system. It also combines a LAG block to smooth the action of the output when it jumps to the input value. The parameters

Parameters: SMPL = Sampling interval (seconds) (set in tuning panel) m = number of sampling points (1-60) (set in builder) I = Lag time RST = reset switch (set to 1 to reset) L = SMPL x (m-1)

• Dead Time Compensation Function (DLAY-C) The dead time compensation block functions in the opposite way to the delay simulator block (DLAY), and is used as part of a PID control loop to compensate for dead time.

Parameters are the same as for the DLAY block.

TE 33AU1C3-01 7-8

Page 9: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

• Integration Block (INTEG)

This block totalises the input (RV). It is used for such applications as totalising flowrates for batch applications. It has a switch to allow a sequence to reset and start it.

Switch function:

SW value Block status 0 Reset and run (sets to 1) 1 Run 2 Stop

Configuration Parameters:

GAIN - sets the scale of the output of the block

I - the time scale of the totalisation in seconds/per time unit. For example, if the flowrate is l/s, then I = 1, if the flowrate is l/min, then I = 60. If the flowrate is l/hr, then I=3600.

• Ramp Function (RAMP)

The ramp block ramps the output upto the input at a given rate. It is usually used in applications where a step change is made to the input, and the output ramps up to it to provide a ramped setpoint to a controller.

Change in Output = (CPV span) / STEP Where: STEP (seconds) is the time for the output to ramp to the span of the

block That is, the output increments by an amount equal to the span of the block divided by the STEP value (set in the tuning panel). Therefore, the larger the STEP value, the slower the ramp.

TE 33AU1C3-01 7-9

Page 10: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

• Moving Average Block (AVE-M)

The Moving Average block samples the input at a given rate and holds the sampled data in a circular buffer of a given size. These samples are added and divided by the number of samples:

mGAINCPV mΧ++Χ+Χ

∗=.........21

Configuration Parameters: NUM = number of sampling points (1-60) SMPL = sample period (sec) PREV = last data value in the input buffer (Xm) RST = Reset Switch. When set to 1, all values in the buffer (and therefore

the output) are set to the current input value, and RST returns to 0. The main application for this function is to look for trends in process inputs that are too noisy to determine real process changes from the raw data. Such applications include leak detection in a furnace or long tailings pipe in which a flow meter at each end of the line measures the flow. The difference between the two flows (which should be zero) is then fed into a Moving Average block and if the average value is seen to be moving in a direction, then there is a leak.

• Cumulative Average Block (AVE-C)

The cumulative average block works like the integrator (INTEG), except that the output is the totalised value divided by the number of samples. Unlike the moving average block there is no limit to the number of samples, which keep increasing until the block is reset. Therefore, the longer it runs for, the less effect an input will have on the output.

nRV

GAINCPVn∑•= 1

where n is the number of samples.

It has a switch to allow a sequence to reset and start it. Switch function:

SW value Block status 0 Reset and run (sets to 1) 1 Run 2 Stop

TE 33AU1C3-01 7-10

Page 11: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

• Variable Line-Segment Function (FUNC-VAR)

This is an X,Y graph in which the input (RV) is the X-axis and the output (CPV) is the Y-axis. There are upto 14 line segments, and the X,Y data is entered through the tuning panel. The block interpolates a straight line between each point. Configuration values:

SECT Number of segments in the curve (1-14) X01 - X15 X-axis (input) data Y01 - Y15 Y-axis (output) data

The X values can be positive or negative, but each successive X value must be greater than the previous value. There is no such restriction on the Y values. The number of segments (SECT) is one less than the number of X,Y values used. A typical application for this function is steam table curves.

Y08Y09

Y07

Y06

Y05

Y04

Y03

Y02

Y01

X09 X07 X08 X05 X06 X04 X03 X02 X01

TE 33AU1C3-01 7-11

Page 12: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

• Temperature and Pressure Compensation of Gas Flow (TPCFL)

This function block uses the ideal gas equation to correct a flow rate based on its temperature and pressure. Because it uses the ideal gas equation, this block is not accurate at extremely high pressures or low temperatures.

15.27315.273

325.101325.101

++

•++

∗=TT

PPFiFo b

b

where: Fo = corrected flowrate Fi = measured flowrate P = measured pressure (kPa) Pb = reference pressure (kPa - see below for other units) T = measured temperature (oC) Tb = reference temperature (oC - see below for other units) Note: Pb and Tb are configurable parameters through the tuning page. Builder Setup Parameters:

Pressure and Temperature Correction Pressure Correction

Corrective Computation

Temperature Correction Deg C Temperature Units Deg F (must be manually entered as F) Pa KPa Mpa

Pressure Units

Kgf/cm2 (must be manually enteredas KGF/CM2) • Oil Flow temperature Correction Blocks (ASTM1 and ASTM2)

These blocks use the old and new Japanese standards for calculating a corrected oil flow based on process temperature and SG of the oil. Configurable Parameters: Type of Oil Crude, Fuel Oil, Lubricant (ASTM2 only) Temperature Units DegC (or DegF by entering F manually) DEN SG of the Oil at 15oC (in tuning panel)

TE 33AU1C3-01 7-12

Page 13: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

7.1.5 Auxiliary Calculation Blocks In addition to calculation functions Switches and Data units are also provided. • 3-Pole, 3-Position Selector Switch (SW-33)

If SW = 1 S11 is switched through to S10 S21 is switched through to S20 S31 is switched through to S30 If SW = 2 S12 is switched through to S10 S22 is switched through to S20 S32 is switched through to S30 If SW = 3 S13 is switched through to S10 S23 is switched through to S20 S33 is switched through to S30

SW can be set by a sequence or logic chart. If it is set to 0, then the output values are not updated.

• 1-Pole, 9-Position Selector Switch (SW-91)

If SW = 1 S11 is switched through to S10 If SW = 2 S12 is switched through to S10 Etc

SW can be set by a sequence or logic chart. If it is set to 0, then the output values are not updated.

TE 33AU1C3-01 7-13

Page 14: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

• Selector Switch Block for 16 Constant Data (DSW-16, DSW-16C)

Data items are configurable through the tuning panel and are: SD01 to SD16 i.e., if SW=1, then CPV = SD01 etc.

SW can be set by a sequence or logic chart. If it is set to 0, then the output values are not updated. The DSW-16 hold numerical data, while the DSW-16C holds character data.

• Data Set Block (DSET)

A data set block is similar to a manual loader, except that the SV is loaded into the output terminal. It has no other function.

• Data Set Block with Process Variable Indicator (DSET-PVI)

This is similar to an MLD-PVI with a PV connected to the IN terminal and the SV connected to the OUT terminal.

TE 33AU1C3-01 7-14

Page 15: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

• Batch Data Set Blocks (BDSET-1L/C, BDSET-2L/C)

A Batch data set block is similar to a DSW-16, in that it has 16 data constants (DT01-DT16) and a switch (SW). However, whereas a DSW-16 has one output, a BDSET has 16 outputs, and when the SW=1, then the constants are loaded into their outputs simultaneously as a one-shot action.

BDSET-1L/C BDSET-2L/C

Configuration Data:

DT01 - DT16 Current Batch Data NX01 - NX16 Next Batch Data (BDSET-2 only) SW 0 - 3 (see below) DH01-DH16 High limit on outputs DL01-DL16 Low limit on outputs

Operation of the Batch Data Set Blocks:

n=0 Set all batch data (DTxx) to 0 n=1-16 Set that batch value (DTn) to its output

tag.ACT.n

n=17 Set all batch data to their outputs 0 → 1 Put BDSET into wait mode 1 → 2 Set all batch data to their outputs (sets SW = 3)

tag.SW. (BDSET-1)

3 Data setting completed → 0 Set Next data to Current data (sets SW = 1) 1 → 2 Set all batch data to their outputs (sets SW = 3)

Or

tag.SW. (BDSET-2) NXBS ≠ 0 3 Data setting completed

TE 33AU1C3-01 7-15

Page 16: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

• Batch Data Acquisition Block (BDA-L/C)

The batch data block is structured in the same way as a BDSET-1 block, except that when the SW is set on data is acquired through the terminals rather than set.

tag.SW.

0 1-16 17

No data is acquired Acquire data for that input Acquire data for all inputs

Or tag.ACT.

0 1-16 17

Set all acquired data to 0 Acquire data for that input Acquire data for all inputs

TE 33AU1C3-01 7-16

Page 17: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

7.2 General Purpose Calculations (CALCU)

7.2.1 General A general purpose calculation block allows a user to write their own functions into a single function block. This allows for a complex series of functions to be performed in one block, and can be copied and used as many times as is required. The language used for the CALCUs is a subset of SEBOL, and is similar to FORTRAN and C. It uses arithmetic operators and conditional statements.

As can be seen from the above diagram, a CALCU has the following I/O:

Terminal Description Corresponding Data Item IN First input RV Q01 - Q07 Inputs 2 - 8 RV1 - RV7 OUT First Output CPV J01 - J03 Outputs 2 - 4 CPV1 - CPV7

Note that a CALCU-C reads and writes character data through the I/O terminals. The CALCU has 8 internal data items that are accessible from the tuning panel on the operator display. These can be used as configuration data for calculations, and they can be written to for display purposes. They are: P01 to P08.

Reference: Reference Manual, Section D3.48

TE 33AU1C3-01 7-17

Page 18: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

7.2.2 Program Basics A calculation has the following structure:

program

Declaration statements Executable statements

end

• The "program" and the "end" are optional. • Executable statements can be split across several lines using "\" or "//" at the end

of each line (except the last line). • Comments can be included in the program using an "*" if the comment takes the

whole line, or "!" if the comment is on the same line as a statement. • The maximum number of statements allowable in a CALCU is 20. The

following are not counted as statements: program, end, else, else if, case, otherwise, end switch, labels, comments, declarations, empty lines. A statement taking multiple lines is counted as one statement.

• If the statements are too large, even if they are within the 20 statement limit, a

capacity overflow error can occur if there is too much to process within the scan of the block. This can be avoided if there is an average of about four items per statement or less.

TE 33AU1C3-01 7-18

Page 19: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

7.2.3 Declaring and Using Variables • Data Types: Data Type Declaration Bits Character String char*n 8*n

Integer Integer 16 Integer Long Integer Long 32 Single Precision Floating Point Float 32

Numerical

Real Double Precision Floating Point Double 64

• I/O Variables

A program can use data that has been connected to the terminals of the CALCU, or reference tagnames directly. In both cases, the program automatically detects the data type of the input or output and so declarations are not required.

♦ If terminal connections are used then the program references RV, RV1 -

RV7 and writes to CPV, CPV1 - CPV3. For example:

CPV = RV + RV1 - RV2 This program statement adds the first two inputs to the CALCU and subtracts the third input. The result is assigned to the first output.

♦ Tags can be addressed directly, rather than through I/O connections, using

the tag.item format. For example:

FIC100.SV = FI200.PV + FI300.PV This program statement adds the two flowrates (FI200 and FI300) together and assigns the result to the Setpoint (SV) of FIC100.

♦ Sequence data can also be referenced using the tag.item.value format. The

expression on each side of the "=" must be enclosed with "{…..}". For example:

{FIC100.MODE.MAN} = {PI100.ALRM.HI} This program statement forces the controller FIC100 into manual if the indicator, PI100 is in high alarm.

TE 33AU1C3-01 7-19

Page 20: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

• Local Variables

A local variable is a variable that is declared in a function block. It is local to that block only and is not available for display or reading by another block. It is also not remembered from scan to scan. Local variables are usually used for splitting equations into smaller, easier to read statements. Example: FLOW = FI100.PV + FI200.PV CPV = FLOW / PI100.PV * TI100.PV A local variable should be declared at the beginning of the program. The syntax for this is:

Data Type Variable Name1, Variable Name2, ….. Example:

Double FLOW, INFLOW, OUTFLOW These three local variables are declared as double precision real numbers. See the previous page for the different data type declarations. If the variable is not declared, then its data type will be assumed as follows:

I Integer L Long Integer F Single-Precision Floating Point number C Character String Others Double-Precision Floating Point Number

TE 33AU1C3-01 7-20

Page 21: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

• Alias Definition (alias)

An alias allows the substitution of an I/O value, tagname or sequence reference with a character string. This character string can then be used throughout the program. This has a couple of applications. It allows for the use of simplified and more readable expressions. More importantly, some tags cannot be used directly in a program as they are mis-interpreted by the compiler. These are tags with "-" in them (will be interpreted as a subtraction), and numbers at the beginning of a tagname. For example:

FIC-100.PV 2PI1000.PV

Both of these tags cannot be used directly in a program and must first be assigned to an alias. The format for an alias is as follows:

alias <alias name> <tag.item or connection item> Type Format Example Input Variable RV, RV1,…., RV7 alias FLOW RV1 Output Variable CPV, CPV1,…., CPV3 alias TOTFLOW CPV Data Connection tag.item alias FLOW FI100.PV

tag.item.value alias SEQ1 {FIC100.MODE.AUT} Sequence Connection tag.item=value (for data status)

Alias SEQ2 {PI100.PV=CAL}

• Character String Substitution (#define)

This function works in a similar way to the alias, except that it is specifically for text substitution. The format is:

#define <identifier> <character string> example:

#define OPEN 2 VALVE1.CSV = OPEN

Expressions can be represented by a single term using the #define. For example:

#define CFLOW (FLOW - 33.0) FLOW = FI100.PV CPV = CFLOW / P02

Note the use of brackets. These are optional, but will have an effect on the way in which the calculation is executed.

TE 33AU1C3-01 7-21

Page 22: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

7.2.4 Operators

Type Operators Description Binomial + Addition - Subtraction * Multiplication / Division mod remainder Unary + Positive

Arithm

etic

- Negative Relational < Less than > Greater than <= Less than or equal to >= Greater than or equal to Equality = = Equal to

Com

parison

<> Not equal to Binary logic and and or or eor Exclusive OR Unary logic

Logical not Negation & Bitwise AND | Bitwise OR ^ Bitwise exclusive OR

Bitw

ise logic

- 1's operator (invert all the bits) << Left bit shift >> Right bit shift <@ Left cyclic shift

Bitw

ise shift

>@ Right cyclic shift

TE 33AU1C3-01 7-22

Page 23: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

7.2.5 Intrinsic Functions

Function Description Examples labs(x) dabs(x)

Calculate absolute value (integer value) (real number)

CPV = dabs(RV)

int(x) Integer by truncating digits after decimal point CPV = int(RV) lmax(x1,x2,….x32) dmax(x1,x2,….x32) lmin(x1,x2,….x32) dmin(x1,x2,….x32)

maximum value (integer values) (real numbers) minimum value (integer values) (real numbers)

CPV = dmax(RV,RV1,34,FI100.PV)

sqrt(x) power(x,y) exp(x) log(x)

square root xy ex natural logarithm

CPV=sqrt(RV) CPV=power(RV,RV1) CPV=exp(RV) CPV=log(RV)

sin(x) cos(x) tan(x) atan(x)

sine cosine tangent arctangent

CPV=sin(RV)

bitpstn(x,y) bitsrch(x,y)

See Reference Manual, section D3.48.8 for information.

TPCKP(F,T,P,Tb,Pb) TC(F,T,Tb) TCF(F,T,Tb) PCKP(F,P,Pb) PCMP(F,P,Pb) PCP(F,P,Pb) PC(F,P,Pb)

Temperature and pressure correction of gas flow Temperature correction of gas flow (Deg C) Temperature correction of gas flow (Deg F) Pressure correction of gas flow (KPa) Pressure correction of gas flow (MPa) Pressure correction of gas flow (Pa) Pressure correction of gas flow (Kg/cm2)

ASTM1(t,F,C) ASTMn(t,F,ρ)

ASTM temperature correction of oil flow. n = 2 (crude oil), 3 (fuel oil), 4 (lubricating oil)

llimit(x,low,high) dlimit(x,low,high)

limit output between high and low values (these can be fixed constant or tag.items).

CPV=dlimit(RV,12.2,87.1)

stpvcalc(step,incr) Returns the value of the step number in a sequence plus the increment value.

SEQ01.PV = stpvcalc(SEQ01.PV,2) if the step of SEQ01.PV is 04, then 2 will be added to it and SEQ01.PV will be set to 06.

TE 33AU1C3-01 7-23

Page 24: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

7.2.6 Control Statements Control statements control the order in which statements are executed. There are for such statements:

• If Statements • Switch Statements • Goto Statements • Exit Statements

• If Statement:

An IF statement can be used in three formats: Format 1

if (<condition>) <statement>

examples:

if (FI100.PV > 23.2) FIC100.SV = 80.0 if (PI100.PV <= PI200.PV - PI300.PV) PIC230.VN = 34.4 if (FI100.PV > 23.2) AND (FI100.PV <46.3) FIC100.SV = 80.0 if ({FIC100.MODE.MAN}) FIC100.MV = 50.0

Format 2

if (<condition>) then ……. else ……. end if

note: if statements can be nested, but make sure that the if statement is properly bracketed with an "end if".

example:

if (FI100.PV > 23.2) then FIC100.SV = 80.0 PIC100.SV = PI200.PV * TI100.PV / P01

else FIC100.SV = 0.0 PIC100.SV = 0.0

end if

TE 33AU1C3-01 7-24

Page 25: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

Format 3

if (<condition>) then …… else if (<expression>) then …… else …… end if

note: several "else if" statements can exist in one if statement.

example:

if (FI100.PV > 80.0) then FIC100.SV = 50.0 {FIC100.MODE.AUT} = 1

else if (FI100.PV > 50.0) then FIC100.SV = 25.0

{FIC100.MODE.AUT} = 1 else if (FI100.PV > 25.0) then FIC100.SV = 10.0

{FIC100.MODE.AUT} = 1 else

FIC100.SV = 0.0 {FIC100.MODE.MAN} = 1

end if

TE 33AU1C3-01 7-25

Page 26: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

• Switch Statement

The switch statement is a branching control that executes a "case" if it satisfies a condition. Format:

switch (<condition>) case <constant1>, constant2, ….> : …….. case <constant1>, constant2, ….> : …….. otherwise: …….. end switch

Notes: 1. there can be several case statements, but there must be a minimum of one. 2. the otherwise statement is optional. 3. <condition> format is "tag.item" and this refers to an integer or

character value. It cannot refer to an analog value (e.g. FIC100.PV is not allowed).

4. <constant> format is an integer or character value. If it is a character value, then it must have " " marks around it. The can be several constants for one case.

Example:

switch (DATASW.SW) ! DATASW is an SW-91 case 1,2,7: FIC100.SV = 40.0 case 3,4: FIC100.SV = 75.0 case 5,8,9: {FIC100.MODE.MAN}=1 FIC100.MV = 100.0 otherwise: FIC100.SV = 65.0 end switch

TE 33AU1C3-01 7-26

Page 27: S7 Calculation Functions

YOKOGAWA TRAINING Section 7. Calculation Functions

TE 33AU1C3-01 7-27

• Goto Statement:

The Goto statement is an unconditional jump. It jumps to a specified label name. Format:

…… goto <label> ……. <label>: ……

Notes: 1. <label> can be any alphanumeric. 2. The label must be located after the GOTO statement, that is, it is not

possible to jump backwards. 3. A GOTO can exist within an IF or SWITCH statement, so that it is

possible to jump out of the control function. It is not possible, however, to jump into a control statement.

example:

…… if (FIC100.PV > 75) then FIC100.SV = 20 goto FLOW else if (FIC100. PV > 50) then ……. else ……. end if …… …… FLOW: ……. ……

• Exit Statement

The Exit statement is similar to the GOTO statement in that it is an unconditional jump. However, instead of jumping to a label, it jumps to the end of the program, so that no statements after the Exit statement are executed. It can be used with conditional control statements (IF and SWITCH).