Bring Values and Sucesses To Our Customers

Home / Support and services / Technical Support

Technical support

Technical Support

Motion Control Quick Start (10) | How to Achieve Multiple Task Operation For Motion Controller


Motion Control Quick Start Knowledge keeps moving.
Before, we had learned: 
quick start (1) -- firmware update
quick start (2) -- ZBasic program development
quick start (3) -- ZPLC program development
quick start (4) -- Communicate with HMI
quick start (5) -- IO Input & Output 
quick start (6) -- Data Storage
quick start (7) -- ZCAN Expansion Module
quick start (8) -- EtherCAT Expansion Module
quick start (9) -- Oscilloscope

 Hi, everyone, nice to meet you.

 As we all know, Zmotion motion controllers support multi-task, today, let’s see details.

1. Material Preparation

--Materials--

(1) One computer with ZDevelop3.01 or above installed.

(2) One controller.

(3) One 24V DC power supply

(4) Several bus drive + motor (or stepper drive + motor).

(5) A number of controller wiring terminals.

(6) Several network cables.

(7) A number of connecting wires.

(8)  Several expansion modules of different types.

--Wiring Reference--

IMAGE 1.png






2.  Multi-task Introduction

(1) what is the multi-task?

Firstly, let’s see what is the task in programming. Task is the function to execute a series of instructions processing, such as, I/O refresh, user program, etc. And one task means one program that is running.

Then, if multiple program modules can run at the same time without interruption, which is called multi-task. Here, multi-task program is achieved through our ZDevelop programming software.

Although multi-task means several tasks run synchronously, actually it takes a complex program apart several parts, which means it starts task separately and tasks are executed simultaneously, each task is independent. In this way, the complicated motion process of equipment will be simpler, and programming is more flexible.

ZMC motion controller not only supports multi-task programming, also every task has own unique number. These numbers don’t have priority, they just identify which the task is of the current program.

Different models support different task amounts. After connecting to controller, “State the controller” in ZDevelop menu bar can check the exact task numbers. Also, it can be known through sending “?*max” in “command”. As shown in the figure below, this controller supports 22 tasks, and the task number range is 0-21.

IMAGE 2 - 1.pngIMAGE 2 - 1.pngIMAGE 2 - 2.png

 

(2) what are the advantages of multi-task?

--Program modular--

User can write several small and specific programs to achieve assigned functions that are consistent with customer’s equipment.

--Concurrency--

Every task can run independently. When task starts, it won’t be influenced by other tasks.

--Simplify the error process--

Error handling becomes simple after dividing the multitasking operation, and only the task with error is processed.

--Command interaction--

When program is running, users can do command interaction in any time, such as, online modify motion parameters, send commands in online command bar, etc. And other programs don’t be affected.

Files or SUB subroutines under the same project can use instructions to call each other. It only needs to set the file to be called as the main task, that is, set the automatic running task number (AutoRun) for the file, and the called file does not set automatic running.

The controller supports multi-file and multi-task running at the same time. And multiple tasks can be started in one file, and tasks can also be started across files.

 

(3) how to check multi-task states?

There are 3 states of multi-task, “Running, Stopped and Paused”. Followings are details of 3 checking methods.

--Task instruction: PROC_STATUS--

This instruction is used to check the task status, parameters only can be read. View from return values, 0-task stops, 1-task is running, 3-task pauses.

For Example:

PRINT    PROC_STATUS(0)            ′print status of task 0

?*PROC_STATUS                            ′print status of all tasks supported by controller

--Task window--

Open task window through “Debug” – “Start/Stop Debug”, as shown in the below figure.

IMAGE 3.png

Task number and running status of started task, current file and operation line number can be viewed through this window.

However, it can’t check the task that is not used.

--Menu bar “Debug”/“Bus state diagnosis” window--

Status of all task numbers, current file and running line number all can be checked.

This window also shows all tasks error information.

IMAGE 4.png

 

(4) what are multi-task instructions?

--multi-task operation instructions--

END: the current task ends normally.

STOP: stop the running task of assigned file.

STOPTASK: stop assigned task.

HALT: stop all tasks.

RUN: start a new task and run a file.

RUNTASK: start a new task and run one SUB or one program with labels.

PAUSETASK: pause assigned task.

RESUMETASK: resume assigned task, then task will execute from that pause position.

?*MAX: check task total amounts and file total amounts supported by controller.

IMAGE 5.png

Please note write task No. carefully when opening task, tasks can’t be opened repeatedly.

--starting task instructions--

There are 3 methods, they are auto-running task number configuration, RUN instruction and RUNTASK instruction. When using instructions to start task, task will be opened after this instruction is scanned by program.

1) Auto-running task number:

Setauto-running task number through "FileView" window. After the controller is powered on, the file with the auto-running task number will be executed first. Basic file can set several AutoRun task numbers, but only one PLC file and HMI file are supported. The auto-run files are run in parallel, and they are turned on at the same time after power-on.

2) RUN instruction

