beautypg.com

Multi tasking – Yaskawa SMC–4000 User Manual

Page 313

background image

303

SMC–4000 User Manual

Multi Tasking

Below is a block diagram demonstrating the
concept of multitasking. Threads can be
started and stopped by each other at will. The
only limitation is that the thread being
launched with the XQ command cannot be
already executing. The recommended
method is to start threads in the initialization
section of the program. Once started, they
will continue to operate until halted. The
controller will time share between threads on
a line-by-line basis. If one program has more
commands per line, it will receive more of the
total execution time available.

Multi tasking is a very useful method of
accomplishing several tasks that have very
little or nothing do with each other. Focus
can be specifically on the task, whereas extra
“juggling” code would be necessary to
adequately handle several unrelated events in
a single program loop. Good examples of
multitasking include:

• Software limit updates for two axes that

operate in each others zone where a
collision could occur.

• An analog output must be updated

continuously

• Short-term event that must be monitored

at the same time as another process. This
is a “spur” thread that runs and dies after
a certain event is attained, such as a
timer.

• I/O logic must be solved at a regular

interval.

• Events that may take place at the same

time, but are handled at different times,
such as a registration buffer that must
store product positions, but the
correction for a particular product will
occur slightly later.

There is no need to multitask when moving
two or more servos if these axes always move
in a predefined sequence. Some users
incorrectly assume that they must use a thread
per axis. Experience will dictate when it is
better to use multitasking, and when one task will suffice.

Subroutines and other sections of code should not be intermixed between threads to avoid complexity
and possible erratic behavior.

All variables & arrays defined in the program are global, meaning that all threads can read and write the
data. This is very useful when threads must share information, such as a product registration buffer. This
can be troubling if the programmer unknowingly uses the same variable in both threads for something
simple, such as the variable “X” as a counter.

Initialization

Main Loop (0)

Application

Specific

Routine 1 of…

Application

Specific

Routine 2 of …

Supporting

Routine

Main Loop (1)

Application

Specific

Routine 1 of…

Application

Specific

Routine 2 of …

Supporting

Routine

Main Loop (2)

Application

Specific

Routine 1 of…

Application

Specific

Routine 2 of …

Supporting

Routine

Fault Handling