Wiki source code of 01 Program execution

Version 12.1 by Stone Wu on 2022/07/28 16:43

Show last authors
1 = Scan structure =
2
3 The scan configuration of the CPU module is as follows.
4
5 (% style="text-align:center" %)
6 [[image:1-1.png||height="455" width="700" class="img-thumbnail"]]
7
8 == Initialization ==
9
10 The initialization based on the status of the CPU module is as follows.
11
12 **√**: execute. **×**: not execute
13
14 (% class="table-bordered" %)
15 |(% rowspan="2" %)**Processing item**|(% colspan="3" %)**Status of the CPU module**
16 |**When the power is ON**|**STOP**|**When STOP RUN**
17 |Initialization of input and output modules|√|×|×
18 |CPU parameter check|√|×|×
19 |Check of system parameters|√|×|×
20 |Device initialization|√|×|√
21 |Error clear|√|×|√
22
23 == Input and output point refresh ==
24
25 Perform the following before starting program calculation.      
26
27 Update the actual input point of the PLC to the input relay X.
28
29 The following is executed after the END instruction is executed.
30
31 Update the PLC output relay Y to the actual output point.
32
33 **Key points**
34
35 When performing a constant scan, the I/O refresh is performed after the waiting time of the constant scan.
36
37 == Operation of the program ==
38
39 According to the program setting, the execution starts from step 0 of each program to the END instruction. This program is called the main program.
40
41 == END processing ==
42
43 Perform the following processing.
44
45 * Completion processing of partial instructions
46 * Watchdog timer reset
47 * Communication processing
48 * Setting the value of special relay/special register (when the setting timing is END processing)
49
50 = Scan time =
51
52 The CPU module repeats the following processing, and the scan time is the total of the following processing and execution time.
53
54 (% style="text-align:center" %)
55 [[image:1-2.png||height="349" width="400" class="img-thumbnail"]]
56
57 The initial scan time indicates the time including this processing.      
58
59 == Initial scan time ==
60
61 It is the first scan time of the CPU module in RUN.
62
63 Process as the following way:
64
65 The value stored in SD134 (initial scan time (ms unit)) and SD135 (initial scan time (s unit)).
66
67 = The flow of each procedure =
68
69 When the CPU module changes to the RUN state, the programs are executed in sequence according to the program execution type and execution sequence settings.
70
71 (% style="text-align:center" %)
72 [[image:1652241271896-263.png||height="344" width="500" class="img-thumbnail"]]
73
74 **Key points**
75
76 When the execution types of the programs are the same, they are executed in the order set in the execution order.
77
78 **✎Note:**
79
80 When executing instructions that can be completed with multiple cycles (such as OUT T, RAMP, RS, etc.), they should be programmed in the scan program. If it is used in event execution type programs and mid-stage execution type programs, these instructions may not be executed in multiple scan cycles, causing actual results to be different from the ideal results. Therefore, unless events, interrupts and subroutines can be executed in each scan cycle. It is not recommended to use multi-cycle execution instructions in other situations.
81
82 = Types of program execution =
83
84 == Scan execution program ==
85
86 Each scan is executed only once from the next scan of the initial execution type program.
87
88 (% style="text-align:center" %)
89 [[image:1-4.png||height="325" width="700" class="img-thumbnail"]]
90
91 When multiple scan execution type programs are executed, the execution time of the scan execution type program is the time until all scan execution type programs are executed. In addition, before the execution of the scan execution type program is completed, if an interrupt program/event execution type program/subroutine is executed, the execution time will also be included.
92
93 **Creation of multiple scanners**
94
95 "Project Management"→ "Program"→ "Scan"→ Right click to create
96
97 (% style="text-align:center" %)
98 [[image:1-5.png||height="372" width="300" class="img-thumbnail"]]
99
100 * Scan the program name: the program name requires to match case, and the program name cannot use the same name with device name (the device name does not match case).
101 * The input of /%$@&=to`^<>?:{}[],;!*.~\~\'" is not supported. It cannot exceed 64 characters. The default name is MAINx.
102 * The number of scan programs that can be built is limited to 100.
103 * Each scan program has been END ended, but only the last END instruction is completed to calculate a scan cycle.
104 * The execution sequence runs from top to bottom in the order of creation.
105
106 (% style="text-align:center" %)
107 [[image:1-6.png||class="img-thumbnail"]]
108
109 == Event execution program ==
110
111 It uses the event specified by the user as a condition to trigger the program to start execution.
112
113 (% style="text-align:center" %)
114 [[image:1-7.png||class="img-thumbnail"]]
115
116 **Trigger type**
117
118 The trigger of event execution type program is as follows.
119
120 **(1) ON event of bit data (TRUE)**
121
122 * After the ON event is specified, if the contact that sets the trigger condition in the ON event is turned ON during the scan program, the ON event program will be executed in the scan program page*1 or before the END instruction is executed.
123 * The ON event program will only be executed once in a single scan cycle.
124 * After the ON event is executed, you can set whether to clear the current value of the output (Y) and timer (T) used in the program.
125
126 *1: Scan program paging: multiple scan programs are established, and each scan program is called a paging. After scan program A is executed, before scan program B is executed, it will be judged whether an event program needs to be executed.
127
128 (% style="text-align:center" %)
129 [[image:1652247397997-492.png||class="img-thumbnail"]]
130
131 When it is the turn of the execution sequence of event execution type program C and Y50 is ON, the program is executed.
132
133 The devices that can be specified are as follows.
134
135 (% class="table-bordered" %)
136 |(% colspan="2" %)**Project**|**Content**
137 |(% rowspan="2" %)Device *1|Bit Device|X, Y, M, SM
138 |Bit specification of word device|D.b
139
140 *1 The indexed device cannot be specified.
141
142 **(2) TIME event**
143
144 After the program is to RUN state and the specified time has elapsed, event is executed one time when it comes to the execution sequence of the first corresponding program. For the second and subsequent executions, the time is re-measured from the start of the last event execution type program. After the specified time has elapsed, the program is executed repeatedly when it comes to the execution sequence of the first corresponding program. In addition, in the next scan after the corresponding program is executed, the current value of the output (Y) and timer (T) used in the corresponding program can be cleared. It can be used for programs that do not need to respond in a fixed period of time.
145
146 (% style="text-align:center" %)
147 [[image:1652247622598-446.png||class="img-thumbnail"]]
148
149 After the specified time has elapsed, when it comes to the first execution sequence, the event execution type program C is executed.
150
151 **Key points**
152
153 When set to clear the current value of output and timer, and the scan time is longer than the set value of elapsed time, the current value of output and timer will not be cleared.
154
155 **Operational steps**
156
157 **1)New event**
158
159 Project management→ Program→ Event → Right click to create.
160
161 (% style="text-align:center" %)
162 [[image:1-10 E.png||class="img-thumbnail"]]
163
164 Event program name:
165
166 * The program name requires to match case, and the program name with the same name as the device cannot be used (the device name does not match case).
167 * The program name does not support /%$@&=to`^<>?:{}[],;!*.~\~\'" character input.
168 * The length of the program name cannot exceed 64 characters. The default name is EVENTx.
169
170 A maximum of 100 new event programs could be created.
171
172 **2) Execution type**
173
174 There are two ways to configure the event execution type:
175
176 1. Configure when creating a new event program, as shown in the figure above.w
177 1. Project management→ Program→ Parameter → Program parameter→Configuration
178
179 (% style="text-align:center" %)
180 [[image:1-11.png||height="419" width="500" class="img-thumbnail"]]
181
182 Configuration instructions:
183
184 1) Configuration interface
185
186 (% style="text-align:center" %)
187 [[image:1-12.png||height="372" width="300" class="img-thumbnail"]]
188
189 2) Parameter content:
190
191 (% class="table-bordered" %)
192 |(% colspan="2" %)**Project**|**Content**|**Setting range**|**Default**
193 |(% colspan="2" %)Execution type|Select event type|Not set/ON event/TIME event|Not set
194 |(% rowspan="2" %)ON event|Contact|The event type can be set when ON event is selected. Set the bit device as the trigger condition.|X/Y/M/SM/D.b|
195 |Whether to clear|When the bit device of the trigger condition set by the ON event is turned OFF, whether to clear the current value of the output (Y) and timer (T) used in the execution program of the ON event in the next cycle.|(((
196 True
197
198 False
199 )))|False
200 |(% rowspan="2" %)TIME event|Time|Set how long to execute the event program once.|1 to 2147483647 (100us unit)|
201 |Whether to clear|When the TIME event is executed, if the event is not executed in the next scan cycle, select whether to clear the output (Y) used in the TIME event execution program and the current value of the timer (T).|(((
202 True
203
204 False
205 )))|False
206
207 **Key points**
208
209 When "ON event" or "TIME event" is specified, if "Clear or not" is set to "Clear", the event program will not be executed in one scan cycle, and all the internal outputs (Y) and current value of timer (T) will all be cleared (except for the cumulative type and subroutine type T). If the time set by the TIME event is less than the scan period, it is equivalent to executing the TIME event every scan period. Even if the clear output is set, the output and timer data in the event program will not be cleared.
210
211 == Interrupt execution program ==
212
213 In the process of executing the scan program, the program that can interrupt the priority execution of the scan program is called an interrupt execution program.
214
215 ~1. When an interrupt cause occurs, the interrupt program corresponding to the interrupt pointer number will be executed. However, the execution needs to be set to the interrupt enabled state by the EI instruction.
216
217 (% style="text-align:center" %)
218 [[image:1652249587490-678.png||class="img-thumbnail"]]
219
220
221 2. An interrupt name corresponds to an interrupt program, and the interrupt name cannot be repeated. Each interrupt has its own trigger condition and execution program, and each interrupt program ends with END.
222
223 3. Interrupt has the characteristic of interrupting the original execution program and executing the interrupt first, but it cannot interrupt the interrupt program being executed.
224
225 4. The interrupt program has the concept of priority. The smaller the priority value, the more priority the response. The priority setting range is 0 to 2.
226
227 The actions when an interruption cause occurs are as follows:
228
229 1. Interrupt prohibition (DI) when an interruption cause occurs.
230
231 If the interrupt execution condition is triggered in a program that is forbidden by DI, the interrupt will not be executed. Even if the subsequent program uses the EI instruction to allow interruption, the previously shielded interrupt program will not be executed. Only the interrupt execution condition is triggered again. The interrupt program will be executed.
232
233 2.When multiple interrupt causes occur simultaneously in the interrupt enabled state.
234
235 The interrupt program with higher priority will be executed sequentially. In addition, when multiple interrupts with the same priority occur at the same time, the actions are executed in the order of interrupt priority.
236
237 If three interrupt programs I0, I10, I16 are created, the priority of I0 is 1, the priority of I10 is 0, and the priority of I16 is 1. The execution logic is shown in the figure below: I10 has the smallest priority and is executed first; I0 and I16 have the same priority and are executed in the order of program establishment.
238
239 (% style="text-align:center" %)
240 [[image:1652249553246-688.png||class="img-thumbnail"]]
241
242 3. When an interrupt occurs during the waiting time when performing constant scan.
243
244 Execute the interrupt program for this interrupt.
245
246 4.When other interrupts occur during the execution of the interrupt program.
247
248 In the interrupt program (including the specification when the interrupt occurs in the event execution program), when other interrupts occur, the original interrupt execution program will not be interrupted. After the original interrupt execution program is completed, the new interrupt program is executed. After the execution is completed Then return to the scanning procedure.
249
250 5. During the execution of the interrupt program, when an interrupt cause with a low priority or the same priority occurs.
251
252 The interruption cause that occurred is stored, and after the interrupt program in execution ends, the interrupt program corresponding to the stored interruption cause is executed. Even if the same interruption cause occurs multiple times, the interruption cause is stored only once.
253
254
255 (% style="text-align:center" %)
256 [[image:1652249673420-476.png||class="img-thumbnail"]]
257
258 6. When the same interruption cause occurs during the execution of the interrupt program;
259
260 The interruption cause that occurred is stored, and after the interrupt program in execution ends, the interrupt program corresponding to the stored interruption cause is executed. Even if the same interruption cause occurs multiple times, the interruption cause is stored only once.
261
262 **Interrupt trigger condition classification**
263
264 1. **External input (X) interrupt**
265
266 **~ **1. Description of external input interrupt
267
268 1. The external input interrupt is triggered by the rising or falling edge of the fixed X point input.
269 1. Supports the rising and falling edge interrupts of a total of 8 input points of X0 to X7, and supports a total of 16 external input interrupts.
270 1. The same interrupt trigger condition cannot create multiple interrupt programs.
271 1. External input interrupt and high-speed counter cannot use the same X point.
272 1. You must use EI in the scan program to allow interrupts before the interrupt execution program will be executed.
273
274 2. External input interrupt steps.
275
276 Project management→ Program→ Interrupt→ right click to create
277
278 (% style="text-align:center" %)
279 [[image:1-16.png||class="img-thumbnail"]]
280
281 1. The interrupt program name requires to match case, and the program name with the same name as the device cannot be used (the device name does not match case),
282 1. The interrupt program name does not support the input of /%$@&=to`^<>?:{}[],;!*.~\~\'" characters,
283 1. The length of the interrupt program name cannot exceed 64 characters and cannot be typed. The default name is INTx.
284
285 Click Configure, and select external interrupt for execution type, as shown in the figure below (it can also be configured in "program parameters" in "parameters" in project management):
286
287 (% style="text-align:center" %)
288 [[image:1-17.png||class="img-thumbnail"]]
289
290 (% class="table-bordered" %)
291 |(% colspan="2" %)**Project**|**Content**|**Setting range**|**Default**
292 |(% colspan="2" %)Execution type|Select the type of interrupt|Not set, External input interrupt, Timer event, high-speed counter interrupt|Not set
293 |(% rowspan="4" %)External input interrupt|channel|Select the channel for external input interrupt|X0 to X7|X0
294 |Trigger edge type|Choose to trigger on rising edge or falling edge|(((
295 Rising edge
296
297 Falling edge
298 )))|Rising edge
299 |priority|When multiple interrupts arrive at the same time, the order of priority execution, the smallest value is executed first|0 to 2|0
300 |Filter time (0.01us)|(((
301 Set the filter time of X point, the unit is 0.01us.
302
303 Note: X rising edge interrupt and X falling edge interrupt use the same X filter, so after the filter setting is changed in the X rising edge configuration, the X falling edge will also change. If the filter time is set to 1000, you must ensure that the high level and low level of the input signal are maintained for more than 10 us before the interrupt can be triggered.
304 )))|0 to 1700|1
305
306 1. Write interrupt execution program
307
308 (% style="text-align:center" %)
309 [[image:1-18.png||class="img-thumbnail"]]
310
311 Double-click the newly created interrupt program in the project management to start writing the interrupt execution program. As shown in the figure above, a newly created interrupt program is INT_X0_UP, and the trigger condition is configured to execute the interrupt program when the X0 rising edge is configured. If the EI instruction is used in the main program to allow interrupts, all programs in INT_X0_UP will be executed whenever X0 changes from OFF to ON , That is, D0 will increment once.
312
313 (% style="text-align:center" %)
314 [[image:1652250056160-117.png||height="215" width="500" class="img-thumbnail"]]
315
316 **~ 2.Timer interrupt**
317
318 1. Timer interrupt description
319
320 1. Timer interrupt is based on the set time, execute the interrupt program every this time, the minimum time interval can reach 100us.
321 1. Up to 100 timer interrupt execution programs can be created.
322 1. Each timer interrupt program is independent of each other and does not affect each other.
323 1. Each timer interrupt program should be configured with priority. When triggered at the same time, it is executed in the order of priority, but when the priority is the same, it is executed in the order of the established program.
324 1. The interrupt execution program is executed only after EI is used in the scanner to allow the interrupt
325
326 2. Timer interrupt step
327
328 Project managementðProgramðInterruptðRight click to create. Enter the program name. The program name only supports the combination of English letters, numbers, and underscores, and must start with an English letter. The default is INTx. Click Configure and select Timer Interrupt as the execution type, as shown in the figure below (it can also be configured in "program parameters" in "parameters" in project management).
329
330 (% style="text-align:center" %)
331 [[image:1-20.png||class="img-thumbnail"]]
332
333 (% class="table-bordered" %)
334 |(% colspan="2" %)**Project**|**Content**|**Setting range**|**Default**
335 |(% colspan="2" %)Execution type|Select the type of interrupt|Not set/External input interrupt/Timer event/high-speed counter interrupt|Not set
336 |(% rowspan="2" %)Timer interrupt|Time|Set the interval time for interrupt triggering|1 to 2147483647 (100us unit)|
337 |priority|When multiple interrupts arrive at the same time, the order of priority execution, the smallest value is executed first|0 to 2|0
338
339 1. Write interrupt execution program
340
341 (% style="text-align:center" %)
342 [[image:1-21.png||class="img-thumbnail"]]
343
344 Double-click the newly created timer interrupt program in the project management to start writing the interrupt execution program. As shown in the figure above, a newly created timer interrupt program is INT0, and the trigger condition is configured to execute the interrupt program every 10ms. If the main program uses EI to enable interrupts, all instruction programs in INT0 will be executed every 10ms, namely D0 It will add 1 to 10ms.
345
346 (% style="text-align:center" %)
347 [[image:1652250294005-455.png||class="img-thumbnail"]]
348
349 **~ 3. High-speed counter interrupt**
350
351 1. Description of high-speed counter interrupt
352
353 1. The high-speed counter interrupt triggers an interrupt condition after the set value of the high-speed counter HSC0 to HSC7 provided by the PLC and executes the interrupt program.
354 1. It can support up to 100 high-speed counter interrupt programs, but the number that can be supported by each channel does not need to be fixed.
355 1. When using the high-speed counter interrupt, project must configure the high-speed counter and use the OUT HSC instruction to enable the corresponding counting channel to count before it can be used (see the high-speed counter description section for the specific configuration method).
356 1. Each high-speed counter interrupt program should be configured with priority. When triggered at the same time, it will be executed in the order of priority. When the priority is the same, it will be executed in the order of channels HSC0-HSC7. When the channel is also the same, it is executed in order according to the creation promise.
357 1. Project must use EI in the scan program to allow interrupts before the interrupt execution program will be executed.
358
359 **✎Note: **Both the HSC channel and the external input interrupt channel must use the PLC input point X. It should be noted that it
360
361 cannot be reused during configuration. For details, please refer to the configuration chapter of the high-speed counter.
362
363 1. high-speed counter interrupt step
364
365 “Project management”ð“Programð“Interrupt”ðRight click to create. Enter the program name. The program name only supports the combination of English letters, numbers, and underscores, and must start with an English letter. The default is INTx. Click Configure, select high-speed interrupt for execution type, as shown in the figure below (it can also be configured in "program parameters" in "parameters" in project management).
366
367 (% style="text-align:center" %)
368 [[image:1-23.png||class="img-thumbnail"]]
369
370 (% class="table-bordered" %)
371 |(% colspan="2" %)**Project**|**Content**|**Setting range**|**Default**
372 |(% colspan="2" %)Execution type|Select the type of interrupt|Not set, External input interrupt, Timer event, high-speed counter interrupt|Not set
373 |(% rowspan="5" %)High count interrupt|Mode|(((
374 Select the type of high-speed counter interrupt:
375
376 (1) High-speed comparison interrupt: The interrupt program is executed after the trigger condition is reached.
377
378 (2) High-speed comparison setting: After reaching the trigger condition, the set contact is set.
379
380 (3) High-speed comparison reset: reset the set contact after reaching the trigger condition.
381 )))|(((
382 High-speed compare interrupt
383
384 High-speed comparison set
385
386 High-speed comparison reset
387
388 Not set
389 )))|(((
390 High-speed compare interrupt
391
392
393 )))
394 |Channel|Select the high-speed counter channel used|HSC0 to HSC7|HSC0
395 |Comparison value|Set the comparison value of the high-speed counter. When the high-speed counter value of the set channel passes this value, the trigger condition is reached.|-2147483648 to 2147483647|
396 |Priority|When multiple interrupts arrive at the same time, the order of priority execution, the smallest value is executed first|0 to 2|0
397 |Contact|It is available when selecting high-speed comparison set and high-speed comparison reset. The contact is set or reset immediately after the trigger condition is reached.|Y/M/D.b|
398
399 3. Description of triggering rules
400
401 (% class="table-bordered" %)
402 |**Mode**|**Configuration**|**The current value**|**Action**
403 |(% rowspan="2" %)High-speed compare interrupt (INT0)|(% rowspan="2" %)Comparison value: 10000|9999 → 10000|Execute all programs in interrupt INT0
404 |10001 → 10000|Execute all programs in interrupt INT0
405 |(% rowspan="2" %)High-speed comparison set (INT1)|(% rowspan="2" %)(((
406 Comparison value: -50,000
407
408 Contact: Y10
409 )))|-50001 → -50000|(((
410 Y10 is immediately set and mapped to the actual output (not affected by the scan period)
411
412 The program in INT1 will not be executed
413 )))
414 |-49999 → -50000|(((
415 Y10 is immediately set and mapped to the actual output (not affected by the scan period)
416
417 The program in INT1 will not be executed
418 )))
419 |(% rowspan="2" %)High-speed comparison reset (INT2)|(% rowspan="2" %)(((
420 Comparison value: 400000
421
422 Contact: Y10
423 )))|399999 → 400000|(((
424 Y10 is reset immediately and mapped to the actual output (not affected by the scan period)
425
426 The program in INT2 will not be executed
427 )))
428 |400001 → 400000|(((
429 Y10 is reset immediately and mapped to the actual output (not affected by the scan period)
430
431 The program in INT2 will not be executed
432 )))
433
434 **✎Note: **Both HSC channel and external input interrupt channel need to use the INPUT point X, so it should be noted that it cannot be reused in configuration. For details, please refer to the configuration section of high-speed counter.
435
436 1. Write interrupt execution program
437
438 * New interrupt program
439
440 Create three new interrupt programs under the interrupt of project management, namely HSC0_20000, HSC0_30000, HSC0_40000. Configure the interrupt program in the "program parameters", as shown in the figure below.
441
442 (% style="text-align:center" %)
443 [[image:1-24.png||class="img-thumbnail"]]
444
445 * High-speed counter configuration
446
447 Configure HSC0 for use in the high-speed counter configuration. After selecting the working mode, click the "Check” button. After the correct configuration box pops up, click Enter.
448
449 (% style="text-align:center" %)
450 [[image:1-25.png||class="img-thumbnail"]]
451
452 Call the high-speed counter in the main program and enable interrupts:
453
454 [[image:1-26.png||class="img-thumbnail"]]
455
456 Program operation:
457
458 Assuming that the High-speed counter channel 0 has been receiving pulses:
459
460 When the count value of HSC0 accumulates from 0 to 20000, all procedures of HSC0_20000 are executed.
461
462 When the count value of HSC0 is accumulated from 20000 to 30000, all procedures of HSC0_30000 are executed.
463
464 When the count value of HSC0 is accumulated from 30000 to 40000, all procedures of HSC0_40000 are executed.
465
466 **Mask interrupt**
467
468 **~ 1. Mask through application instructions**
469
470 The PLC interrupt is in the shielded state by default when it is powered on, and can only be used after the interrupt is allowed through the EI instruction.
471
472 The interrupt mask instruction DI masks all interrupts without parameters, and masks some priority interrupts with parameters (refer to the program flow instruction DI/EI for details).
473
474 **~ 2. Mask through special registers SM and SD**
475
476 1.External input interrupt mask register
477
478 (% class="table-bordered" %)
479 |(% colspan="4" %)**External input interrupt mask register**
480 |**Special register number**|**Type of interrupt**|**Instruction**|**Defaults**
481 |SM352|X0 rising edge interrupt|ON: Mask interrupt OFF: Enable interrupt|OFF
482 |SM353|X0 falling edge interrupt|ON: Mask interrupt OFF: Enable interrupt|OFF
483 |SM354|X1 rising edge interrupt|ON: Mask interrupt OFF: Enable interrupt|OFF
484 |SM355|X1 falling edge interrupt|ON: Mask interrupt OFF: Enable interrupt|OFF
485 |SM356|X2 rising edge interrupt|ON: Mask interrupt OFF: Enable interrupt|OFF
486 |SM357|X2 falling edge interrupt|ON: Mask interrupt OFF: Enable interrupt|OFF
487 |SM358|X3 rising edge interrupt|ON: Mask interrupt OFF: Enable interrupt|OFF
488 |SM359|X3 falling edge interrupt|ON: Mask interrupt OFF: Enable interrupt|OFF
489 |SM360|X4 rising edge interrupt|ON: Mask interrupt OFF: Enable interrupt|OFF
490 |SM361|X4 falling edge interrupt|ON: Mask interrupt OFF: Enable interrupt|OFF
491 |SM362|X5 rising edge interrupt|ON: Mask interrupt OFF: Enable interrupt|OFF
492 |SM363|X5 falling edge interrupt|ON: Mask interrupt OFF: Enable interrupt|OFF
493 |SM364|X6 rising edge interrupt|ON: Mask interrupt OFF: Enable interrupt|OFF
494 |SM365|X6 falling edge interrupt|ON: Mask interrupt OFF: Enable interrupt|OFF
495 |SM366|X7 rising edge interrupt|ON: Mask interrupt OFF: Enable interrupt|OFF
496 |SM367|X7 falling edge interrupt|ON: Mask interrupt OFF: Enable interrupt|OFF
497
498 2. Timer interrupt mask register
499
500 (% class="table-bordered" %)
501 |(% colspan="4" %)**Timer interrupt mask register**
502 |**Special register number**|**Type of interrupt**|**Instruction**|**Default**
503 |SD350|1st to 16th timer interrupt|(((
504 Each bit can control the mask of an interrupt.
505
506 ON: Mask interrupt OFF: Enable interrupt
507 )))|0
508 |SD351|17th to 32th timer interrupt|(((
509 Each bit can control the mask of an interrupt.
510
511 ON: Mask interrupt OFF: Enable interrupt
512 )))|0
513 |SD352|33th to 48th timer interrupt|(((
514 Each bit can control the mask of an interrupt.
515
516 ON: Mask interrupt OFF: Enable interrupt
517 )))|0
518 |SD353|49th to 64th timer interrupt|(((
519 Each bit can control the mask of an interrupt.
520
521 ON: Mask interrupt OFF: Enable interrupt
522 )))|0
523 |SD354|65th to 80th timer interrupt|(((
524 Each bit can control the mask of an interrupt.
525
526 ON: Mask interrupt OFF: Enable interrupt
527 )))|0
528 |SD355|81st to 96th timer interrupt|(((
529 Each bit can control the mask of an interrupt.
530
531 ON: Mask interrupt OFF: Enable interrupt
532 )))|0
533 |SD356|97th to 100th timer interrupt|(((
534 Each bit can control the mask of an interrupt.
535
536 ON: Mask interrupt OFF: Enable interrupt
537 )))|0
538
539 1. high-speed counter interrupt mask register
540
541 (% class="table-bordered" %)
542 |(% colspan="4" %)**High-speed counter interrupt mask register**
543 |**Special register number**|**Type of interrupt**|**Instruction**|**Default**
544 |SD382|1st to 16th high-speed counter interrupt|(((
545 Each bit can control the mask of an interrupt.
546
547 ON: Mask interrupt OFF: Enable interrupt
548 )))|0
549 |SD383|17th to 32nd high-speed counter interrupt|(((
550 Each bit can control the mask of an interrupt.
551
552 ON: Mask interrupt OFF: Enable interrupt
553 )))|0
554 |SD384|33th to 48th high-speed counter interrupt|(((
555 Each bit can control the mask of an interrupt.
556
557 ON: Mask interrupt OFF: Enable interrupt
558 )))|0
559 |SD385|49th to 64th high-speed counter interrupt|(((
560 Each bit can control the mask of an interrupt.
561
562 ON: Mask interrupt OFF: Enable interrupt
563 )))|0
564 |SD386|65th to 80th high-speed counter interrupt|(((
565 Each bit can control the mask of an interrupt.
566
567 ON: Mask interrupt OFF: Enable interrupt
568 )))|0
569 |SD387|81st to 96th high-speed counter interrupt|(((
570 Each bit can control the mask of an interrupt.
571
572 ON: Mask interrupt OFF: Enable interrupt
573 )))|0
574 |SD388|97th to 100th high-speed counter interrupt|(((
575 Each bit can control the mask of an interrupt.
576
577 ON: Mask interrupt OFF: Enable interrupt
578 )))|0
579
580 == Subroutine ==
581
582 During the execution of the scan program, the executed program can be called by the CALL instruction.
583
584 A subroutine is to split a certain module in the main program for the main program to call, which is conducive to the modularization of the program. Such as other high-level language functions, but this function has no parameters and no return value.
585
586 (% style="text-align:center" %)
587 [[image:1652250926997-587.png||class="img-thumbnail"]]
588
589 1. Instructions for calling subroutines
590
591 After a new subroutine is created, the content of the program is not executed. It is executed only when the CALL(P) instruction is used to call the subroutine in the scan, event, and interrupt programs, and the call is executed once. Three new subroutines SUB0, SUB1, SUB2 are created as shown in the figure below. In the main program MAIN, the subprogram can be called by using the CALL(P) subprogram program name.
592
593 Through this programming method, the use of the same logic program for different conditions can reduce the number of Circuit program steps and improve the readability of the Circuit program.
594
595 (% style="text-align:center" %)
596 [[image:1-28.png||class="img-thumbnail"]]
597
598 **~ 1.✎Note:**
599
600 1. When using the timer (OUT T), note that the output will not be reset when the subroutine is not called, and a specific subroutine register must be used.
601 1. It is not allowed to call recursively between subprograms, that is, call SUB1 in SUB0, and then call SUB0 in SUB1. This is not allowed.
602 1. The subroutine can be nested up to 32 levels. If the level exceeds 32 levels, a serious error will be reported and the Circuit program operation will be forcibly stopped.
603 1. Unlike the LX3V series mainframe, the subroutine in the LX5V series mainframe ends with the END instruction instead of SRET.
604
605 == Positioning instructions ==
606
607 ~1. Event
608
609 1.ON event
610
611 If the high-speed pulse instruction is turned on during the ON event, the high-speed pulse instruction will be sent as normal. If the ON contact of the trigger event in the scan period is turned OFF during the pulse sending, select whether to continue sending the pulse or stop the pulse according to the unscanned processing flag bit.
612
613 (% class="table-bordered" %)
614 |**Output shaft**|Y0|Y1|Y2|Y3|Y4|Y5|Y6|Y7
615 |**Not scanned flag bit**|SM899|SM959|SM1019|SM1079|SM1139|SM1199|SM1259|SM1319
616
617 When the flag bit is 0 (continue to send pulse), if the instruction is not scanned in the current scan cycle, continue to send pulses until it stops. At this time, it should be noted that if the trigger event OFF contact turns ON after the pulse is sent, the pulse will be sent again.
618
619 When the flag bit is 1 (stop sending pulses), if the trigger event ON contact turns OFF in a certain scan period, it will decelerate and stop.
620
621 2. TIME event
622
623 If the high-speed pulse instruction is turned on in the TIME event, the high-speed pulse instruction will be sent as normal. If the instruction is not scanned in a certain scan period during the pulse transmission, select whether to continue sending the pulse or stop the pulse according to the unscanned processing flag bit.
624
625 (% class="table-bordered" %)
626 |**Output shaft**|Y0|Y1|Y2|Y3|Y4|Y5|Y6|Y7
627 |**Not scanned flag bit**|SM899|SM959|SM1019|SM1079|SM1139|SM1199|SM1259|SM1319
628
629 When the flag bit is 0 (continue to send pulse), if the instruction is not scanned in the current scan cycle, the pulse will continue to be sent until it stops. In the TIME event, it is impossible to ensure that the instruction is scanned in every scan cycle, so you should avoid using high-speed pulse instructions in the TIME time, otherwise the pulse will be sent again after the pulse is sent.
630
631 When the flag bit is 1 (stop sending pulses), if the instruction is not scanned in the current scan cycle, it will decelerate and stop. In the TIME event, if the flag bit is set to 1 (stop sending pulses), there will be no pulse sending.
632
633 2. Subroutine
634
635 If the high-speed pulse instruction is turned on in the subroutine, the high-speed pulse instruction will be sent as normal. If the scanning period is closed during pulse sending, select whether to continue sending or stop the pulse according to the unscanned processing flag.
636
637 (% class="table-bordered" %)
638 |**Output shaft**|Y0|Y1|Y2|Y3|Y4|Y5|Y6|Y7
639 |**Not scanned flag bit**|SM899|SM959|SM1019|SM1079|SM1139|SM1199|SM1259|SM1319
640
641 When the flag bit is 0 (continue to send pulse), if the instruction is not scanned in the current scan cycle, the pulse will continue to be sent until it stops. At this time, it should be noted that if the subroutine is called again after the pulse is sent, the pulse will be sent again.
642
643 When the flag bit is 1 (stop sending pulses), if the subroutine is closed during high-speed pulse sending, the speed will decelerate and stop. If the subroutine is closed before sending the pulse, then no pulse is sent.
644
645 3. Interrupt
646
647 1. External interrupt
648
649 If the high-speed pulse instruction is enabled in the external interrupt, the high-speed pulse instruction selects whether the pulse continues to be sent or the pulse stops according to the unscanned processing flag bit.
650
651 (% class="table-bordered" %)
652 |**Output shaft**|Y0|Y1|Y2|Y3|Y4|Y5|Y6|Y7
653 |**Not scanned flag bit**|SM899|SM959|SM1019|SM1079|SM1139|SM1199|SM1259|SM1319
654
655 When the flag bit is 0 (continue to send pulse), continue to send high-speed pulses until it stops.
656
657 When the flag bit is 1 (stop sending pulse), the high-speed pulse decelerates and stops.
658
659 2. Timer interrupt
660
661 If the high-speed pulse instruction is turned on in the timer interruption, the high-speed pulse instruction is sent as normal. If the instruction is not scanned in a certain scan period in the pulse transmission, the pulse continues to be sent or the pulse stops is selected according to the unscanned processing flag.
662
663 (% class="table-bordered" %)
664 |**Output axis**|Y0|Y1|Y2|Y3|Y4|Y5|Y6|Y7
665 |**Not scanned flag bit**|SM899|SM959|SM1019|SM1079|SM1139|SM1199|SM1259|SM1319
666
667 When the flag bit is 0 (continue to send pulse), if the instruction is not scanned in the current scan cycle, continue to send pulses until it stops. In the timer interrupt, it is impossible to ensure that the instruction is scanned in every scan cycle, so it is necessary to avoid using high-speed pulse instructions in the T timer interrupt. Otherwise, after the pulse transmission is completed, the pulse will be sent again.
668
669 When the flag bit is 1 (stop sending pulses), if the instruction is not scanned in the current scan cycle, it will decelerate and stop. In the TIME event, if the flag bit is set to 1 (stop sending pulses), there will be no pulse sending.
670
671 3.High-speed comparison interrupt
672
673 If the high-speed pulse instruction is enabled in the high-speed comparison interrupt, the high-speed pulse instruction selects whether the pulse continues to be sent or the pulse stops according to the unscanned processing flag.
674
675 (% class="table-bordered" %)
676 |**Output axis**|Y0|Y1|Y2|Y3|Y4|Y5|Y6|Y7
677 |**Not scanned flag bit**|SM899|SM959|SM1019|SM1079|SM1139|SM1199|SM1259|SM1319
678
679 When the flag bit is 0 (continue to send pulse), continue to send high-speed pulses until it stops.
680
681 When the flag bit is 1 (stop sending pulse), the high-speed pulse decelerates and stops.