aboutsummaryrefslogtreecommitdiffstats
path: root/tests/tc999_projects/acme-002.awl
blob: 79d4d4f60702f2ece51456dd501b593ec00b0cb2 (plain)
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
DATA_BLOCK DB 1
TITLE =
AUTHOR : Xaadem
VERSION : 0.1


  STRUCT 	
   OUT_FIL : REAL  := 2.000000e+001;	//Filter OUTPUT
  END_STRUCT ;	
BEGIN
   OUT_FIL := 2.000000e+001; 
END_DATA_BLOCK

FUNCTION FC 170 : WORD
TITLE =SCALING VALUES
//
AUTHOR : SEA
FAMILY : CONVERT
NAME : SCALE
VERSION : 2.0


VAR_INPUT
  IN : INT ;	// input value to be scaled
  HI_LIM : REAL ;	// upper limit in engineering units
  LO_LIM : REAL ;	// lower limit in engineering units 
  BIPOLAR : BOOL ;	// 1=bipolar; 0=unipolar
END_VAR
VAR_OUTPUT
  OUT : REAL ;	// result of the scale conversion
END_VAR
VAR_TEMP
  IN_REAL : REAL ;	// input value as a REAL number
  K1 : REAL ;	// low limit for input value
  K2 : REAL ;	// high limit for input value
  SPAN : REAL ;	// HI_LIM - LO_LIM
  TEMP1 : REAL ;	// temporary result
END_VAR
BEGIN
NETWORK
TITLE =
//
// set K1 and K2 constants based upon BIPOLAR
//
      SET   ; // if(BIPOLAR=0)
      A     #BIPOLAR; //   .
      JC    EL01; // {
      L     0.000000e+000; //   K1=0
      T     #K1; //     .
      JU    EI01; // } else {
EL01: L     -2.764800e+004; //   K1=-27648.0
      T     #K1; //     .
EI01: NOP   0; // }
      L     2.764800e+004; // K2=+27648.0
      T     #K2; //   .
//
// convert input (IN) to real
//
      L     #IN; // ACC1=IN
      ITD   ; // convert to double integer 
      DTR   ; // convert to real
      T     #IN_REAL; // IN_REAL-IN as a real
//
// determine SPAN = HI_LIM - LO_LIM
//
      L     #HI_LIM; // SPAN=HI_LIM-LO_LIM
      L     #LO_LIM; // .
      -R    ; // .
      T     #SPAN; // .
//
// If the input value is outside the K1 and K2 range, the output
// is clamped to the nearer of either the LO_LIM or the HI_LIM 
// and an error is logged. If the input value is exactly at a limit the
// output will be set to the computed limit with no error returned.
//
      L     #IN_REAL; // if(IN_REAL<K1)
      L     #K1; //   .
      >=R   ; //   .
      JC    EL02; // {
      L     8; //   error
      T     #RET_VAL; //     .
      L     #SPAN; //   if(SPAN<0)
      L     0.000000e+000; //     .
      <R    ; //     .
      JCN   EL03; //   {
      L     #HI_LIM; //     ACC1=HI_LIM
      JU    EI03; //   } else {
EL03: L     #LO_LIM; //     ACC1=LO_LIM
EI03: NOP   0; //   } 
      T     #OUT; //   OUT=ACC1
      JU    FAIL; //   error
EL02: POP   ; // } else {
      L     #K2; //   if(IN_REAL>K2)
      <=R   ; //     .
      JC    EI04; //   {
      L     8; //     error
      T     #RET_VAL; //       .
      L     #SPAN; //     if(SPAN<0)
      L     0.000000e+000; //     {
      <R    ; //         .
      JCN   EL05; //         .
      L     #LO_LIM; //       ACC1=LO_LIM
      JU    EI05; //     } else {
EL05: L     #HI_LIM; //       ACC1=HI_LIM
EI05: NOP   0; //     } 
      T     #OUT; //     OUT=ACC1
      JU    FAIL; //     error
EI04: NOP   0; //   }
      NOP   0; // }
//
// scale the input
//
      L     #K2; // TEMP1=K2-K1
      L     #K1; //   .
      -R    ; //   .
      T     #TEMP1; //   .
      L     #IN_REAL; // IN_REAL-K1
      L     #K1; //   .
      -R    ; //   .
      L     #TEMP1; // divide by TEMP1
      /R    ; //   .
      L     #SPAN; // multiply by SPAN
      *R    ; //   .
      L     #LO_LIM; // add LO_LIM
      +R    ; //   .
      T     #OUT; // OUT=scale(IN_REAL)
//
// set BR bit : no error-set BR bit to 1; with error-set BR bit to 0.
//
      L     0; // return error code 0
      T     #RET_VAL; //
      SET   ; // RLO = 1 (NO ERROR)
      JU    SVBR; // 
FAIL: CLR   ; // RLO = 0 (ERROR)
SVBR: SAVE  ; // BR = RLO
END_FUNCTION

FUNCTION FC 185 : VOID
TITLE =F I L T E R    
{ Know_How := '1' }
AUTHOR : Xaadem
NAME : FILTER
VERSION : 0.1


VAR_INPUT
  XE : REAL ;	//Input Word
  FAC_PERCENT : REAL ;	//Smoothing factor in %
  INIT : BOOL ;	//Initialisation flag, should be set during CPU start-up
