Wiki source code of 04 Program flow

Last modified by Devin Chen on 2024/01/28 11:38

Show last authors
1 = **Program jump** =
2
3 == {{id name="_Toc102982428"/}}{{id name="_Toc17621"/}}{{id name="_Toc871"/}}{{id name="_Toc23743"/}}**CJ/Conditional jump** ==
4
5 When the jump instruction is ON, the program with the specified pointer number in the same program file is executed.
6
7 -[CJ (P) (P)]
8
9 **Content, range and data type**
10
11 (% class="table-bordered" %)
12 |**Parameter**|**Content**|**Range**|**Data type**|**Data type (label)**
13 |(P)|The pointer number of the jump target|P0 to P4095|Device name|POINTER
14
15 **Device used**
16
17 (% class="table-bordered" %)
18 |(% rowspan="2" %)**Instruction**|(% rowspan="2" %)**Parameter**|(((
19 **Offset modification**
20 )))|(((
21 **Pulse extension**
22 )))|**other**
23 |**[D]**|**XXP**|**P**
24 |CJ|Parameter 1| |●|●
25
26 **Features**
27
28 * CJ(P)
29
30 {{id name="OLE_LINK159"/}}When the execution instruction is ON, the program with the specified pointer number is executed.
31
32 When the execution instruction is OFF, execute the next program.
33
34 (% style="text-align:center" %)
35 [[image:4_html_a501306a22b46191.png||class="img-thumbnail"]]
36
37 1. Execute instructions.
38 1. Each scan is executed.
39 1. One scan is executed.
40
41 (% class="box infomessage" %)
42 (((
43 **✎Note: **
44
45 After turning ON the coil of the timer, if the timer whose coil is ON is jumped by the CJ(P) instruction, the measurement will not be performed normally.
46
47 When the OUT instruction is jumped by the CJ(P) instruction, the scan time will be shorter.
48
49 When the CJ(P) instruction is used to jump backward, the scan time will be longer.
50 )))
51
52 For the CJ(P) instruction, you can jump to a step smaller than the step number being executed. However, in order to avoid the time limit of the watchdog timer, a method of jumping out of the loop during this period should be considered.
53
54 (((
55 (% style="text-align:center" %)
56 [[image:4-2.png||class="img-thumbnail"]]
57
58 (1) While X3 is ON, the loop is executed.
59
60 (2) When X7 is set to ON, it jumps out of the loop.
61 )))
62
63 • The device skipped by the CJ(P) instruction does not change.
64
65 (((
66 When X2 is ON, jump to the label of P19.
67
68 Even if X2 and X4 turn ON/OFF during CJ instruction execution, Y4 and Y5 will not change.
69
70 (% style="text-align:center" %)
71 [[image:1652258381961-360.png||class="img-thumbnail"]]
72
73 (1) When X2 is ON, jump to the label of P19.
74
75 (2) Even if X2 and X4 turn ON/OFF during CJ instruction execution, Y4 and Y5 will not change.
76 )))
77
78 • The label (P□) occupies 1 step.
79
80 (% style="text-align:center" %)
81 [[image:4_html_624bb12f51649fa1.gif||class="img-thumbnail"]]
82
83 The jump instruction can only specify the pointer number in the same program file.
84
85 When jumping to the pointer number within the jump range during jump operation, the program after the jump destination pointer number is executed.
86
87 The label procedure is shown below. When creating a loop program, move the cursor to the left of the bus bar of the Circuit program, and enter the label (P) at the beginning of the loop block.
88
89 (% style="text-align:center" %)
90 [[image:4_html_66293951b95227d4.png||class="img-thumbnail"]]
91
92 It is also possible to program the label at the position where the step number is less than the CJ instruction, but if the scan time becomes more than 200ms (default setting), a watchdog timer error will occur, which requires attention.
93
94 (% style="text-align:center" %)
95 [[image:1652258541371-747.png||class="img-thumbnail"]]
96
97 When the pointer number in the operand is the same and the label is one, the operation is as follows.
98
99 (((
100 (% style="text-align:center" %)
101 [[image:1652258590342-123.png||class="img-thumbnail"]]
102
103 (1) When X20 is ON, jump from the CJ instruction of X20 to label P9.
104
105 (2) When X20 is OFF and X21 is ON, jump from the CJ instruction of X21 to label P9.
106 )))
107
108 If the tag number is reused, it will become an error state.
109
110 (% style="text-align:center" %)
111 [[image:4_html_8fb019c9369040bb.gif||class="img-thumbnail"]]
112
113 SM100 is always ON during the operation of the CPU module, so the usage method shown below will jump unconditionally.
114
115 (% style="text-align:center" %)
116 [[image:4_html_595b9dbff9fae7fc.png||class="img-thumbnail"]]
117
118 The pointer number P63 of LX3V represents the jump to the END instruction. The P63 pointer of LX5V no longer provides this function. If you need to use this function, please use the GOEND instruction.
119
120 **Error code**
121
122 No error message
123
124 **Example**
125
126 **(1) The situation to jump after OFF processing**
127
128 After one operation cycle when X023 changes from OFF to ON, the CJ P7 instruction is valid.
129
130 With this method, the output between CJ P7 instruction and mark P7 can be turned off before jumping.
131
132 (% style="text-align:center" %)
133 [[image:4_html_e09161008c47ac30.png||class="img-thumbnail"]]
134
135 **(2) CJ instruction and action of contact coil**
136
137 In the following program example, when X000 is ON, jump from the CJ instruction of the first loop to the mark P8. When X000 is OFF, no jump is performed, but the program is executed in order from step 1, and the CJ instruction in the 11th loop jumps to mark P9. The jumped instruction is not executed.
138
139 (((
140 (% style="text-align:center" %)
141 [[image:4_html_e0d34198cc559166.png||class="img-thumbnail"]]
142
143 Double-coil action of Y001 output:
144
145 When X000=OFF, it will act through X001.
146
147 When X000=ON, it will act through X012.
148
149 Even if the program is distinguished by conditional jump, if the same coil (Y000) is programmed twice or more within or outside the jump, it will be treated as normal double coil processing.
150
151 The action of the subroutine timer (T192 to T199):
152
153 After the coil is driven, the action continues even if it jumps, and the output contact also operates.
154
155 If using the high-speed counter (HSC0 to HSC7) operation
156
157 After the coil is driven, the action continues even if it jumps, and the output contact also operates.
158 )))
159
160 In the above program, if each input changes during the jump, the action of each coil is shown in the following table.
161
162 (% class="table-bordered" %)
163 |(% style="width:235px" %)**Content**|(% style="width:292px" %)**Contact state before jump**|(% style="width:549px" %)**Coil action in jump**
164 |(% rowspan="2" style="width:235px" %)(((
165 Y,M,S (Y1, M1, S1)
166 )))|(% style="width:292px" %)X1, X2, X3 OFF|(% style="width:549px" %)Y1, M1, S1 OFF
167 |(% style="width:292px" %)X1, X2, X3 ON|(% style="width:549px" %)Y1, M1, S1 ON
168 |(% rowspan="2" style="width:235px" %)(((
169 1ms, 10ms, 100ms timer (T0)
170 )))|(% style="width:292px" %)X4 OFF|(% style="width:549px" %)Timer not working
171 |(% style="width:292px" %)X4 ON|(% style="width:549px" %)Timer interrupt (continue after X0 OFF)
172 |(% rowspan="2" style="width:235px" %)(((
173 Program timer (T192)
174 )))|(% style="width:292px" %)X5 OFF, X6 OFF|(% style="width:549px" %)Timer not working, but the timer is reset when X13 is ON
175 |(% style="width:292px" %)X5 OFF, X6 ON|(% style="width:549px" %)Timing continues (contact action after X0 OFF)
176 |(% rowspan="2" style="width:235px" %)(((
177 Counter (C0)
178 )))|(% style="width:292px" %)X7 OFF, X10 OFF|(% style="width:549px" %){{id name="OLE_LINK160"/}}Counting interrupt, but it is reset when X13 is ON
179 |(% style="width:292px" %)X7 OFF, X10 ON|(% style="width:549px" %)Count interruption (continue after X0 OFF)
180 |(% rowspan="2" style="width:235px" %)(((
181 Application instructions
182
183 (MOV)
184 )))|(% style="width:292px" %)X11 OFF|(% rowspan="2" style="width:549px" %)(((
185 Single-cycle application instructions are not executed in the jump
186
187 Multi-cycle application instructions are partially executable (such as high-speed pulse instructions)
188 )))
189 |(% style="width:292px" %)X11 ON
190
191 **(3) The relationship between CJ instruction and MC to MCR jump**
192
193 The relationship between the main control instruction and the jump instruction and the action content are as follows.
194
195 However, since the operation of ②, ④, and ⑤ will become complicated, please avoid using them.
196
197 (% style="text-align:center" %)
198 [[image:4_html_679b6b2848540f73.png||class="img-thumbnail"]]
199
200 = {{id name="_Toc23403"/}}**Subroutine jump** =
201
202 == {{id name="_Toc12697"/}}**{{id name="_Toc7169"/}}{{id name="_Toc17038"/}}{{id name="_Toc102982430"/}}CALL/Subroutine call** ==
203
204 When the jump instruction is ON, the program with the specified pointer number in the same program file is executed.
205
206 -[CALL (P) (P)]
207
208 **Content, range and data type**
209
210 (% class="table-bordered" %)
211 |**Parameter**|**Content**|**Range**|**Data type**|**Data type (label)**
212 |(P)|Subroutine name|-|Pointer|POINTER
213
214 **Device used**
215
216 (% class="table-bordered" %)
217 |(% rowspan="2" %)**Instruction**|(% rowspan="2" %)**Parameter**|(((
218 **Offset modification**
219 )))|(% style="width:211px" %)(((
220 **Pulse extension**
221 )))|(% style="width:214px" %)**other**
222 |**[D]**|(% style="width:211px" %)**XXP**|(% style="width:214px" %)(((
223 **Subroutine name**
224 )))
225 |CALL|Parameter 1| |(% style="width:211px" %)●|(% style="width:214px" %)●
226
227 Parameter 1 can only use the subroutine name.
228
229 **Features**
230
231 When the CALL(P) instruction is executed, the subroutine of the pointer (P) will be executed. (P) can only write the name of the newly created subprogram, if the program name does not exist, the Circuit program compilation fails.
232
233 (% style="text-align:center" %)
234 [[image:4_html_8924f686c859efa4.png||class="img-thumbnail"]]
235
236 (% style="text-align:center" %)
237 [[image:4_html_60fa80c6a001beb0.gif||class="img-thumbnail"]]
238
239 CALL(P) instructions can be nested up to 32 levels.
240
241 (% style="text-align:center" %)
242 [[image:4_html_29c8e378dfb34066.png||class="img-thumbnail"]]
243
244 (% class="box infomessage" %)
245 (((
246 **✎Note: **
247
248 • Multiple CALL(P) instructions can call the same subprogram, but subprograms with the same program name are not allowed.
249
250 • Use program timers in subroutines (the same applies to interrupt programs). This timer counts when the coil instruction or the END instruction is executed. If it reaches the timer setting value, the output contact will act when the coil instruction or END instruction is executed. Generally, the timer only counts when the coil instruction is executed, so if it is used in a subroutine that executes the coil instruction under certain conditions, it will not count.
251
252 • If the 1ms accumulative timer is used in a subroutine (the same in an interrupt program), when it reaches the set value, the output contact will act when the first coil instruction is executed (when the subroutine is executed), so be careful.
253
254 • The devices that are turned on in the subprogram (the same in the interrupt program) will be retained after the program ends. Therefore, these devices should be reset in the main program after the end of the program.
255 )))
256
257 **Error code**
258
259 (% class="table-bordered" %)
260 |**Error code**|**Content**
261 |4102H|CALL(P) instruction exceeds 32 levels of nesting structure
262
263 **Example**
264
265 **(1) New subroutine**
266
267 Project management→Subroutine→Right click to create
268
269 (% style="text-align:center" %)
270 [[image:4_html_3d0d21476f0bb476.png||class="img-thumbnail"]]
271
272 **(2) Subroutine call**
273
274 (% style="text-align:center" %)
275 [[image:4_html_474fbc929fb22b37.png||class="img-thumbnail"]]
276
277 In the scan program, turn on M10 to call the subroutine SUB0, execute the Circuit program in the subroutine SUB0, until the END instruction of the subroutine is executed, return to the scan program MAIN to execute LD M11.
278
279 **(3) Subroutine nesting**
280
281 (% style="text-align:center" %)
282 [[image:4_html_d7bf03e5f06b73a8.png||class="img-thumbnail"]]
283
284 In the above figure, the subroutine SUB0 is called in the scan program, and the subroutine SUB1 is called in SUB0. So when the scan program M10 is turned on, after the CALL instruction is executed, the subroutine SUB0 will be executed first.And after the CALL instruction of SUB0 is executed, SUB1 will be executed first. After executing the END instruction of SUB1, return to SUB0 for execution. After executing the END instruction of SUB0, return to the scan program MAIN. The program has only 2 levels of nesting, and the number of nesting levels cannot be greater than 32.
285
286 = {{id name="_Toc8930"/}}**Interrupt disable, interrupt enable** =
287
288 == {{id name="_Toc102982432"/}}**DI and EI/Interrupt prohibited and allowed** ==
289
290 The CPU module is usually interrupt disabled. This instruction can make the CPU module into the interrupt enabled state (EI instruction), and then become disabled again (DI instruction).
291
292 • DI: It is forbidden to interrupt program execution.
293
294 • EI: Release the interrupt prohibition state.
295
296 -[DI (s)]
297
298 -[EI]
299
300 **Content, range and data type**
301
302 (% class="table-bordered" %)
303 |**Parameter**|**Content**|**Range**|**Data type**|**Data type (label)**
304 |(P)|Subroutine name|-|Pointer|POINTER
305
306 (% class="table-bordered" %)
307 |(% rowspan="2" %)**Instruction**|(% rowspan="2" %)**Parameter**|**Offset modification**|**Pulse extension**
308 |**[D]**|**XXP**
309 |DI|Parameter 1| |●
310
311 **{{id name="OLE_LINK161"/}}Features**
312
313 * DI
314
315 • Even if the execution interrupt condition is triggered in the program, prohibit the interrupt program execution before executing the EI instruction.
316
317 • When the PLC is powered on or after STOP, it will become the state after DI instruction is executed, and the interrupt program cannot be executed.
318
319 • The DI instruction can choose whether to use parameters. When there is no parameter, it means that all interrupt programs are prohibited. With parameters, according to the value in parameter s1, interrupt programs with this priority and lower priority are prohibited.
320
321 • The priority of the interrupt ranges from 0 to 2. The smaller the value, the higher the response priority of the interrupt. That is, the interrupt with priority 0 is the fastest to be responded.
322
323 • If there is no EI instruction before the DI instruction, the DI instruction is invalid.
324
325 * EI
326
327 • Release the interrupt prohibition state when DI instruction is executed, and allow interrupt program to run.
328
329 • When the EI and DI instructions are not enabled, they all maintain the original enabled or forbidden interrupt program execution status. The currently disabled interrupt priority can be viewed in SD151.
330
331 (% class="table-bordered" %)
332 |SD151|(% style="width:297px" %)Currently disabled interrupt priority|(% style="width:571px" %)(((
333 According to the interrupt prohibition instruction (DI instruction), the interrupt prohibition instruction (DI instruction) below the specified priority, and the interrupt enable instruction (EI instruction), the priority of the interrupt prohibition will be stored.
334
335 0: All priority interrupts are disabled (default);
336
337 1: Priority 1 and 2 interrupts are prohibited;
338
339 2: Priority 2 interrupt is prohibited;
340
341 3: All priority interrupts are allowed
342 )))|(% style="width:148px" %)R(read only)
343
344 A: Sequence control program
345
346 * DI, EI nested structure
347
348 (((
349 (1) Interrupt allowable intervals of all priority levels;
350
351 (2) Interrupt forbidden zone below priority 2 (interrupt allowable zone above priority 1);
352
353 (3) Interrupt forbidden interval below priority 1 (interrupt allowable interval above priority 0);
354
355 (4) Interrupt prohibition zone below priority 2 (interrupt enable zone above priority 1);
356
357 (5) Interrupt allowable intervals of all priority levels;
358
359 (6) EI paired with [DI K1];
360
361 (7) EI paired with [DI K2].
362
363 (% style="text-align:center" %)
364 [[image:4_html_a573e3db41c8e5e9.png||class="img-thumbnail"]]
365 )))
366
367 • Interrupts (requests) that occur after the DI instruction are processed after the EI instruction is executed.
368
369 • When the DI instruction is executed multiple times and the priority of the argument is specified to be higher than the priority currently being prohibited, interrupts below the priority of the argument are disabled.
370
371 • When the DI instruction is executed multiple times and the priority of the argument is specified to be lower than the priority currently being disabled, the interrupt disable status will not be changed.
372
373 • The nesting of DI instructions can be up to 16 levels.
374
375 • The interrupt priority of the interrupt pointer can be set by the properties of the interrupt program. Refer to the description of the interrupt program for details.
376
377 • The interrupt prohibition interval when DI instruction and EI instruction are executed is as follows.
378
379 **(1) When the DI instruction is executed multiple times (when the interrupt with priority higher than the currently prohibited interrupt priority is prohibited and specified)**
380
381 (% style="text-align:center" %)
382 [[image:4_html_c7e0f7f383d45a1b.png||class="img-thumbnail"]]
383
384 Scan execution type program
385
386 1. Interrupt allowable intervals of all priority levels;
387 1. Interrupt prohibition interval below priority 2 (interrupt allowable interval above priority 1);
388 1. Interrupt prohibition section below priority 1 (interrupt enable section above priority 0).
389
390 **(2) When the DI instruction is executed multiple times (when the interrupt priority is lower than the currently prohibited interrupt priority is prohibited and specified)**
391
392 (% style="text-align:center" %)
393 [[image:4_html_aad79b3250e8a24b.png||class="img-thumbnail"]]
394
395 Scan execution type program
396
397 1. Interrupt allowable intervals of all priority levels;
398 1. Interrupt prohibited interval below priority 1 (interrupt allowable interval above priority 0);
399 1. The interrupts below priority 1 are already in the disabled state, so the interrupt disable priority will not be changed.
400
401 **(3) When DI instruction is executed through interrupt program**
402
403 (% style="text-align:center" %)
404 [[image:4_html_a6d7521496fdd1f8.png||class="img-thumbnail"]]
405
406 A: Scan execution type program
407
408 B: interrupt program
409
410 1. Interrupt allowable intervals of all priority levels;
411 1. Interrupt prohibited interval below priority 3 (interrupt allowable interval above priority 1);
412 1. Interrupt prohibition section below priority 2 (interrupt enable section above priority 0).
413
414 **(4) When only DI instructions without arguments are executed**
415
416 (% style="text-align:center" %)
417 [[image:4_html_606dbe3d93909e42.png||class="img-thumbnail"]]
418
419 A: Scan execution type program
420
421 1. Interrupt allowable intervals of all priority levels;
422 1. Interrupt prohibition interval below priority 1 (all interrupt prohibition intervals);
423 1. Because the DI instruction with no argument is set to interrupt prohibition, by executing the EI instruction once, all priority interrupts are set to allow.
424
425 **(5) In the case of executing DI instructions with arguments and DI instructions without arguments (when executing in the order of DI instructions with arguments → DI instructions without arguments)**
426
427 (% style="text-align:center" %)
428 [[image:4_html_b9b528491258d0e4.png||class="img-thumbnail"]]
429
430 A: Scan execution type program
431
432 1. Interrupt allowable intervals of all priority levels;
433 1. Interrupt prohibition interval below priority 2 (interrupt allowable interval above priority 1);
434 1. Interrupt prohibition section below priority 1 (all interrupt prohibition sections).
435
436 **(6) In the case of executing DI instructions with arguments and DI instructions without arguments (in the case of execution in the order of DI instructions with no arguments → DI instructions with arguments)**
437
438 (% style="text-align:center" %)
439 [[image:4_html_622cf36b6bdc523.png||class="img-thumbnail"]]
440
441 {{id name="_Toc11636"/}}A: Scan execution type program
442
443 1. Interrupt allowable intervals of all priority levels;
444 1. Interrupt prohibition section below priority 1 (all interrupt prohibition sections).
445
446 **Error code**
447
448 (% class="table-bordered" %)
449 |**Error code**|**Content**
450 |4085H|(S) read address exceeds the device range
451 |4084H|The data set in (S) exceeds 0 to 2
452 |4185H|When the nesting of DI instructions exceeds 16 levels
453
454 **Example**
455
456 (((
457 (% style="text-align:center" %)
458 [[image:4_html_e068a061529263d1.png||class="img-thumbnail"]]
459
460 All interrupt programs can be triggered
461
462 Can trigger interrupt programs of priority 0 and priority 1
463
464 Can trigger interrupts with priority 0
465
466 Cannot trigger any interrupts
467
468 Can trigger an interrupt program with a priority of 0
469
470 Can trigger interrupt programs with priority 0 and priority 1
471 )))
472
473 == {{id name="_Toc2335"/}}**SIMASK/Interrupt mask** ==
474
475 Set interrupt pointer No. specified in (I) to the execution permission state/execution prohibition state according to the value of (s).
476
477 -[SIMASK (I) (s)]
478
479 **Content, range and data type**
480
481 (% class="table-bordered" %)
482 |**Parameter**|**Content**|**Range**|**Data type**|**Data type (label)**
483 |(I)|Interrupt program name|-|Program name|POINTER
484 |(s)|Specify the enable/disable of interrupt|0: Allow. 1: Prohibited|Signed BIN 16 bit|ANY16
485
486 **Device used**
487
488 (% class="table-bordered" %)
489 |(% rowspan="2" %)**Instruction**|(% rowspan="2" %)**Parameter**|(% colspan="12" %)**Devices**|(((
490 **Offset**
491
492 **modification**
493 )))|(((
494 **Pulse**
495
496 **extension**
497 )))
498 |**KnX**|**KnY**|**KnM**|**KnS**|**T**|**C**|**D**|**R**|**SD**|**K**|**H**|**E**|**[D]**|**XXP**
499 |(% rowspan="2" %)SIMASK|Parameter 1|(% colspan="12" %)Only support interrupt program name| |
500 |Parameter 2|●|●|●|●|●|●|●|●|●|●|●|●|●|
501
502 **Features**
503
504 • The interrupt program of the interrupt program name specified in (I) is set to the execution permission state/execution prohibited state according to the data specified in (s).
505
506 • When (s) is 0: Interrupt program execution permission status
507
508 • When (s) is 1, the execution of the interrupt program is prohibited
509
510 • Regarding the interrupt program when the power is turned on or after STOP→RUN, all interrupt programs will be executed.
511
512 • After setting interrupt prohibition, the prohibition state will be saved even if the instruction is disconnected. To restore it, write 0 to (S), turn on the instruction again, or execute STOP→RUN.
513
514 • The interrupted execution permission status/execution prohibition status will be stored in SM or SD, details as following:
515
516 **{{id name="_Toc10728"/}}(1) External interrupt**
517
518 (((
519 (% class="table-bordered" %)
520 |**Register**|**Content**|**Register**|**Content**|**Register**|**Content**|**Register**|**Content**
521 |SM352|X0 rising edge interrupt|SM356|X2 rising edge interrupt|SM360|X4 rising edge interrupt|SM364|X6 rising edge interrupt
522 |SM353|X0 falling edge interrupt|SM357|X2 falling edge interrupt|SM361|X4 falling edge interrupt|SM365|X6 falling edge interrupt
523 |SM354|X1 rising edge interrupt|SM358|X3 rising edge interrupt|SM362|X5 rising edge interrupt|SM366|X7 rising edge interrupt
524 |SM355|X1 falling edge interrupt|SM359|X3 falling edge interrupt|SM363|X5 falling edge interrupt|SM367|X7 falling edge interrupt
525 )))
526
527 **(2) Timer interrupt**
528
529 (% class="table-bordered" %)
530 |**Register**|**Content**
531 |SD350 to SD356|Timer interrupt mask, each bit represents an interrupt, a total of 100
532
533 **(3) High-speed counter interrupt**
534
535 (% class="table-bordered" %)
536 |**Register**|**Content**
537 |SD382 to SD388|high-speed counter interrupt mask, each bit represents an interrupt, a total of 100
538
539 **Error code**
540
541 (% class="table-bordered" %)
542 |**Error code**|**Content**
543 |4084H|Data beyond 0 and 1 is input in the application instruction(s)
544 |4085H|(S) in the read application instruction exceeds the device range
545 |4189H|The SIMASK instruction specifies an interrupt program name that is not set
546
547 **Example**
548
549 (((
550 (% style="text-align:center" %)
551 [[image:4_html_fd3e8efafb82209a.png||class="img-thumbnail"]]
552
553 As shown in the figure: when M10 is turned on, the three interrupt programs of INT10, INT91 and INT70 are prohibited from running.
554 )))
555
556 = {{id name="_Toc15333"/}}**Cycle instructions** =
557
558 == {{id name="_Toc102982435"/}}**FOR to NEXT/Cycle** ==
559
560 When the processing between the FOR to NEXT instruction is executed unconditionally (n) times, the next processing of the NEXT instruction will be performed.
561
562 (% style="text-align:center" %)
563 [[image:4_html_bdecdd2d7f545f5b.gif||class="img-thumbnail"]]
564
565 **Content, range and data type**
566
567 (% class="table-bordered" %)
568 |**Parameter**|**Content**|**Range**|**Data type**|**Data type (label)**
569 |(n)|Number of repetitions between FOR to NEXT instructions|1 to 32767|Signed BIN 16 bit|ANY16
570
571 (% class="table-bordered" %)
572 |(% rowspan="2" %)**Instruction**|(% rowspan="2" %)**Parameter**|(% colspan="12" %)**Devices**|(((
573 **Offset**
574
575 **modification**
576 )))|(((
577 **Pulse**
578
579 **extension**
580 )))
581 |**KnX**|**KnY**|**KnM**|**KnS**|**T**|**C**|**D**|**R**|**SD**|**K**|**H**|**E**|**[D]**|**XXP**
582 |FOR|Parameter 1|●|●|●|●|●|●|●|●|●|●|●|●|●|
583
584 **Features**
585
586 • When the processing between the FOR to NEXT instruction is executed unconditionally (n) times, the next processing of the NEXT instruction will be performed.
587
588 • (n) can be specified in the range of 1 to 32767. When specifying -32768 to 0, the same processing as (n)=1 will be performed.
589
590 • If you do not want to execute the processing between the FOR and NEXT instructions, use the CJ instruction to jump.
591
592 • The FOR instruction can be nested up to 5 levels.
593
594 **✎Note: **
595
596 • In the case of FOR to NEXT instruction programming with nesting between FOR to NEXT instructions, up to 5 levels can be achieved.
597
598 (% style="text-align:center" %)
599 [[image:4_html_df140146b29101ab.png||class="img-thumbnail"]]
600
601 • Do not use IRET, SRET, RET, FEND, END and other instructions to block between FOR to NEXT instructions.
602
603 • If the number of repetitions is too large, the cycle time (operation cycle) becomes longer and the watchdog timer error occurs, you need to change the watchdog timer time or reset the watchdog timer.
604
605 • The following program will become an error.
606
607 (% style="text-align:center" %)
608 [[image:4_html_3646fec26f307e30.gif||class="img-thumbnail"]]
609
610 • If the FOR to NEXT instruction is repeatedly executed and ends midway, use the BREAK instruction.
611
612 **Error code**
613
614 (% class="table-bordered" %)
615 |**Error code**|**Content**
616 |4085H|(s) read address exceeds the device range
617 |4100H|When the nesting of FOR to NEXT instructions exceeds 5 levels or the number of FOR to NEXT does not correspond
618
619 **Example**
620
621 (% style="text-align:center" %)
622 [[image:4_html_cf327fbe235812df.png||class="img-thumbnail"]]
623
624 The program INC D0 will be executed 10 times, and INC D1 will be executed 100 times.
625
626 After execution, D0 will be equal to 10 and D1 will be equal to 100.
627
628 == {{id name="_Toc102982436"/}}**BREAK/Break cycle** ==
629
630 When the processing between the FOR to NEXT instruction is executed unconditionally (n) times, the next processing of the NEXT instruction will be performed.
631
632 -[BREAK]
633
634 **Features**
635
636 • Forcibly end the repeated processing by FOR to NEXT instructions.
637
638 • This instruction can only be between FOR to NEXT, otherwise an operation error will be reported.
639
640 • The BREAK instruction can only jump out of the loop nesting structure where the instruction itself is located.
641
642 • When the contact is connected, the loop structure of the FOR to NEXT instruction where it is located is forced to end, as shown in the figure below.
643
644 (((
645 (% style="text-align:center" %)
646 [[image:4_html_c83826b59b86eb5a.png||class="img-thumbnail"]]
647
648 M0 turns ON, no matter how many cycles are left to execute, jump directly to step 35 to execute the program.
649
650 M4 turns ON, no matter how many loops are left to execute, jump directly to step 50 to execute the program.
651 )))
652
653 **Error code**
654
655 (% class="table-bordered" %)
656 |**Error code**|**Content**
657 |4186H|{{id name="OLE_LINK163"/}}BREAK instruction is not used between FOR to NEXT instructions
658
659 **Example**
660
661 (% style="text-align:center" %)
662 [[image:4_html_300cc2cbd41e93af.png||class="img-thumbnail"]]
663
664 The program INC D0 will be executed 10 times, and INC D1 will be executed 100 times.
665
666 When M0 is OFF, D0 will be equal to 10 and D1 will be equal to 100 after execution.
667
668 When M0 is ON, the BREAK instruction is executed, and the current loop is exited. The INC D1 instruction will not be executed, and the result D1=0.
669
670 = {{id name="_Toc21268"/}}**Master Control Instructions** =
671
672 == {{id name="_Toc102982438"/}}{{id name="_Toc25408"/}}{{id name="_Toc22131"/}}{{id name="_Toc6021"/}}**MC and MCR instructions** ==
673
674 • MC: Start main control.
675
676 • MCR: End the main control.
677
678 (% style="text-align:center" %)
679 [[image:4_html_6f51bb3cb7d2ba4f.png||class="img-thumbnail"]]
680
681 **Content, range and data type**
682
683 (% class="table-bordered" %)
684 |**Parameter**|**Content**|**Range**|**Data type**|**Data type (label)**
685 |(N)|Nested ID N|0 to 7|Signed BIN 16 bit|ANY16
686 |(d)|Device number that is turned ON|-|Bit|ANY_BOOL
687
688 (% class="table-bordered" %)
689 |(% rowspan="2" %)**Instruction**|(% rowspan="2" %)**Parameter**|(% colspan="12" %)**Devices**|**Offset modification**|**Pulse extension**
690 |**KnX**|**KnY**|**KnM**|**KnS**|**T**|**C**|**D**|**R**|**SD**|**K**|**H**|**E**|**[D]**|**XXP**
691 |(% rowspan="2" %)MC|Parameter1|(% colspan="12" %)Only use N0 to N7| |
692 |Parameter2|●|●|●|●|●|●|●|●|●|●|●|●| |
693 |MCR|Parameter1|(% colspan="12" %)Only use N0 to N7| |
694
695 **Features**
696
697 The main control instruction is used to create an efficient circuit program switching program by opening and closing the common bus of the circuit program.
698
699 The transition of ordinary Circuit program and master control Circuit program is as follows:
700
701 (((
702 (% style="text-align:center" %)
703 [[image:4_html_43089229889e1c0c.png||class="img-thumbnail"]]
704 )))
705
706 MC to MCR internal program, X0 must be open to execute
707
708 ■MC
709
710 • When the execution instruction of the MC instruction is turned on by the start of main control, the operation result from the start of the MC instruction to the MCR instruction is the execution result of the instruction (loop). When the MC execution instruction is OFF, the calculation results from the MC instruction to the MCR instruction are as follows.
711
712 (% class="table-bordered" %)
713 |**Devices**|**Device status**
714 |Timer|The count value becomes 0, and the coil and contact are all turned off.
715 |Counter, cumulative timer|The coil turns off, but the count value and contact remain in the current state.
716 |Devices in the OUT instruction|Forced to be OFF.
717 |(((
718 Devices in SET and RST instruction
719
720 Devices in basic and application instructions
721 )))|Keep the current state
722
723 • For MC instructions, the same nesting (N) number can be used multiple times by changing the device of (d).
724
725 • When the MC instruction is ON, the coil of the device specified in (d) will turn ON. In addition, when the same device is used in an OUT instruction, etc., it becomes a double coil. Therefore, the device specified in (d) must not be used in other instructions.
726
727 **Key points:**
728
729 If there are instructions that do not require contact (such as, FOR to NEXT instructions).If the instruction after MC can not affect the main CPU module, the instruction will execute.
730
731 ■MCR
732
733 • The release instruction of the main control indicates the end of the main control range.
734
735 • Do not add a contact instruction before the MCR instruction.
736
737 • When using, MC instruction and MCR instruction of the same nesting number should be used. However, when the MCR instruction has a nested structure concentrated in one position, all main controls can be terminated by the smallest number (N) number. (Refer to notes)
738
739 ■Nested structure
740
741 The main control instruction can be used through a nested structure. Each main control section is distinguished by nesting (N). N0 to N7 can be used for nesting.
742
743 By using the nested structure, it is possible to create a Circuit program that sequentially restricts the execution conditions of the program. The Circuit program using the nested structure is shown below.
744
745 (Left: Display of engineering tools, Right: Actual action loop)
746
747 (% style="text-align:center" %)
748 [[image:1652259670879-365.png||class="img-thumbnail"]]
749
750 1. Execute when A is ON;
751 1. Execute when A and B are ON;
752 1. Execute when A, B, C are ON;
753 1. It has nothing to do with A, B,
754
755 **✎Note: **
756
757 • If there is no instruction (LD, LDI, etc.) connected to the bus after the MC instruction, a program structure error occurs.
758
759 • MC to MCR instructions cannot be used in FOR to NEXT, STL to RET, subroutines, events, and interrupts. In addition, there cannot be instructions such as IRET, FEND, END, RET (SRET) inside MC to MCR to block.
760
761 • There can be up to 8 nests (N0 to N7). In the case of nesting, the MC instruction is used from the small number of nesting (N), while the MCR instruction is used from the old number. If the order is reversed, it does not become a nested structure, so the CPU module cannot operate normally.
762
763 • When the MCR instruction is a nested structure concentrated in one location, all main control can be ended by the smallest number (N) number.
764
765 **Error code**
766
767 No operation error
768
769 **Example**
770
771 (1) No nested structure
772
773 (((
774 (% style="text-align:center" %)
775 [[image:4_html_4f6cacf53f330135.png||class="img-thumbnail"]]
776
777 Main control program 1
778
779 Main control program 2
780 )))
781
782 The main control program 1 and the main control program 2 do not belong to the nested structure, so you can use N0 programming. There is no limit to the number of times N0 can be used in this case.
783
784 **(2) Nested structure**
785
786 When using the MC instruction, the number of nesting level N increases sequentially.(N0→ N1→ N2→ N3→ N4→ N5→ N6→ N7). When returning, use the MCR instruction to release from the larger nesting level. (N7→ N6→ N5→ N4→ N3→ N2→ N1 → N0).
787
788 For example, when MCR N6 and MCR N7 are not programmed, if MCR N5 is programmed, the nesting level will return to 5 at once.The nesting level can be programmed up to 8 levels (N7).
789
790 (((
791 (% style="text-align:center" %)
792 [[image:1652260093074-914.png||class="img-thumbnail"]]
793 )))
794
795 As shown above:
796
797 87 Walk: Level N0, Y0 will follow X1 state only when X0 is ON.
798
799 95 Walk: Level N1, Y1 will follow X3 state only when X0 and X2 are both ON.
800
801 103 Walk: Level N2, Y2 will follow X5 state only when X0, X2, and X4 are ON at the same time.
802
803 109 Walk: Level N1, use MCR N2 to return to level N1. Y3 will follow the state of X6 only when X0 and X2 are both ON.
804
805 115 walk: level N0, use MCR N1 to return to level N0. Y4 will follow the state of X7 only when X0 is ON.
806
807 121 Walk: Does not belong to the main control structure, has nothing to do with X0, X2, X4, Y5 follows the state change of X10.
808
809 = {{id name="_Toc16744"/}}**Watchdog reset** =
810
811 == {{id name="_Toc15927"/}}**WDT/watchdog timer** ==
812
813 The watchdog timer is reset by the program.
814
815 -[WDT]
816
817 **Features**
818
819 • Reset the watchdog timer through the program.
820
821 • Use when the scan time exceeds the set value of the watchdog timer depending on conditions.
822
823 • For t1 from step 0 to WDT instruction, and from WDT instruction to END instruction, do not exceed the set value of the watchdog timer.
824
825 (% style="text-align:center" %)
826 [[image:4_html_3341a4693ce1250c.png||class="img-thumbnail"]]
827
828 • The WDT instruction can be used more than twice in one scan.
829
830 **✎Note: **
831
832 • The watchdog timeout time can be set in the special register SD122. The default is 200ms.
833
834 • Use the special relay SM122 to control whether to turn on the watchdog timer function. The WDT instruction will be invalid after closing.
835
836 (% style="text-align:center" %)
837 [[image:4_html_21bc20f7ff159189.png||class="img-thumbnail"]]
838
839 (1) The watchdog timer time is set to 300ms;
840
841 (2)  Refresh the watchdog timer.
842
843 **Error code**
844
845 There is no operation error.
846
847 **Example**
848
849 (% style="text-align:center" %)
850 [[image:4_html_ceca3c411d993d90.png||class="img-thumbnail"]]
851
852 The FOR to NXET instruction loop takes a long scan period for many times, which may exceed the set watchdog timer 300ms, causing the PLC to report an error and cannot continue to run. After turning on M0, the WDT instruction will run, and the watchdog timer is updated every cycle , So that it will not report an error to execute the program normally.