1<?xml version="1.0" encoding="UTF-8"?>
2<project
3 xmlns="http://www.plcopen.org/xml/tc6.xsd"
4 xmlns:xhtml="http://www.w3.org/1999/xhtml"
5 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6 xsi:schemaLocation="http://www.plcopen.org/xml/tc6.xsd http://www.plcopen.org/xml/tc6.xsd" >
7<fileHeader
8 companyName="FGDES/LRT"
9 creationDateTime="2017-03-08T22:44:54"
10 productName="CompileDES"
11 productVersion="3.09" />
12<contentHeader
13 name="Blink_Pox_B_2017_02"
14 version="1" >
15 <coordinateInfo>
16 <fbd><scaling x="1" y="1"/></fbd>
17 <ld><scaling x="1" y="1"/></ld>
18 <sfc><scaling x="1" y="1"/></sfc>
19 </coordinateInfo>
20</contentHeader>
21<types>
22<dataTypes />
23<pous>
24<pou name="fcg_cyclic_fb" pouType="functionBlock">
25<interface>
26 <inputVars retain="false">
27 <variable name="RESET">
28 <type> <BOOL /> </type>
29 <initialValue> <simpleValue value="false" /> </initialValue>
30 <documentation><![CDATA[external reset]]></documentation>
31 </variable>
32 </inputVars>
33 <outputVars retain="false">
34 <variable name="STATUS">
35 <type> <BYTE /> </type>
36 <documentation><![CDATA[status (0x00 <> waiting, 0x01<>executing, 0x02<>err)]]></documentation>
37 </variable>
38 </outputVars>
39 <localVars retain="false">
40 <variable name="fcg_recent_event">
41 <type> <INT /> </type>
42 <documentation><![CDATA[recent event (0<>none)]]></documentation>
43 </variable>
44 <variable name="fcg_pending_events_0">
45 <type> <BYTE /> </type>
46 <documentation><![CDATA[pending input events incl timer elapse]]></documentation>
47 </variable>
48 <variable name="fcg_enabled_events_0">
49 <type> <BYTE /> </type>
50 <documentation><![CDATA[events enabled by all generators]]></documentation>
51 </variable>
52 <variable name="fcg_parallel_state_0">
53 <type> <INT /> </type>
54 <documentation><![CDATA[parallel state]]></documentation>
55 </variable>
56 <variable name="fcg_parallel_state_1">
57 <type> <INT /> </type>
58 <documentation><![CDATA[parallel state]]></documentation>
59 </variable>
60 <variable name="fcg_parallel_state_2">
61 <type> <INT /> </type>
62 <documentation><![CDATA[parallel state]]></documentation>
63 </variable>
64 <variable name="fcg_exec_event">
65 <type> <INT /> </type>
66 <initialValue> <simpleValue value="-1" /> </initialValue>
67 <documentation><![CDATA[executed event (-1<>init, 0<>none)]]></documentation>
68 </variable>
69 <variable name="fcg_sched_event">
70 <type> <INT /> </type>
71 <documentation><![CDATA[scheduled event (0<>none)]]></documentation>
72 </variable>
73 <variable name="fcg_line_level_0">
74 <type> <BOOL /> </type>
75 <documentation><![CDATA[line levels]]></documentation>
76 </variable>
77 <variable name="fcg_first_loop">
78 <type> <BOOL /> </type>
79 <documentation><![CDATA[loop flag]]></documentation>
80 </variable>
81 <variable name="fcg_timer_Tick_cnt">
82 <type> <TIME /> </type>
83 <documentation><![CDATA[timer states]]></documentation>
84 </variable>
85 <variable name="fcg_timer_Tick_run">
86 <type> <BOOL /> </type>
87 <documentation><![CDATA[timer states]]></documentation>
88 </variable>
89 <variable name="fcg_time_elapsed">
90 <type> <TIME /> </type>
91 <documentation><![CDATA[elapsed time since last invokation]]></documentation>
92 </variable>
93 <variable name="fcg_aux_executables_0">
94 <type> <BYTE /> </type>
95 <documentation><![CDATA[enabled events that can be executed]]></documentation>
96 </variable>
97 <variable name="fcg_aux_wordret">
98 <type> <BYTE /> </type>
99 <documentation><![CDATA[aux maths and stack variables ]]></documentation>
100 </variable>
101 <variable name="fcg_aux_edge">
102 <type> <BOOL /> </type>
103 <documentation><![CDATA[aux maths and stack variables ]]></documentation>
104 </variable>
105 <variable name="fcg_aux_wordaddr">
106 <type> <INT /> </type>
107 <documentation><![CDATA[aux maths and stack variables ]]></documentation>
108 </variable>
109 <variable name="fcg_aux_bitaddr">
110 <type> <INT /> </type>
111 <documentation><![CDATA[aux maths and stack variables ]]></documentation>
112 </variable>
113 <variable name="fcg_aux_bitmask">
114 <type> <BYTE /> </type>
115 <documentation><![CDATA[aux maths and stack variables ]]></documentation>
116 </variable>
117 <variable name="" address="%IX54.1">
118 <type> <BOOL /> </type>
119 <documentation><![CDATA[physical input]]></documentation>
120 </variable>
121 <variable name="" address="%QX55.1">
122 <type> <BOOL /> </type>
123 <documentation><![CDATA[physical output]]></documentation>
124 </variable>
125 <variable name="" address="%QX55.2">
126 <type> <BOOL /> </type>
127 <documentation><![CDATA[physical output]]></documentation>
128 </variable>
129 <variable name="" address="%QX55.3">
130 <type> <BOOL /> </type>
131 <documentation><![CDATA[physical output]]></documentation>
132 </variable>
133 <variable name="fcg_systime_ton">
134 <type> <derived name="TON" /> </type>
135 <documentation><![CDATA[iec timer to simulate system time]]></documentation>
136 </variable>
137 <variable name="fcg_systime_recent">
138 <type> <TIME /> </type>
139 <documentation><![CDATA[iec timer to simulate system time]]></documentation>
140 </variable>
141 <variable name="fcg_systime_now">
142 <type> <TIME /> </type>
143 <documentation><![CDATA[iec timer to simulate system time]]></documentation>
144 </variable>
145 </localVars>
146</interface>
147<body>
148<ST>
149<![CDATA[
150(* ************************************************ *)
151(* CodeGenerator: Target IEC 61131 Structured Text *)
152(* ************************************************ *)
153
154
155(* CompileDES 3.09 (using libFAUDES 2.28a) *)
156(* Configuration: Blink_Pox_B_2017_02 *)
157
158
159
160(* ************************************************ *)
161(* * executor core cyclic code: reset/initialise * *)
162(* ************************************************ *)
163
164
165(* ************************************************ *)
166(* * reset internal state * *)
167
168(* set internal reset flag *)
169IF RESET THEN
170 fcg_exec_event := -1;
171END_IF;
172
173(* do reset core *)
174IF fcg_exec_event = -1 THEN
175 (* clear status *)
176 STATUS := 0;
177 (* set initial state *)
178 fcg_parallel_state_0 := 1;
179 fcg_parallel_state_1 := 1;
180 fcg_parallel_state_2 := 1;
181 (* clear scheduled event *)
182 fcg_sched_event := 0;
183 (* clear recent event *)
184 fcg_recent_event := 0;
185 (* clear pending/enabled events *)
186 fcg_pending_events_0 := BYTE#0;
187 fcg_enabled_events_0 := BYTE#0;
188 (* reset timer *)
189 fcg_timer_Tick_run := false;
190 fcg_timer_Tick_cnt := TIME#1s;
191END_IF;
192
193(* do reset/track systime *)
194IF fcg_exec_event = -1 THEN
195 fcg_systime_ton(IN:=false);
196 fcg_systime_recent := TIME#0ms;
197END_IF;
198fcg_systime_ton(IN:=true, PT:=TIME#2h, ET=>fcg_systime_now);
199fcg_time_elapsed := SUB_TIME(fcg_systime_now,fcg_systime_recent);
200IF fcg_systime_now < TIME#1h THEN
201 fcg_systime_recent := fcg_systime_now;
202ELSE
203 fcg_systime_ton(IN:=false, PT:=TIME#2h);
204 fcg_systime_ton(IN:=true, PT:=TIME#2h);
205 fcg_systime_recent := TIME#0ms;
206END_IF;
207
208
209
210(* ************************************************ *)
211(* * bail out on external reset * *)
212
213IF RESET THEN
214 RETURN;
215END_IF;
216
217
218
219(* ************************************************ *)
220(* * update timer states * *)
221
222
223IF fcg_time_elapsed > TIME#0ms THEN
224 IF fcg_timer_Tick_run THEN
225 IF fcg_timer_Tick_cnt > fcg_time_elapsed THEN
226 fcg_timer_Tick_cnt := SUB_TIME(fcg_timer_Tick_cnt, fcg_time_elapsed);
227 ELSE
228 fcg_timer_Tick_cnt := TIME#0s;
229 END_IF;
230 END_IF;
231END_IF;
232
233
234
235(* ************************************************ *)
236(* * executor core cyclic code: begin * *)
237(* ************************************************ *)
238
239
240
241(* ************************************************ *)
242(* * sense input events * *)
243
244(* init: reset all line data and generate statics *)
245IF fcg_exec_event = -1 THEN
246 fcg_line_level_0 := %IX54.1;
247 IF NOT fcg_line_level_0 THEN
248 (* negative value: trigger init event [PushButton] *)
249 fcg_pending_events_0 := fcg_pending_events_0 OR BYTE#16#01;
250 END_IF;
251END_IF;
252
253(* normal operation: read lines and detect edges *)
254IF fcg_exec_event <> -1 THEN
255 (* read line [%IX54.1] *)
256 fcg_aux_edge := %IX54.1;
257 IF fcg_aux_edge <> fcg_line_level_0 THEN
258 IF fcg_line_level_0 THEN
259 (* negative edge trigger input event [PushButton] *)
260 fcg_pending_events_0 := fcg_pending_events_0 OR BYTE#16#01;
261 fcg_sched_event := 0;
262 END_IF;
263 fcg_line_level_0 := fcg_aux_edge;
264 END_IF;
265END_IF;
266
267
268
269(* ************************************************ *)
270(* * sense timer elapse * *)
271
272IF fcg_timer_Tick_run AND (fcg_timer_Tick_cnt <= TIME#0ms) THEN
273 fcg_timer_Tick_run := false;
274 fcg_pending_events_0 := fcg_pending_events_0 OR BYTE#16#02;
275 fcg_sched_event := 0;
276END_IF;
277
278
279
280(* ************************************************ *)
281(* * event execution loop * *)
282
283(* clear status to waiting *)
284STATUS := 0;
285(* set entry flag *)
286fcg_first_loop := true;
287WHILE true DO
288
289
290
291(* ************************************************ *)
292(* * update enabled events after execution * *)
293
294(* if event was executed (and on initialisation) *)
295IF fcg_exec_event <> 0 THEN
296 (* set all to enabled *)
297 fcg_enabled_events_0 := BYTE#16#ff;
298
299 (* restricting enabled events by [Blink3] *)
300 CASE fcg_parallel_state_0 OF
301 1:
302 fcg_enabled_events_0 := fcg_enabled_events_0 AND BYTE#16#07;
303 2:
304 fcg_enabled_events_0 := fcg_enabled_events_0 AND BYTE#16#0b;
305 3:
306 fcg_enabled_events_0 := fcg_enabled_events_0 AND BYTE#16#13;
307 4:
308 fcg_enabled_events_0 := fcg_enabled_events_0 AND BYTE#16#23;
309 5:
310 fcg_enabled_events_0 := fcg_enabled_events_0 AND BYTE#16#43;
311 6:
312 fcg_enabled_events_0 := fcg_enabled_events_0 AND BYTE#16#83;
313 END_CASE;
314
315 (* restricting enabled events by [Delay] *)
316 CASE fcg_parallel_state_1 OF
317 1:
318 fcg_enabled_events_0 := fcg_enabled_events_0 AND BYTE#16#fd;
319 2:
320 fcg_enabled_events_0 := fcg_enabled_events_0 AND BYTE#16#03;
321 END_CASE;
322
323 (* restricting enabled events by [WaitButton] *)
324 CASE fcg_parallel_state_2 OF
325 1:
326 fcg_enabled_events_0 := fcg_enabled_events_0 AND BYTE#16#fb;
327 END_CASE;
328
329 (* dispose event *)
330 fcg_exec_event := 0;
331 fcg_sched_event := 0;
332END_IF;
333
334
335
336(* ************************************************ *)
337(* * schedule next event to execute * *)
338
339IF fcg_sched_event = 0 THEN
340
341 (* setup candidate set to "pending or internal" *)
342 fcg_aux_executables_0 := fcg_pending_events_0 OR BYTE#16#fc;
343 (* restrict candidate set by "enabled" *)
344 fcg_aux_executables_0 := fcg_aux_executables_0 AND fcg_enabled_events_0;
345
346 (* find highest priority event (lowest bitaddress) *)
347 fcg_sched_event := 0;
348 IF NOT ( fcg_aux_executables_0 = BYTE#0 ) THEN
349 IF ( fcg_aux_executables_0 AND BYTE#16#0f ) <> BYTE#0 THEN
350 IF ( fcg_aux_executables_0 AND BYTE#16#03 ) <> BYTE#0 THEN
351 IF ( fcg_aux_executables_0 AND BYTE#16#01 ) <> BYTE#0 THEN
352 fcg_sched_event := 1;
353 ELSE
354 fcg_sched_event := 2;
355 END_IF;
356 ELSE
357 IF ( fcg_aux_executables_0 AND BYTE#16#04 ) <> BYTE#0 THEN
358 fcg_sched_event := 3;
359 ELSE
360 fcg_sched_event := 4;
361 END_IF;
362 END_IF;
363 ELSE
364 IF ( fcg_aux_executables_0 AND BYTE#16#30 ) <> BYTE#0 THEN
365 IF ( fcg_aux_executables_0 AND BYTE#16#10 ) <> BYTE#0 THEN
366 fcg_sched_event := 5;
367 ELSE
368 fcg_sched_event := 6;
369 END_IF;
370 ELSE
371 IF ( fcg_aux_executables_0 AND BYTE#16#40 ) <> BYTE#0 THEN
372 fcg_sched_event := 7;
373 ELSE
374 fcg_sched_event := 8;
375 END_IF;
376 END_IF;
377 END_IF;
378 END_IF;
379
380 (* remove scheduled event from pending events *)
381 IF fcg_sched_event > 0 THEN
382 fcg_aux_bitaddr := fcg_sched_event;
383 fcg_aux_bitaddr := fcg_aux_bitaddr - 1;
384 fcg_aux_wordaddr := fcg_aux_bitaddr / 8;
385 fcg_aux_bitaddr := fcg_aux_bitaddr MOD 8;
386 fcg_aux_bitmask := SHL( IN:=BYTE#16#01 , N:=fcg_aux_bitaddr );
387 fcg_pending_events_0 := fcg_pending_events_0 AND (NOT fcg_aux_bitmask );
388 END_IF;
389
390 (* detect sync error *)
391 IF fcg_sched_event = 0 THEN
392 fcg_aux_wordret := fcg_pending_events_0;
393 IF NOT ( fcg_aux_wordret = BYTE#0 ) THEN
394 STATUS := STATUS OR BYTE#16#02;
395 END_IF;
396 END_IF;
397
398 (* cancel pending events if no event could be scheduled *)
399 IF fcg_sched_event = 0 THEN
400 fcg_pending_events_0 := BYTE#0;
401 END_IF;
402
403END_IF;
404
405
406
407(* ************************************************ *)
408(* * break execution loop * *)
409
410IF fcg_sched_event = 0 THEN EXIT; END_IF;
411fcg_first_loop := false;
412
413
414
415(* ************************************************ *)
416(* * execute scheduled event * *)
417
418IF fcg_sched_event <> 0 THEN
419
420 fcg_exec_event := fcg_sched_event;
421 fcg_sched_event := 0;
422 STATUS := STATUS OR BYTE#16#01;
423
424 (* execute event for [Blink3] *)
425 CASE fcg_parallel_state_0 OF
426 1:
427 CASE fcg_exec_event OF
428 3:
429 fcg_parallel_state_0 := 2;
430 END_CASE;
431 2:
432 CASE fcg_exec_event OF
433 4:
434 fcg_parallel_state_0 := 3;
435 END_CASE;
436 3:
437 CASE fcg_exec_event OF
438 5:
439 fcg_parallel_state_0 := 4;
440 END_CASE;
441 4:
442 CASE fcg_exec_event OF
443 6:
444 fcg_parallel_state_0 := 5;
445 END_CASE;
446 5:
447 CASE fcg_exec_event OF
448 7:
449 fcg_parallel_state_0 := 6;
450 END_CASE;
451 6:
452 CASE fcg_exec_event OF
453 8:
454 fcg_parallel_state_0 := 1;
455 END_CASE;
456 END_CASE;
457
458 (* execute event for [Delay] *)
459 CASE fcg_parallel_state_1 OF
460 1:
461 CASE fcg_exec_event OF
462 3 .. 8:
463 fcg_parallel_state_1 := 2;
464 END_CASE;
465 2:
466 CASE fcg_exec_event OF
467 2:
468 fcg_parallel_state_1 := 1;
469 END_CASE;
470 END_CASE;
471
472 (* execute event for [WaitButton] *)
473 CASE fcg_parallel_state_2 OF
474 1:
475 CASE fcg_exec_event OF
476 1:
477 fcg_parallel_state_2 := 2;
478 8:
479 fcg_parallel_state_2 := 1;
480 END_CASE;
481 2:
482 CASE fcg_exec_event OF
483 1, 3:
484 fcg_parallel_state_2 := 2;
485 8:
486 fcg_parallel_state_2 := 1;
487 END_CASE;
488 END_CASE;
489
490 fcg_recent_event := fcg_exec_event;
491
492END_IF;
493
494
495
496(* ************************************************ *)
497(* * operate timers * *)
498
499IF fcg_exec_event > 0 THEN
500 CASE fcg_exec_event OF
501 3 .. 8:
502 fcg_timer_Tick_cnt := TIME#1s;
503 fcg_timer_Tick_run := true;
504 END_CASE;
505END_IF;
506
507
508
509(* ************************************************ *)
510(* * operate outputs * *)
511
512IF fcg_exec_event > 2 THEN
513 CASE fcg_exec_event OF
514 3:
515 (* outputs for [OnLedA] *)
516 %QX55.1 := true;
517 4:
518 (* outputs for [OnLedB] *)
519 %QX55.2 := true;
520 5:
521 (* outputs for [OnLedC] *)
522 %QX55.3 := true;
523 6:
524 (* outputs for [OffLedA] *)
525 %QX55.1 := false;
526 7:
527 (* outputs for [OffLedB] *)
528 %QX55.2 := false;
529 8:
530 (* outputs for [OffLedC] *)
531 %QX55.3 := false;
532 END_CASE;
533END_IF;
534
535
536
537(* ************************************************ *)
538(* * end execution loop * *)
539
540END_WHILE;
541
542
543
544
545(* ************************************************ *)
546(* * executor core cyclic code: end * *)
547(* ************************************************ *)
548
549
550
551(* ************************************************ *)
552(* CodeGenerator: Generated Code Ends Here *)
553(* ************************************************ *)
554]]>
555</ST>
556</body>
557</pou>
558</pous>
559</types>
560<instances>
561 <configurations />
562</instances>
563</project>