END_VAR
VAR_OUTPUT
  XA : REAL ;	//Output of measuring value which is smoothed
END_VAR
VAR_IN_OUT
  AUX : REAL ;	//Auxiliary word
END_VAR
VAR_TEMP
  MD232 : REAL ;	//Temporary value
  MD204 : REAL ;	//Temporary value
  MD208 : REAL ;	//Temporary value
  MD212 : REAL ;	//Temporary value
  MD216 : REAL ;	//Temporary value
  MD220 : REAL ;	//Temporary value
  AUX1 : REAL ;	//Temporary value
END_VAR
BEGIN
NETWORK
TITLE =read XE input

      L     #XE; 
      T     #MD232; 
      NOP   0; 
NETWORK
TITLE =

      AN    #INIT; 
      JC    M001; 
NETWORK
TITLE =Initialisation !!

M003: L     #XE; 
      T     #XA; 
      NOP   0; 
NETWORK
TITLE =Initialisation !!

      L     #MD232; 
      T     #AUX; 
      NOP   0; 
NETWORK
TITLE =Jump to the end

      A     M     20.1; 
      JC    M002; 
NETWORK
TITLE =Old and new value are equal

M001: A(    ; 
      L     #MD232; 
      L     #AUX; 
      ==R   ; 
      )     ; 
      JNB   _001; 
      L     #MD232; 
      T     #XA; 
_001: NOP   0; 
NETWORK
TITLE =Old and new value are equal

      L     #MD232; 
      L     #AUX; 
      ==R   ; 
      SAVE  ; 
      BEC   ; 
NETWORK
TITLE =If Fac_Prozent > 0 ==> XA=Xe

      L     #FAC_PERCENT; 
      L     0.000000e+000; 
      <R    ; 
      JC    M003; 
NETWORK
TITLE =If Fac_Prozent > 100 ==> XA=Xe

      L     #FAC_PERCENT; 
      L     1.000000e+002; 
      >R    ; 
      JC    M003; 
NETWORK
TITLE =B=XE-XA

      L     #MD232; 
      L     #AUX; 
      -R    ; 
      T     #MD204; 
      NOP   0; 
NETWORK
TITLE =Move factor into temporary word

      L     #FAC_PERCENT; 
      T     #MD212; 
      NOP   0; 
NETWORK
TITLE =B*Factor

      L     #MD212; 
      L     #MD204; 
      *R    ; 
      T     #MD216; 
      NOP   0; 
NETWORK
TITLE =B*Factor / 100

      L     #MD216; 
      L     1.000000e+002; 
      /R    ; 
      T     #MD220; 
      NOP   0; 
NETWORK
TITLE =XANew = AUX+(B*Factor% / 100)

      L     #AUX; 
      L     #MD220; 
      +R    ; 
      T     #AUX; 
      NOP   0; 
NETWORK
TITLE =XAnew = AUXnew

      L     #AUX; 
      T     #XA; 
      NOP   0; 
NETWORK
TITLE =End of block

M002: A     M     20.1; 
      SAVE  ; 
      BEC   ; 
END_FUNCTION

ORGANIZATION_BLOCK OB 1
TITLE = "Main Program Sweep (Cycle)"
AUTHOR : Xaadem
VERSION : 0.1


VAR_TEMP
  OB1_EV_CLASS : BYTE ;	//Bits 0-3 = 1 (Coming event), Bits 4-7 = 1 (Event class 1)
  OB1_SCAN_1 : BYTE ;	//1 (Cold restart scan 1 of OB 1), 3 (Scan 2-n of OB 1)
  OB1_PRIORITY : BYTE ;	//Priority of OB Execution
  OB1_OB_NUMBR : BYTE ;	//1 (Organization block 1, OB1)
  OB1_RESERVED_1 : BYTE ;	//Reserved for system
  OB1_RESERVED_2 : BYTE ;	//Reserved for system
  OB1_PREV_CYCLE : INT ;	//Cycle time of previous OB1 scan (milliseconds)
  OB1_MIN_CYCLE : INT ;	//Minimum cycle time of OB1 (milliseconds)
  OB1_MAX_CYCLE : INT ;	//Maximum cycle time of OB1 (milliseconds)
  OB1_DATE_TIME : DATE_AND_TIME ;	//Date and time OB1 started
  Value : REAL ;	
  AIXX : REAL ;	
  OUTfilter : REAL ;	
END_VAR
BEGIN
NETWORK
TITLE =

      A     M      0.0; 
      =     L     32.0; 
      BLD   103; 
      CALL FC   170 (
           IN                       := IW   512,
           HI_LIM                   := 1.000000e+005,
           LO_LIM                   := 0.000000e+000,
           BIPOLAR                  := L     32.0,
           RET_VAL                  := MW     2,
           OUT                      := #Value);
      NOP   0; 
NETWORK
TITLE =

      A     M     20.0; 
      =     L     32.0; 
      BLD   103; 
      CALL FC   185 (
           XE                       := #Value,
           FAC_PERCENT              := 9.000000e+001,
           INIT                     := L     32.0,
           XA                       := #OUTfilter,
           AUX                      := #AIXX);
      NOP   0; 
NETWORK
TITLE =

      L     #OUTfilter; 
      L     2.000000e+001; 
      +R    ; 
      T     DB1.DBD    0; 
      NOP   0; 
END_ORGANIZATION_BLOCK

bues.ch cgit interface