Chapter 10 CPU Function
10.1.8 Methods on How to Use Variables between Tasks
Extra attention should be given when reading and writing the same global variables in the main task and the
periodic task.
If the value of %MW100 is read and written in the main task and periodic task programs as shown below, the
value of %MW100 will be changed continuously depending on the usage position in the periodic task.
â‘ Write the value of %MW100 to 30 in the main task program
â‘¡ The value of %MW100 is 30 when read from the periodic task
â‘¢ Write the value of %MW100 to 31 in the main task program
â‘£ The value of %MW100 is 31 when read from the periodic task
⑤ Write the value of %MW100 to 32 in the main task program
â‘¥ The value of %MW100 is 32 when read from the periodic task
Main task period
I/O
refre
sh
Program
Motion
control
I/O
refre
sh
Program
Motion
control
I/O
refre
sh
Program
Motion
control
Program
Program
Program
Main
task
Period
task
%MW100
Write
Read
Write
Read
Write
Read
Main task period
â‘ =30
â‘¡ =30
â‘¢ =31
â‘£ =31
⑤ =32
â‘¥ =32
프로그램 수행
Program Program Program
%MW100=30 %MW100=31
Periodic task program
%MW100=32
Since the value of %MW100 is continuously changed to 30, 31 and 32 in one cycle of the periodic task, the
value may be different depending on the location of the device use. If in the periodic task program, the value is
written in the global variable (example: %MW100) used in the main task program, the result of the main task
program operation may be affected.
※ Please be careful when programming to avoid using the same device between the main task program and
the periodic task program, if possible.