The file as one task is turned on through RUN instruction:

For example:

RUN "TuXing_001.bas",2              ′set the file TuXing_001.bas as task 2, and start it.

3) RUNTASK instruction

SUB subprogram or signed program are set as one task and are turned on through RUNTASK instruction. Start global SUB subprogram through cross-file, and the label program that needs to start task only can exist in this file.

For example:

RUNTASK 1,task_home            ′set as task 1 to start the task_home subprogram

When using instructions to open task, task will be turned on after the program scanned this instruction.

--stop task instructions--

Similarly, there are 3 methods to stop multi-task: STOPTASK, STOP and HALT instructions.

If stops the task and restarts it, it will be executed from the beginning.

When starts task, usually use STOPTASK to stop the task firstly. Then start through RUNTASK for avoiding errors caused by start repeatedly.

1) STOPTASK

It supports stopping file task, SUB subprogram task and labelled task.

For example:

STOPTASK2     ′stop task 2

2) STOP

It supports stopping Basic file tasks.It is recommended to use STOPTASK instruction, because the operation is simpler.

3) HALT

It supports stopping all tasks.

For example:

HALT                    ′stop all tasks in project

Also “Emerge Stop” button can be used to stop all tasks rapidly.

--pausing and resuming tasks--

Use PAUSETASK command to pause task, and use RESUMETASK command to resume task. After resuming, the task continues to execute from where it was suspended. And paused tasks support stopping.

1) PAUSETASK: pause assigned task

For example:

PAUSETASK 1                          ′pause task 1

2)RESUMETASK: resume assigned task

For example:

RESUMENTASK 1                        ′continue to running task 1

 


3.    Multi-task calling and display routines.

(1) multi-task calling

To download and run the program, firstly start the file with the auto-run task number. Multiple auto-run task numbers can be set, or only one can be set. Other file tasks can be started with the RUN command.

IMAGE 6.png

According to the location of the program to be called, add the RUN or RUNTASK command in the auto-run file to call other tasks to execute.

The framework of multitasking calls is shown in the figure below.

IMAGE 7.png

(2) multi-task program modular

Programming reference framework:

IMAGE 8.png

When programming, the modules are divided, and some program blocks are called and executed when needed, which reduces the program scanning time and improves the execution efficiency of the controller.

The program is downloaded and run, and the file with the automatic running task number is started. The automatic running program is generally called the main program, which executes program initialization, parameter definition, logic processing and starts other tasks.

Add the RUN or RUNTASK command to the auto-run file to start other tasks.

(3) call tasks each other (Basic and PLC)

--Basic task calls PLC task--

Call PLC file through RUN instruction.

IMAGE 9.png

Call subprogram defined by LBL instruction in PLC through RUNTASK instruction.

IMAGE 10.png

--PLC task calls Basic task--

For PLC, using EXE or EXEP (pulse execution) instructions to call Basic task, then calling Basic file task or subprogram task.

IMAGE 11.png

(4) multi-task display routines

The routine includes two files, and the main task TASK0 is started by the automatic task number of the file.

The homing task TASK1 and the motion task TASK2 are started by the task instructions in the main task TASK0.

The call of the SUB subroutine is also turned on in the main task.

(if you need the full routine codes, please contact us)

IMAGE 12.png

--File 1: Main.bas--

IMAGE 13.png

--File 2: TuXing_001.bas--

IMAGE 14.png




ABOUT ZMOTION

That's all, thank you for your reading -- Motion Control Quick Start (10) | How to Achieve Multiple Task Operation For Motion Controller

For more information, please pay close attention to "Support"  and   "Download" , and there are other platforms about Zmotion - Youtube   &   LinkedIn   &   Twitter    &   Tiktok    &   Facebook including technical information (development environment, routine code), product showing, company development, etc.

Hope to meet you, talk with you and be friends with you.  Welcome!

This article is edited by ZMOTION, here, share with you, let's learn together.

ZMOTION: DO THE BEST TO USE MOTION CONTROL.

Note: Copyright belongs to Zmotion Technology, if there is reproduction, please indicate article source. Thank you.

Zmotion Technology focuses on development of motion control technology and general motion control products, it is a national high and new technology enterprise. Due to its concentration and hard work in motion control technology, ZMOTION already become one of the fastest growing industrial motion control companies in China, and is also the rare company who has managed core technologies of motion control and real time industrial control software completely. Here, Zmotion provides motion controller, motion control card, vision motion controller, expansion module and HMI. In addition, there is one program software developed by Zmotion -- ZDevelop. It is a good choice for you to program and compile. And program through upper computer, there is PC manual.

Zmotion Technology  provides motion control card, motion controller, vision motion controller, expansion module and HMI. ( more keywords  for Zmotion: EtherCAT motion control card, EtherCAT motion controller, motion control system, vision controller, motion control PLC, robot controller, vision positioning...)

Have a good day, best wishes, see you next time.


2013-2023 版权所有 Zmotion Corp. Copyright Reserved 粤ICP备13037187号-1