-
Notifications
You must be signed in to change notification settings - Fork 5
/
RateLim.scl
277 lines (269 loc) · 10.7 KB
/
RateLim.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
// Name: FB1882
// Symbolic Name: RateLim
// Symbol Comment: Gradient limitation
// Family: LogicAn
// Version: 4.0
// Author: AdvLib82
// Last modified: 01/11/2016
// Use: -
// Size: 1368 bytes
// Signature: generiert vom SCL Übersetzer Version: SCLCOMP K05.03.08.03_02.01.00.01 release
FUNCTION_BLOCK FB11882
TITLE ='Gradient limitation'
{ S7_tasklist := 'OB100' }
AUTHOR : AdvLib82
FAMILY : LogicAn
NAME : RateLim
VERSION : '4.0'
VAR_INPUT
In { S7_dynamic := 'true' }: STRUCT //Analog Input Value
Value : REAL ; // Value
ST : BYTE := B#16#80; // Signal Status
END_STRUCT ;
InScale { S7_edit := 'para'; S7_xedit := 'High,para;Low,para;' }: STRUCT //Input Signal Ramp Scale
High : REAL := 1.000000e+002; // High Value
Low : REAL ; // Low Value
END_STRUCT ;
UpRaLim { S7_dynamic := 'true' }: REAL := 3.000000e+000; //Positive Ramp Rate Value
DnRaLim { S7_dynamic := 'true' }: REAL := 3.000000e+000; //Negative Ramp Rate Value
RateOn { S7_dynamic := 'true' }: STRUCT //Ramp Rate Enable/Disable
Value : BOOL ; // Value
ST : BYTE := B#16#80; // Signal Status
END_STRUCT ;
RmpOn { S7_dynamic := 'true' }: STRUCT //1= Activate ramp to ramp target RmpTarget
Value : BOOL ; // Value
ST : BYTE := B#16#80; // Signal Status
END_STRUCT ;
RmpModTime { S7_dynamic := 'true' }: BOOL ; //1= Use time (RmpTime) for ramp, 0= Use rates UpRaLim, DnRaLim
RmpTime { S7_dynamic := 'true' }: REAL ; //Time for ramp from current value up to RmpTarget
RmpTarget { S7_dynamic := 'true' }: STRUCT //Target value for ramp
Value : REAL ; // Value
ST : BYTE := B#16#80; // Signal Status
END_STRUCT ;
SampleTime { S7_link := 'false'; S7_param := 'false'; S7_sampletime := 'true'; S7_visible := 'false' }: REAL := 1.000000e-001; //Sample Time[sec]
TimeFactor { S7_visible := 'false'; S7_edit := 'para' }: INT ; //Time Conversion Factor (0- /Sec, 1- /Min, 2- /Hr)
Feature { S7_visible := 'false' }: STRUCT //Status of various features
Bit0 : BOOL ; //0 = Start up with defined initializing in OB100; 1 = keep last stored values
Bit1 : BOOL ; //Reserved
Bit2 : BOOL ; //Reserved
Bit3 : BOOL ; //Reserved
Bit4 : BOOL ; //Reserved
Bit5 : BOOL ; //Reserved
Bit6 : BOOL ; //Reserved
Bit7 : BOOL ; //Reserved
Bit8 : BOOL ; //0 = Rate of change in engineering unit; 1 = Rate of change in percentage
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
Out { S7_dynamic := 'true' }: STRUCT //Ramp Output
Value : REAL ; // Value
ST : BYTE := B#16#80; // Signal Status
END_STRUCT ;
UpRaAct { S7_dynamic := 'true' }: STRUCT //Positive Ramping Active
Value : BOOL ; // Value
ST : BYTE := B#16#80; // Signal Status
END_STRUCT ;
DnRaAct { S7_dynamic := 'true' }: STRUCT //Negative Ramping Active
Value : BOOL ; // Value
ST : BYTE := B#16#80; // Signal Status
END_STRUCT ;
ErrorNum { S7_visible := 'false'; S7_dynamic := 'true' }: INT := -1; //Error Number
END_VAR
VAR
SnErr : INT ; //Error information.
SxFirstStart : BOOL := TRUE; //Initial run.
SxRmpOn : BOOL ; //Ramping to RmpTarget
SrGradient : REAL ; //Effective Ramp Value
SrTimeFact : REAL := 1.000000e+000; //Time conversion factor into /Sec or /Min or /Hr.END_VAR
SrStartRmp : REAL ; //Ramp start value
SrRmpTarget : REAL ; //Ramp target
SrRestRmp : REAL ; //Rest value in ramp function and gradient limitation
Sar_reserve : ARRAY [0 .. 7 ] OF //8 bytes reserved for future use.
BYTE ; //8 bytes reserved for future use.
END_VAR
VAR_TEMP
TOP_SI : STRUCT
EV_CLASS : BYTE ; // Bits 0 to 3: Event ID· Bits 4 to 7: Event class
EV_NUM : BYTE ; // Event number
PRIORITY : BYTE ; // Number of the priority class (meaning OF B#16#FE: OB NOT available or locked)
NUM : BYTE ; // OB number.
TYP2_3 : BYTE ; // Data ID 2_3: identifies the information entered in ZI2_3
TYP1 : BYTE ; // Data ID 1 : identifies the information entered in ZI1
ZI1 : WORD ; // Additional information 1
ZI2_3 : DWORD ; // Additional information 2_3
END_STRUCT ;
START_UP_SI : STRUCT
EV_CLASS : BYTE ; // Bits 0 to 3: Event ID· Bits 4 to 7: Event class
EV_NUM : BYTE ; // Event number
PRIORITY : BYTE ; // Number of the priority class (meaning OF B#16#FE: OB NOT available or locked)
NUM : BYTE ; // OB number.
TYP2_3 : BYTE ; // Data ID 2_3: identifies the information entered in ZI2_3
TYP1 : BYTE ; // Data ID 1 : identifies the information entered in ZI1
ZI1 : WORD ; // Additional information 1
ZI2_3 : DWORD ; // Additional information 2_3
END_STRUCT ;
nInfErr : INT ; //Infinity Error Nos
xUpRaAct : BOOL ; //Upward ramping active (internal)
xDnRaAct : BOOL ; //Downward ramping active (internal)
rUpRaLim : REAL ; //Equivalent Rate of Percentage of Upward Ramp Rate set.
rDnRaLim : REAL ; //Equivalent Rate OF Percentage OF Downward Ramp Rate set.
rDiff : REAL ; //Difference between Input and Ramped output
rTemp : REAL ; //Temp. REAL variable
rOut : REAL ; //New Out value
xFeatStartupWithOutInit : BOOL ; //Bit 0 = 0 Start up with defined init in OB100 (default)
xFeatEuPercentRateChange : BOOL ; //Bit 8 = 0, Ramping in Engineering Unit
stcDigVal : STRUCT
Value : BOOL ; // Value
ST : BYTE ; // Signal Status
END_STRUCT ;
stcDigVal_b AT stcDigVal : BYTE;
stcAnaVal : STRUCT
Value : REAL ; // Value
ST : BYTE ; // Signal Status
END_STRUCT ;
END_VAR
BEGIN
xFeatStartupWithOutInit:=Feature.Bit0;
xFeatEuPercentRateChange:=Feature.Bit8;
SnErr:=RD_SINFO(TOP_SI := TOP_SI
,START_UP_SI := START_UP_SI
); // INT
IF (BYTE_TO_INT(TOP_SI.NUM)=100) OR SxFirstStart THEN (*A7d0*)
SxFirstStart:=FALSE;
IF NOT(xFeatStartupWithOutInit) THEN (*A7d3*)
stcDigVal_b:=B#16#0;
stcDigVal.ST:=B#16#80;
stcAnaVal.Value:=0.0;
stcAnaVal.ST:=B#16#80;
Out:=stcAnaVal;
UpRaAct:=stcDigVal;
DnRaAct:=stcDigVal;
SrRmpTarget:=RmpTarget.Value;
SxRmpOn:=FALSE;
END_IF;
ELSIF (BYTE_TO_INT(TOP_SI.NUM)>=30) AND (BYTE_TO_INT(TOP_SI.NUM)<=38) THEN (*A7d3*)
ErrorNum:=0;
xUpRaAct:=FALSE;
xDnRaAct:=FALSE;
Out.ST:=In.ST;
In.Value:=ChkREAL(In := In.Value
,ErrNum := nInfErr
);
IF (nInfErr=1) OR (nInfErr=3) THEN (*A7d4*)
ErrorNum:=30;
ELSE (*A7d4*)
IF xFeatEuPercentRateChange THEN (*A7d6*)
rUpRaLim:=(InScale.High-InScale.Low)*(UpRaLim/100.0);
rDnRaLim:=(InScale.High-InScale.Low)*(DnRaLim/100.0);
ELSE (*A7d6*)
rUpRaLim:=UpRaLim;
rDnRaLim:=DnRaLim;
END_IF; (*A7d7*)
IF TimeFactor=0 THEN (*A7d8*)
SrTimeFact:=1.0;
ELSIF TimeFactor=1 THEN (*A7da*)
SrTimeFact:=1.666667e-002;
ELSIF TimeFactor=2 THEN (*A7db*)
SrTimeFact:=2.777778e-004;
ELSE (*A7db*)
ErrorNum:=43;
END_IF; (*A7d9*)
IF ((NOT(SxRmpOn)) AND RmpOn.Value) OR (RmpTarget.Value<>SrRmpTarget) THEN (*A7dc*)
SrStartRmp:=Out.Value;
SrRestRmp:=0.0;
END_IF; (*A7dc*)
IF RmpOn.Value THEN (*A7dd*)
Out.ST:=RmpTarget.ST;
IF RmpModTime THEN (*A7de*)
IF RmpTime>0.0 THEN (*A7df*)
rDiff:=(((RmpTarget.Value-SrStartRmp)*SrTimeFact)*SampleTime)/RmpTime;
ELSE (*A7df*)
rDiff:=RmpTarget.Value-SrStartRmp;
RmpTime:=0.0;
END_IF;
ELSE (*A7de*)
IF (RmpTarget.Value-SrStartRmp)>0.0 THEN (*A7e2*)
rDiff:=(ABS(rUpRaLim)*SrTimeFact)*SampleTime;
ELSE (*A7e2*)
rDiff:=((-ABS(rDnRaLim))*SrTimeFact)*SampleTime;
END_IF;
END_IF; (*A7e1*)
rTemp:=SrRestRmp+rDiff;
rOut:=rTemp+Out.Value;
SrRestRmp:=(Out.Value-rOut)+rTemp;
IF ((rOut<=RmpTarget.Value) AND (rDiff<=0.0)) OR ((rOut>=RmpTarget.Value) AND (rDiff>=0.0)) THEN (*A7e4*)
SxRmpOn:=TRUE;
Out.Value:=RmpTarget.Value;
ELSE (*A7e4*)
IF rDiff>=0.0 THEN (*A7e6*)
xUpRaAct:=TRUE;
END_IF; (*A7e6*)
IF rDiff<=0.0 THEN (*A7e7*)
xDnRaAct:=TRUE;
END_IF; (*A7e7*)
Out.Value:=rOut;
END_IF;
ELSIF RateOn.Value THEN (*A7e9*)
IF InScale.High>=InScale.Low THEN (*A7d5*)
rDiff:=In.Value-Out.Value;
IF rDiff>=0.0 THEN (*A7eb*)
IF UpRaLim<>0.0 THEN (*A7ee*)
SrGradient:=(ABS(rUpRaLim)*SrTimeFact)*SampleTime;
IF rDiff>SrGradient THEN (*A7ed*)
xUpRaAct:=TRUE;
END_IF;
END_IF; (*A7ed*)
ELSE
IF DnRaLim<>0.0 THEN (*A7ee*)
SrGradient:=((-ABS(rDnRaLim))*SrTimeFact)*SampleTime;
IF rDiff<SrGradient THEN (*A7ee*)
xDnRaAct:=TRUE;
END_IF;
END_IF;
END_IF; (*A7ee*)
IF (xUpRaAct) OR xDnRaAct THEN (*A7f1*)
rTemp:=SrRestRmp+SrGradient;
rOut:=rTemp+Out.Value;
SrRestRmp:=(Out.Value-rOut)+rTemp;
Out.Value:=rOut;
ELSE (*A7f1*)
Out.Value:=In.Value;
SrRestRmp:=0.0;
END_IF;
END_IF; (*A7f2*)
ELSE (*A7e9*)
Out.Value:=In.Value;
SrRestRmp:=0.0;
END_IF;
END_IF; (*A7d5*)
UpRaAct.Value:=xUpRaAct;
DnRaAct.Value:=xDnRaAct;
SrRmpTarget:=RmpTarget.Value;
SxRmpOn:=RmpOn.Value;
UpRaAct.ST:=Out.ST;
DnRaAct.ST:=Out.ST;
END_IF; (*A7d3*)
END_FUNCTION_BLOCK