5 Designing Tasks
5-36
NJ-series CPU Unit Software User’s Manual (W501)
System
If a refreshing task is set for a global variable, the accessing task, at the start of accessing task exe-
cution, always reads the most recent value of the variable that was written at the completion of
refreshing task execution.
This will allow you to maintain the concurrency of the values of global variables within the tasks with-
out performing any special programming.
If an instruction that writes the value to a global variable is used in the accessing task, an error will
occur when you check the program on the Sysmac Studio.
Precautions for Correct UsePrecautions for Correct Use
If you are using the ActEventTask instruction between two tasks, you must keep in mind when
the global variables are accessed, and when they are refreshed. For example, in the following
diagram, the value of the GVarA global variable that is accessed from the event task is the value
that was current at the end of task period 1. Therefore, even if the periodic task in task period 2
writes the value of GVarA, that value will not be reflected in the event task. The value that the
event task writes to the GVarB global variable is not passed to the periodic task until the start of
task period 3. Even if the periodic task in task period 2 accesses the value of GVarB, the value
that the event task writes will not be accessed.
Task period of task A
Task period of task A
Task period of task A
Refreshing
task: Task A
Accessing task:
Task B
Value of variable
is not read.
Global variable
Write
Refreshing
task: Task A
Task period of task B
Accessing task:
Task B
Value of variable
is not read.
Global variable
Accessing task:
Task B
Value of
variable is read.
Write
Refreshing
task: Task A
Global variable
Write
GVarA
123
GVarA
123
GVarA
567
GVarB
987
GVarB
654
Event task
(refreshing task)
GVarB
987
A value of
123 is
written.
A value of 987
is written.
A value of 567
is written.
GVarB
654
A value of 654
is written.
A value of 654 is read.
A value of
987 is read.
A value of 123
is read.
The value of GVarA is passed
to the event task at this point.
The value that is written
here is not reflected in
the event task.
The value that the event task
writes cannot be accessed.
The value of GVarB is passed to
the periodic task at this point.
Periodic task
(accessing task)
Task period 1
Execution of
ActEventTask
Task period 3Task period 2
Periodic task
(accessing task)
Periodic task
(accessing task)
High
Low
Execution
priority