-
Notifications
You must be signed in to change notification settings - Fork 5
/
FlowCorr.scl
302 lines (277 loc) · 9.22 KB
/
FlowCorr.scl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
// Name: FB1916
// Symbolic Name: FlowCorr
// Symbol Comment: Pressure Temperature Correction
// Family: Math
// Version: 4.0
// Author: AdvLib82
// Last modified: 03/18/2015
// Use: UDT16,FC260
// Size: 2398 bytes
// Signature: generiert vom SCL Übersetzer Version: SCLCOMP K05.03.08.01_01.04.00.03 release
FUNCTION_BLOCK FB11916
TITLE ='Pressure Temperature Correction'
AUTHOR : AdvLib82
FAMILY : Math
NAME : FlowCorr
VERSION : '4.0'
VAR_INPUT
DiffP { S7_dynamic := 'true' }: STRUCT //Differential pressure
Value : REAL := 1.000000e+000; //Value
ST : BYTE := B#16#80; //Signal Status
END_STRUCT ;
DiffP0 { S7_dynamic := 'true' }: STRUCT //Differential pressure at operating point
Value : REAL := 1.000000e+002; //Value
ST : BYTE := B#16#80; //Signal Status
END_STRUCT ;
P { S7_dynamic := 'true' }: STRUCT //Pressure
Value : REAL ; //Value
ST : BYTE := B#16#80; //Signal Status
END_STRUCT ;
P0 { S7_dynamic := 'true' }: STRUCT //Pressure at operating point
Value : REAL := 1.000000e+000; //Value
ST : BYTE := B#16#80; //Signal Status
END_STRUCT ;
P_Atmos { S7_dynamic := 'true' }: STRUCT //Ambient pressure
Value : REAL := 1.000000e+003; //Value
ST : BYTE := B#16#80; //Signal Status
END_STRUCT ;
Temp { S7_dynamic := 'true' }: STRUCT //Temperature
Value : REAL ; //Value
ST : BYTE := B#16#80; //Signal Status
END_STRUCT ;
Temp0 { S7_dynamic := 'true' }: STRUCT //Temperature at operating point
Value : REAL := 2.000000e+001; //Value
ST : BYTE := B#16#80; //Signal Status
END_STRUCT ;
Density { S7_dynamic := 'true' }: STRUCT //Density
Value : REAL ; //Value
ST : BYTE := B#16#80; //Signal Status
END_STRUCT ;
Density0 { S7_dynamic := 'true' }: STRUCT //Density at operating point
Value : REAL ; //Value
ST : BYTE := B#16#80; //Signal Status
END_STRUCT ;
Flow0 { S7_dynamic := 'true' }: STRUCT //Flow at operating point
Value : REAL ; //Value
ST : BYTE := B#16#80; //Signal Status
END_STRUCT ;
TempAbs { S7_dynamic := 'true' }: STRUCT //Absolute temperature
Value : REAL := 2.731500e+002; //Value
ST : BYTE := B#16#80; //Signal Status
END_STRUCT ;
Mode : INT := 1; //Mode 1..3
P_SqrtOn { S7_edit := 'para' }: BOOL ; //1 = transmitter calculates square root
SubsFlow { S7_edit := 'para' }: REAL ; //Substitution value
Feature { S7_visible := 'false' }: STRUCT //Status of various features
Bit0 : BOOL ; //Reserved
Bit1 : BOOL ; //Reserved
Bit2 : BOOL ; //Reserved
Bit3 : BOOL ; //Reserved
Bit4 : BOOL ; //Reserved
Bit5 : BOOL ; //Reserved
Bit6 : BOOL ; //Reserved
Bit7 : BOOL ; //Reserved
Bit8 : BOOL ; //1 = Substitute value
Bit9 : BOOL ; //Reserved
Bit10 : BOOL ; //Reserved
Bit11 : BOOL ; //Reserved
Bit12 : BOOL ; //Reserved
Bit13 : BOOL ; //Reserved
Bit14 : BOOL ; //Reserved
Bit15 : BOOL ; //Reserved
Bit16 : BOOL ; //Reserved
Bit17 : BOOL ; //Reserved
Bit18 : BOOL ; //Reserved
Bit19 : BOOL ; //Reserved
Bit20 : BOOL ; //Reserved
Bit21 : BOOL ; //Reserved
Bit22 : BOOL ; //Reserved
Bit23 : BOOL ; //Reserved
Bit24 : BOOL ; //Reserved
Bit25 : BOOL ; //Reserved
Bit26 : BOOL ; //Reserved
Bit27 : BOOL ; //Reserved
Bit28 : BOOL ; //Reserved
Bit29 : BOOL ; //Reserved
Bit30 : BOOL ; //Reserved
Bit31 : BOOL ; //Reserved
END_STRUCT ;
END_VAR
VAR_OUTPUT
Bad : STRUCT //1= Bad process value
Value : BOOL ; // Value
ST : BYTE := B#16#80; // Signal Status
END_STRUCT ;
Flow { S7_dynamic := 'true' }: STRUCT //Calculated flow
Value : REAL ; //Value
ST : BYTE := B#16#80; //Signal Status
END_STRUCT ;
END_VAR
VAR
Sar_reserve : ARRAY [0 .. 7 ] OF //8 bytes reserved for future use.
BYTE ; //8 bytes reserved for future use.
END_VAR
VAR_TEMP
i : INT ; //Counter, InvError
nSTprio : INT ; //Hilfswerte
nSTprioNew : INT ; //Hilfswerte
rTemp : REAL ; //Internal temperature
rTemp0 : REAL ; //Internal temperature at operating point
rTempAbs : REAL ; //Internal temperature absolut
rP : REAL ; //Internal pressure
rP0 : REAL ; //Internal pressure at operating point
rDiffP : REAL ; //Internal differential pressure
rDiffP0 : REAL ; //Internal differential pressure at operating point
rP_Atmos : REAL ; //Internal ambient pressure
rDensity : REAL ; //Internal density
rDensity0 : REAL ; //Internal density at operating point
rFlow0 : REAL ; //Internal flow value
rFlowNew : REAL ; //new Flow.Value
arStatus : ARRAY [0 .. 10 ] OF //array to calculate the status
BYTE ; //array to calculate the status
bFlowST : BYTE ; //Internal status of flow
xBadAct : BOOL ; //Bad Status
xBadChReal : BOOL ; //Bad CheckReal
END_VAR
BEGIN
//>L 67.3:=TRUE;>>
rFlowNew:=Flow.Value;
bFlowST:=Flow.ST;
xBadAct:=FALSE;
xBadChReal:=FALSE;
arStatus[0]:=DiffP.ST;
arStatus[1]:=DiffP0.ST;
arStatus[2]:=Flow0.ST;
arStatus[3]:=TempAbs.ST;
arStatus[4]:=Temp0.ST;
arStatus[5]:=Temp.ST;
arStatus[6]:=P_Atmos.ST;
arStatus[7]:=P0.ST;
arStatus[8]:=P.ST;
arStatus[9]:=Density0.ST;
arStatus[10]:=Density.ST;
nSTprio:=6;
nSTprioNew:=6;
FOR i:=0 TO 10 BY 1 DO
CASE BYTE_TO_INT(arStatus[i]) OF
128 :
nSTprioNew:=6;
0 :
nSTprioNew:=0;
40 :
nSTprioNew:=1;
96 :
nSTprioNew:=2;
104 :
nSTprioNew:=3;
120 :
nSTprioNew:=4;
164 :
nSTprioNew:=5;
ELSE:
nSTprioNew:=0;
END_CASE;
IF nSTprioNew<nSTprio THEN
nSTprio:=nSTprioNew;
END_IF;
IF nSTprio=0 THEN EXIT; END_IF;
END_FOR;
CASE nSTprio OF
6 :
bFlowST:=B#16#80;
0 :
bFlowST:=B#16#0;
1 :
bFlowST:=B#16#28;
2 :
bFlowST:=B#16#60;
3 :
bFlowST:=B#16#68;
4 :
bFlowST:=B#16#78;
5 :
bFlowST:=B#16#A4;
ELSE:
bFlowST:=0;
END_CASE;
rDiffP:=ChkREAL(In := DiffP.Value,ErrNum := i);
IF (i=3) OR (i=1) THEN xBadChReal:=TRUE; END_IF;
rDiffP0:=ChkREAL(In := DiffP0.Value,ErrNum := i);
IF (i=3) OR (i=1) THEN xBadChReal:=TRUE; END_IF;
rFlow0:=ChkREAL(In := Flow0.Value,ErrNum := i);
IF (i=3) OR (i=1) THEN xBadChReal:=TRUE; END_IF;
IF P_SqrtOn THEN
rDiffP:=rDiffP**2;
END_IF;
IF (rDiffP0<>0.0) AND (NOT xBadChReal) THEN
CASE Mode OF
1 :
rTempAbs:=ChkREAL(In := TempAbs.Value,ErrNum := i);
IF (i=3) OR (i=1) THEN xBadChReal:=TRUE; END_IF;
rTemp0:=ChkREAL(In := Temp0.Value,ErrNum := i);
IF (i=3) OR (i=1) THEN xBadChReal:=TRUE; END_IF;
rTemp:=ChkREAL(In := Temp.Value,ErrNum := i);
IF (i=3) OR (i=1) THEN xBadChReal:=TRUE; END_IF;
rP_Atmos:=ChkREAL(In := P_Atmos.Value,ErrNum := i);
IF (i=3) OR (i=1) THEN xBadChReal:=TRUE; END_IF;
rP0:=ChkREAL(In := P0.Value,ErrNum := i);
IF (i=3) OR (i=1) THEN xBadChReal:=TRUE; END_IF;
rP:=ChkREAL(In := P.Value,ErrNum := i);
IF (i=3) OR (i=1) THEN xBadChReal:=TRUE; END_IF;
rTemp0:=rTempAbs+rTemp0;
rTemp:=rTempAbs+rTemp;
rP0:=(rP_Atmos/1.000000e+003)+rP0;
rP:=(rP_Atmos/1.000000e+003)+rP;
IF ((rTemp<>0.0) AND (rP0<>0.0)) AND (NOT xBadChReal) THEN
rFlowNew:=SQRT(ABS(((rDiffP/rDiffP0)*(rTemp0/rTemp))*(rP/rP0)))*rFlow0;
ELSE
xBadChReal:=TRUE;
END_IF;
2 :
rDensity0:=ChkREAL(In := Density0.Value,ErrNum := i);
IF (i=3) OR (i=1) THEN xBadChReal:=TRUE; END_IF;
rDensity:=ChkREAL(In := Density.Value,ErrNum := i);
IF (i=3) OR (i=1) THEN xBadChReal:=TRUE; END_IF;
IF (rDensity0<>0.0) AND (NOT(xBadChReal)) THEN
rFlowNew:=SQRT(ABS((rDiffP/rDiffP0)*(rDensity/rDensity0)))*rFlow0;
ELSE
xBadChReal:=TRUE;
END_IF;
3 :
rDensity0:=ChkREAL(In := Density0.Value,ErrNum := i);
IF (i=3) OR (i=1) THEN xBadChReal:=TRUE; END_IF;
rDensity:=ChkREAL(In := Density.Value,ErrNum := i);
IF (i=3) OR (i=1) THEN xBadChReal:=TRUE; END_IF;
IF (rDensity<>0.0) AND (NOT xBadChReal) THEN
rFlowNew:=SQRT(ABS((rDiffP/rDiffP0)*(rDensity0/rDensity)))*rFlow0;
ELSE
xBadChReal:=TRUE;
END_IF;
ELSE
xBadChReal:=TRUE;
END_CASE;
ELSE
xBadChReal:=TRUE;
END_IF;
IF NOT(xBadChReal) THEN
rFlowNew:=ChkREAL(In := rFlowNew,ErrNum := i);
IF (i=3) OR (i=1) THEN xBadChReal:=TRUE; END_IF;
END_IF;
IF xBadChReal THEN
IF Feature.Bit8 THEN
rFlowNew:=SubsFlow;
bFlowST:=B#16#60;
ELSE
rFlowNew:=Flow.Value;
IF bFlowST<>B#16#0 THEN
bFlowST:=B#16#28;
END_IF;
END_IF;
END_IF;
IF ((bFlowST=B#16#0) OR (bFlowST=B#16#28)) OR xBadChReal THEN
xBadAct:=TRUE;
END_IF;
Flow.Value:=rFlowNew;
Flow.ST:=bFlowST;
Bad.Value:=xBadAct;
END_FUNCTION_BLOCK