Wiki source code of 04 Program Flow

Last modified by Wecon on 2025/09/03 21:02

Show last authors
1 == **Program Jump** ==
2
3 === **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 (% style="margin-left:auto; margin-right:auto" %)
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 |(% rowspan="2" %)**instruction**|(% rowspan="2" %)**Parameter**|(% colspan="24" %)**Devices**|(((
18 **Offset**
19
20 **modification**
21 )))|(((
22 **Pulse**
23
24 **extension**
25 )))|**other**
26 |**X**|**Y**|**M**|**S**|**SM**|**T(bit)**|**C(bit)**|**LC(bit)**|**HSC(bit)**|**D.b**|**KnX**|**KnY**|**KnM**|**KnS**|**T**|**C**|**D**|**R**|**SD**|**LC**|**HSC**|**K**|**H**|**E**|**[D]**|**XXP**|**P**
27 |CJ|Parameter 1| | | | | | | | | | | | | | | | | | | | | | | | | |●|●
28
29 **Features**
30
31 1. CJ(P)
32
33 When the execution instruction is ON, the program with the specified pointer number is executed.
34
35 When the execution instruction is OFF, execute the next program.
36
37 (% style="text-align:center" %)
38 [[image:88.png||height="170" width="367"]]
39
40 1. Execute instructions.
41 1. Each scan is executed.
42 1. One scan is executed.
43
44 {{info}}
45 **✎Note: **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 {{/info}}
47
48 When the OUT instruction is jumped by the CJ(P) instruction, the scan time will be shorter.
49
50 When the CJ(P) instruction is used to jump backward, the scan time will be longer.
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 (% style="text-align:center" %)
55 [[image:89.png||height="238" width="1177"]]
56
57 • The device skipped by the CJ(P) instruction does not change.
58
59 (% style="text-align:center" %)
60 [[image:90.png||height="255" width="1168"]]
61
62 • The label (P□) occupies 1 step.
63
64 (% style="text-align:center" %)
65 [[image:91.png||height="193" width="343"]]
66
67 The jump instruction can only specify the pointer number in the same program file.
68
69 When jumping to the pointer number within the jump range during jump operation, the program after the jump destination pointer number is executed.
70
71 The label procedure is shown below. When creating a loop program, move the cursor to the left of the bus bar of the ladder diagram, and enter the label (P) at the beginning of the loop block.
72
73 (% style="text-align:center" %)
74 [[image:92.png||height="253" width="361"]]
75
76 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.
77
78 (% style="text-align:center" %)
79 [[image:93.png||height="186" width="749"]]
80
81 When the pointer number in the operand is the same and the label is one, the operation is as follows.
82
83 (% style="text-align:center" %)
84 [[image:94.png]]
85
86 If the tag number is reused, it will become an error state.
87
88 (% style="text-align:center" %)
89 [[image:95.png||height="226" width="323"]]
90
91 SM100 is always ON during the operation of the CPU module, so the usage method shown below will jump unconditionally.
92
93 (% style="text-align:center" %)
94 [[image:96.png||height="221" width="353"]]
95
96 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.
97
98 **Error code**
99
100 No error message
101
102 **Example**
103
104 1) The situation to jump after OFF processing
105
106 After one operation cycle when X023 changes from OFF to ON, the CJ P7 instruction is valid.
107
108 With this method, the output between CJ P7 instruction and mark P7 can be turned off before jumping.
109
110 (% style="text-align:center" %)
111 [[image:97.png||height="251" width="377"]]
112
113 2)  CJ instruction and action of contact coil
114
115 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.
116
117 [[image:98.png||height="432" style="float:left" width="323"]]Double-coil action of Y001 output:
118
119 When X000=OFF, it will act through X001.
120
121 When X000=ON, it will act through X012.
122
123
124 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.
125
126 The action of the subroutine timer (T192 to T199):
127
128 After the coil is driven, the action continues even if it jumps, and the output contact also operates.
129
130
131 If using the high-speed counter (HSC0 to HSC7) operation
132
133 After the coil is driven, the action continues even if it jumps, and the output contact also operates.
134
135
136
137
138 In the above program, if each input changes during the jump, the action of each coil is shown in the following table.
139
140 (% style="margin-left:auto; margin-right:auto" %)
141 |=**Content**|=**Contact state before jump**|=**Coil action in jump**
142 |(% rowspan="2" %)(((
143 Y,M,S
144
145 (Y1, M1, S1)
146 )))|X1, X2, X3 OFF|Y1, M1, S1 OFF
147 |X1, X2, X3 ON|Y1, M1, S1 ON
148 |(% rowspan="2" %)(((
149 1ms, 10ms, 100ms timer
150
151 (T0)
152 )))|X4 OFF|Timer not working
153 |X4 ON|Timer interrupt (continue after X0 OFF)
154 |(% rowspan="2" %)(((
155 Program timer
156
157 (T192)
158 )))|X5 OFF, X6 OFF|Timer not working, but the timer is reset when X13 is ON
159 |X5 OFF, X6 ON|Timing continues (contact action after X0 OFF)
160 |(% rowspan="2" %)(((
161 Counter
162
163 (C0)
164 )))|X7 OFF, X10 OFF|Counting interrupt, but it is reset when X13 is ON
165 |X7 OFF, X10 ON|Count interruption (continue after X0 OFF)
166 |(% rowspan="2" %)(((
167 application instructions
168
169 (MOV)
170 )))|X11 OFF|(% rowspan="2" %)(((
171 Single-cycle application instructions are not executed in the jump
172
173 Multi-cycle application instructions are partially executable (such as high-speed pulse instructions)
174 )))
175 |X11 ON
176
177 3) The relationship between CJ instruction and MC to MCR jump
178
179 The relationship between the main control instruction and the jump instruction and the action content are as follows.
180
181 However, since the operation of ②, ④, and ⑤ will become complicated, please avoid using them.
182
183 (% style="text-align:center" %)
184 [[image:99.png||height="461" width="690"]]
185
186 == **Subroutine Jump** ==
187
188 ----
189
190 === **CALL/Subroutine Call** ===
191
192 ----
193
194 When the jump instruction is ON, the program with the specified pointer number in the same program file is executed.
195
196 -[CALL  (P) (P)]
197
198 **Content, range and data type**
199
200 (% style="margin-left:auto; margin-right:auto" %)
201 |=**Parameter**|=**Content**|=**Range**|=**Data type**|=**Data type (label)**
202 |(P)|Subroutine name|-|Pointer|POINTER
203
204 **Device used**
205
206 |(% rowspan="2" %)**instruction**|(% rowspan="2" %)**Parameter**|(% colspan="24" %)**Devices**|(((
207 **Offset**
208
209 **modification**
210 )))|(((
211 **Pulse**
212
213 **extension**
214 )))|**other**
215 |**X**|**Y**|**M**|**S**|**SM**|**T(bit)**|**C(bit)**|**LC(bit)**|**HSC(bit)**|**D.b**|**KnX**|**KnY**|**KnM**|**KnS**|**T**|**C**|**D**|**R**|**SD**|**LC**|**HSC**|**K**|**H**|**E**|**[D]**|**XXP**|(((
216 **Subroutine**
217
218 **name**
219 )))
220 |CALL|Parameter 1| | | | | | | | | | | | | | | | | | | | | | | | | |●|●
221
222 Parameter 1 can only use the subroutine name.
223
224 **Features**
225
226 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 ladder diagram compilation fails.
227
228 (% style="text-align:center" %)
229 [[image:100.png]]
230
231 (% style="text-align:center" %)
232 [[image:101.png||height="203" width="397"]]
233
234 CALL(P) instructions can be nested up to 32 levels.
235
236 (% style="text-align:center" %)
237 [[image:102.png||height="180" width="517"]]
238
239 {{info}}
240 **✎Note: **
241
242 • Multiple CALL(P) instructions can call the same subprogram, but subprograms with the same program name are not allowed.
243
244 • 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.
245
246 • 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.
247
248 • 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.
249 {{/info}}
250
251
252 **Error code**
253
254 (% style="margin-left:auto; margin-right:auto" %)
255 |=**Error code**|=**Content**
256 |4102H|CALL(P) instruction exceeds 32 levels of nesting structure
257
258 **Example**
259
260 1) New subroutine
261
262 Project management→Subroutine→ Scan→Right click to create
263
264 (% style="text-align:center" %)
265 [[image:103.png||height="316" width="254"]]
266
267 2) Subroutine call
268
269 [[image:104.png||height="360" style="float:left" width="531"]][[image:105.png||height="342" style="float:right" width="798"]]
270
271
272
273
274
275
276
277
278
279
280
281
282
283 In the scan program, turn on M10 to call the subroutine SUB0, execute the ladder diagram in the subroutine SUB0, until the END instruction of the subroutine is executed, return to the scan program MAIN to execute LD M11.
284
285 3Z) Subroutine nesting
286
287 (% style="text-align:center" %)
288 [[image:106.png||height="156" width="346"]]
289
290 (% style="text-align:center" %)
291 [[image:107.png]]
292
293 (% style="text-align:center" %)
294 [[image:108.png||height="164" width="346"]]
295
296 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.
297
298 == **Interrupt Disable, Interrupt Enable** ==
299
300 ----
301
302 === **DI and EI/Interrupt Prohibited and Allowed** ===
303
304 ----
305
306 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).
307
308 • DI: It is forbidden to interrupt program execution.
309
310 • EI: Release the interrupt prohibition state.
311
312 -[DI (s)]
313
314 -[EI]
315
316 **Content, range and data type**
317
318 (% style="margin-left:auto; margin-right:auto" %)
319 |=**Parameter**|=**Content**|=**Range**|=**Data type**|=**Data type (label)**
320 |(P)|Subroutine name|-|Pointer|POINTER
321
322 |(% rowspan="2" %)**instruction**|(% rowspan="2" %)**Parameter**|(% colspan="24" %)**Devices**|**Offset modification**|**Pulse extension**
323 |**X**|**Y**|**M**|**S**|**SM**|**T(bit)**|**C(bit)**|**LC(bit)**|**HSC(bit)**|**D.b**|**KnX**|**KnY**|**KnM**|**KnS**|**T**|**C**|**D**|**R**|**SD**|**LC**|**HSC**|**K**|**H**|**E**|**[D]**|**XXP**
324 |DI|Parameter 1| | | | | | | | | | | | | | | | | | | | | | | | | |●
325
326 **Features**
327
328 * DI
329
330 • Even if the execution interrupt condition is triggered in the program, prohibit the interrupt program execution before executing the EI instruction.
331
332 • 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.
333
334 • 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.
335
336 • 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.
337
338 • If there is no EI instruction before the DI instruction, the DI instruction is invalid.
339
340 * EI
341
342 • Release the interrupt prohibition state when DI instruction is executed, and allow interrupt program to run.
343
344 • 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.
345
346 (% style="margin-left:auto; margin-right:auto" %)
347 |=(% scope="row" %)SD151|Currently disabled interrupt priority|(((
348 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.
349
350 0: All priority interrupts are disabled (default);
351
352 1: Priority 1 and 2 interrupts are prohibited;
353
354 2: Priority 2 interrupt is prohibited;
355
356 3: All priority interrupts are allowed
357 )))|R(read only)
358
359 * DI, EI nested structure
360
361 [[image:109.png||height="290" style="float:left" width="391"]]A: Sequence control program
362
363 (1) Interrupt allowable intervals of all priority levels;
364
365 (2) Interrupt forbidden zone below priority 2 (interrupt allowable zone above priority 1);
366
367 (3) Interrupt forbidden interval below priority 1 (interrupt allowable interval above priority 0);
368
369 (4) Interrupt prohibition zone below priority 2 (interrupt enable zone above priority 1);
370
371 (5) Interrupt allowable intervals of all priority levels;
372
373 (6) EI paired with [DI K1];
374
375 (7) EI paired with [DI K2].
376
377 • Interrupts (requests) that occur after the DI instruction are processed after the EI instruction is executed.
378
379 • 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.
380
381 • 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.
382
383 • The nesting of DI instructions can be up to 16 levels.
384
385 • 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.
386
387 • The interrupt prohibition interval when DI instruction and EI instruction are executed is as follows.
388
389 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)
390
391 (% style="text-align:center" %)
392 [[image:110.png]]
393
394 Scan execution type program
395
396 1. Interrupt allowable intervals of all priority levels;
397 1. Interrupt prohibition interval below priority 2 (interrupt allowable interval above priority 1);
398 1. Interrupt prohibition section below priority 1 (interrupt enable section above priority 0).
399
400 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)
401
402 (% style="text-align:center" %)
403 [[image:111.png]]
404
405 Scan execution type program
406
407 1. Interrupt allowable intervals of all priority levels;
408 1. Interrupt prohibited interval below priority 1 (interrupt allowable interval above priority 0);
409 1. The interrupts below priority 1 are already in the disabled state, so the interrupt disable priority will not be changed.
410
411 3)  When DI instruction is executed through interrupt program
412
413 (% style="text-align:center" %)
414 [[image:112.png||height="155" width="517"]]
415
416 A: Scan execution type program
417
418 B: interrupt program
419
420 1. Interrupt allowable intervals of all priority levels;
421 1. Interrupt prohibited interval below priority 3 (interrupt allowable interval above priority 1);
422 1. Interrupt prohibition section below priority 2 (interrupt enable section above priority 0).
423
424 4)  When only DI instructions without arguments are executed
425
426 (% style="text-align:center" %)
427 [[image:113.png]]
428
429 A: Scan execution type program
430
431 1. Interrupt allowable intervals of all priority levels;
432 1. Interrupt prohibition interval below priority 1 (all interrupt prohibition intervals);
433 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.
434
435 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)
436
437 (% style="text-align:center" %)
438 [[image:114.png]]
439
440 A: Scan execution type program
441
442 * Interrupt allowable intervals of all priority levels;
443 * Interrupt prohibition interval below priority 2 (interrupt allowable interval above priority 1);
444 * Interrupt prohibition section below priority 1 (all interrupt prohibition sections)
445
446 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)
447
448 (% style="text-align:center" %)
449 [[image:115.png]]
450
451 A: Scan execution type program
452
453 * Interrupt allowable intervals of all priority levels;
454 * Interrupt prohibition section below priority 1 (all interrupt prohibition sections).
455
456 **Error code**
457
458 |**Error code**|**Content**
459 |4085H|(S) read address exceeds the device range
460 |4084H|The data set in (S) exceeds 0 to 2
461 |4185H|When the nesting of DI instructions exceeds 16 levels
462
463 **Example**
464
465 (% style="text-align:center" %)
466 [[image:116.png]]
467
468 All interrupt programs can be triggered
469
470
471 Can trigger interrupt programs of priority 0 and priority 1
472
473
474 Can trigger interrupts with priority 0
475
476
477 Cannot trigger any interrupts
478
479
480 Can trigger an interrupt program with a priority of 0
481
482
483 Can trigger interrupt programs with priority 0 and priority 1
484
485
486
487 === **SIMASK/Interrupt Mask** ===
488
489 ----
490
491 Set interrupt pointer No. specified in (I) to the execution permission state/execution prohibition state according to the value of (s).
492
493 -[SIMASK (I)  (s)]
494
495 **Content, range and data type**
496
497 (% style="margin-left:auto; margin-right:auto" %)
498 |=**Parameter**|=**Content**|=**Range**|=**Data type**|=**Data type (label)**
499 |(I)|Interrupt program name|-|Program name|POINTER
500 |(s)|Specify the enable/disable of interrupt|0: Allow. 1: Prohibited|Signed BIN 16 bit|ANY16
501
502 **Device used**
503
504 |(% rowspan="2" %)**instruction**|(% rowspan="2" %)**Parameter**|(% colspan="24" %)**Devices**|(((
505 **Offset**
506
507 **modification**
508 )))|(((
509 **Pulse**
510
511 **extension**
512 )))
513 |**X**|**Y**|**M**|**S**|**SM**|**T(bit)**|**C(bit)**|**LC(bit)**|**HSC(bit)**|**D.b**|**KnX**|**KnY**|**KnM**|**KnS**|**T**|**C**|**D**|**R**|**SD**|**LC**|**HSC**|**K**|**H**|**E**|**[D]**|**XXP**
514 |(% rowspan="2" %)SIMASK|Parameter 1|(% colspan="24" %)Only support interrupt program name| |
515 |Parameter 2| | | | | | | | | | |●|●|●|●|●|●|●|●|●| | |●|●|●|●|
516
517 **Features**
518
519 • 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).
520
521 • When (s) is 0: Interrupt program execution permission status
522
523 • When (s) is 1, the execution of the interrupt program is prohibited
524
525 • Regarding the interrupt program when the power is turned on or after STOP→RUN, all interrupt programs will be executed.
526
527 • 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.
528
529 • The interrupted execution permission status/execution prohibition status will be stored in SM or SD, details as following:
530
531 (1)  External Interrupt
532
533 (% style="margin-left:auto; margin-right:auto" %)
534 |=**Register**|=**Content**|=**Register**|=**Content**|=**Register**|=**Content**|=**Register**|=**Content**
535 |SM352|X0 rising edge interrupt|SM356|X2 rising edge interrupt|SM360|X4 rising edge interrupt|SM364|X6 rising edge interrupt
536 |SM353|X0 falling edge interrupt|SM357|X2 falling edge interrupt|SM361|X4 falling edge interrupt|SM365|X6 falling edge interrupt
537 |SM354|X1 rising edge interrupt|SM358|X3 rising edge interrupt|SM362|X5 rising edge interrupt|SM366|X7 rising edge interrupt
538 |SM355|X1 falling edge interrupt|SM359|X3 falling edge interrupt|SM363|X5 falling edge interrupt|SM367|X7 falling edge interrupt
539
540 (2) Timer interrupt
541
542 (% style="margin-left:auto; margin-right:auto" %)
543 |=**Register**|=**Content**
544 |SD350 to SD356|Timer interrupt mask, each bit represents an interrupt, a total of 100
545
546 (3) High-speed counter interrupt
547
548 (% style="margin-left:auto; margin-right:auto" %)
549 |=**Register**|=**Content**
550 |SD382 to SD388|high-speed counter interrupt mask, each bit represents an interrupt, a total of 100
551
552 **Error code**
553
554 (% style="margin-left:auto; margin-right:auto" %)
555 |=**Error code**|=**Content**
556 |4084H|Data beyond 0 and 1 is input in the application instruction(s)
557 |4085H|(S) in the read application instruction exceeds the device range
558 |4189H|The SIMASK instruction specifies an interrupt program name that is not set
559
560 **Example**
561
562 (% style="text-align:center" %)
563 [[image:117.png]]
564
565
566
567 As shown in the figure: when M10 is turned on, the three interrupt programs of INT10, INT91 and INT70 are prohibited from running.
568
569
570
571
572 == **Cycle instructions** ==
573
574 ----
575
576 === **FOR to NEXT/Cycle** ===
577
578 ----
579
580 When the processing between the FOR to NEXT instruction is executed unconditionally (n) times, the next processing of the NEXT instruction will be performed.
581
582 (% style="text-align:center" %)
583 [[image:118.png]]
584
585 **Content, range and data type**
586
587 (% style="margin-left:auto; margin-right:auto" %)
588 |=**Parameter**|=**Content**|=**Range**|=**Data type**|=**Data type (label)**
589 |(n)|Number of repetitions between FOR to NEXT instructions|1 to 32767|Signed BIN 16 bit|ANY16
590
591 |(% rowspan="2" %)**instruction**|(% rowspan="2" %)**Parameter**|(% colspan="24" %)**Devices**|(((
592 **Offset**
593
594 **modification**
595 )))|(((
596 **Pulse**
597
598 **extension**
599 )))
600 |**X**|**Y**|**M**|**S**|**SM**|**T(bit)**|**C(bit)**|**LC(bit)**|**HSC(bit)**|**D.b**|**KnX**|**KnY**|**KnM**|**KnS**|**T**|**C**|**D**|**R**|**SD**|**LC**|**HSC**|**K**|**H**|**E**|**[D]**|**XXP**
601 |FOR|Parameter 1| | | | | | | | | | |●|●|●|●|●|●|●|●|●| | |●|●|●|●|
602
603 **Features**
604
605 • When the processing between the FOR to NEXT instruction is executed unconditionally (n) times, the next processing of the NEXT instruction will be performed.
606
607 • (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.
608
609 • If you do not want to execute the processing between the FOR and NEXT instructions, use the CJ instruction to jump.
610
611 • The FOR instruction can be nested up to 5 levels.
612
613 {{info}}
614 **✎Note: **In the case of FOR to NEXT instruction programming with nesting between FOR to NEXT instructions, up to 5 levels can be achieved.
615 {{/info}}
616
617 (% style="text-align:center" %)
618 [[image:119.png||height="225" width="583"]]
619
620 • Do not use IRET, SRET, RET, FEND, END and other instructions to block between FOR to NEXT instructions.
621
622 • 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.
623
624 • The following program will become an error.
625
626 (% style="text-align:center" %)
627 [[image:120.png||height="403" width="836"]]
628
629 • If the FOR to NEXT instruction is repeatedly executed and ends midway, use the BREAK instruction.
630
631 **Error code**
632
633 (% style="margin-left:auto; margin-right:auto" %)
634 |=**Error code**|=**Content**
635 |4085H|(s) read address exceeds the device range
636 |4100H|When the nesting of FOR to NEXT instructions exceeds 5 levels or the number of FOR to NEXT does not correspond
637
638 **Example**
639
640 (% style="text-align:center" %)
641 [[image:121.png]]
642
643 The program INC D0 will be executed 10 times, and INC D1 will be executed 100 times.
644
645 After execution, D0 will be equal to 10 and D1 will be equal to 100.
646
647 === **BREAK/Break Cycle** ===
648
649 ----
650
651 When the processing between the FOR to NEXT instruction is executed unconditionally (n) times, the next processing of the NEXT instruction will be performed.
652
653 -[BREAK]
654
655 **Features**
656
657 • Forcibly end the repeated processing by FOR to NEXT instructions.                                                               
658
659 • This instruction can only be between FOR to NEXT, otherwise an operation error will be reported.
660
661 • The BREAK instruction can only jump out of the loop nesting structure where the instruction itself is located.
662
663 • 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.
664
665 [[image:122.png||style="float:left"]]
666
667
668 When M0 is set to ON, no matter how many cycles are left, it will directly jump to the seventh grid to execute the program.
669
670
671
672
673
674
675 When M4 is set to ON, no matter how many cycles are left, it will directly jump to the tenth grid to execute the program.
676
677
678
679
680
681
682
683 **Error code**
684
685 (% style="margin-left:auto; margin-right:auto" %)
686 |=**Error code**|=**Content**
687 |4186H|BREAK instruction is not used between FOR to NEXT instructions
688
689 **Example**
690
691 (% style="text-align:center" %)
692 [[image:123.png]]
693
694 The program INC D0 will be executed 10 times, and INC D1 will be executed 100 times.
695
696 When M0 is OFF, D0 will be equal to 10 and D1 will be equal to 100 after execution.
697
698 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.
699
700 == **Watchdog Reset** ==
701
702 ----
703
704 === **WDT/Watchdog Timer** ===
705
706 ----
707
708 The watchdog timer is reset by the program.
709
710 -[WDT]
711
712 **Features**
713
714 • Reset the watchdog timer through the program.
715
716 • Use when the scan time exceeds the set value of the watchdog timer depending on conditions.
717
718 • 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.
719
720 (% style="text-align:center" %)
721 [[image:124.png||height="200" width="631"]]
722
723 • The WDT instruction can be used more than twice in one scan.
724
725 {{info}}
726 **✎Note: **
727
728 • The watchdog timeout time can be set in the special register SD122. The default is 200ms.
729
730 • Use the special relay SM122 to control whether to turn on the watchdog timer function. The WDT instruction will be invalid after closing.
731 {{/info}}
732
733 (% style="text-align:center" %)
734 [[image:125.png||height="97" width="368"]]
735
736 1. The watchdog timer time is set to 300ms;
737 1. Refresh the watching timer.
738
739 **Error code**
740
741 There is no operation error.
742
743 **Example**
744
745 (% style="text-align:center" %)
746 [[image:126.png]]
747
748 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.
749
750
751
752