Share this

[Positive Motion] PLC Programming for EtherCAT Motion Controller (Part 1): Linear Interpolation

2026-04-06 03:00:35 · · #1

Ladder diagrams (LAD, Ladder Logic Programming Language) are the most widely used graphical programming language for PLCs and are often referred to as the primary programming language for PLCs.

Ladder diagrams follow the form of relay control circuits. They are simplified versions of commonly used relay and contactor logic control, and are characterized by being visual, intuitive, and practical. They are easy for electrical technicians to understand and are the most widely used programming language for PLCs.

The ZMC006CE, powered by Positive Motion Technology, is a high-performance, cost-effective motion controller that supports ZBasic and ZPlC programming languages, as well as the EtherCAT motion controller programmable via the ZHMI interface. Before delving into linear interpolation, let's briefly understand this product.

Instructional Videos

Introduction to Trapezoid Diagrams

(I) Ladder Diagram Operation Logic

The PLC ladder diagram execution starts from the left bus and scans sequentially from left to right and from top to bottom. One scan cycle is from the first line of the program to END. Then a new round of program scanning begins until the program is stopped.

During PLC operation, the process mainly goes through five stages: self-testing, communication processing, input detection, program execution, and output refresh. Before scanning the program, fault detection and program checks are performed first. If an abnormality is found, the system will stop and display an error message, print out program writing problems, and then perform communication responses with other devices.

Scan cycle diagram

A scan cycle consists of three stages: input detection, program execution, and output refresh.

1. Input detection

The PLC sequentially reads the on/off status of each input terminal in a scanning manner and writes it to the corresponding input status register, thus refreshing the input, and then proceeds to the program execution stage. Generally, the width of the input signal should be greater than one scan cycle; otherwise, signal loss may occur.

2. Program execution

The PLC scans each ladder diagram instruction from left to right and from top to bottom, and saves the corresponding calculation and processing results in the output status register. During program execution, if the input signal state changes, the input state in the status register remains unchanged until the next scan begins, at which point the input signal state is read again.

3. Output refresh

After all instructions have been executed, the on/off status of the output status register is written to the output terminal to drive the corresponding output device.

The scan cycle depends primarily on the program length, instruction type, and CPU instruction execution speed. The scan cycle time can be viewed using special registers D8010 (scan time), D8011 (minimum scan time), and D8012 (maximum scan time).

(II) Ladder Diagram Mixed with Basic

1. PLC calling BASIC instructions

A PLC can call Basic standard instructions using the EXE or EXEP instructions. The EXEP instruction is the pulse form of the EXE instruction, and it only calls the Basic standard instruction after the drive input changes from OFF to ON.

The syntax is as follows:

"EXE @BASIC instruction" is equivalent to "BASIC instruction".

2. PLC calling BASIC and PLC programs

PLCs use the CALL instruction to call subroutines. The program file must be within the same project file (.ZPJ) to be eligible for calling.

2.1 PLC calling PLC subroutine

After the CALL instruction calls the subroutine, execution jumps to the corresponding LBL line and returns when it reaches the SRET instruction.

2.2 PLC calling Basic subroutines

When a PLC calls a Basic subroutine, it is necessary to add @ before the SUB function name. When calling, you can choose whether to pass parameters according to the actual situation, such as parameter LV0 in the right figure.

PLC ladder diagram program

Called Basic subroutine

3. BASIC calling PLC files

Program files can only be called if they are within the same project file (.ZPJ).

3.1 Basic Startup of PLC Task

In Basic, you can use the statement "run"xxx.plc", task number" to start a PLC file task.

The PLC subroutine SRET subroutine return instruction can include a return value, which is stored in the LV local register. The return value is in floating-point format, and the caller retrieves the return value using the RETURN instruction.

3.2. Basic calling PLC subroutines

In Basic, use "CALL SUB_FUNC" or "RUNTASK task_number, SUB_FUNC" to call the PLC subroutine LBL.

As shown in the figure below, after the Basic program executes the CALL statement, it jumps to the LBL subroutine of the PLC program for execution. After the subroutine SRET is executed, the return parameter LV1 is stored in RETURN.

Introduction to 2D interpolation function and ladder diagram.

(I) Interpolation Principle

In linear interpolation, the interpolation between two points approximates the actual contour by moving along a group of points on a straight line. First, assume a small distance is taken along the X-direction from the starting point of the actual contour (a fixed distance is traveled along the equivalent axis for each pulse). If the endpoint is found to be above the actual contour, the next line segment moves a small distance along the Y-direction. If the endpoint is still below the actual contour, the line continues moving a small distance along the Y-direction until it is above the actual contour, then moves a small distance along the X-direction, and so on, until the endpoint of the contour is reached. The actual contour is composed of segments of broken lines. Although these are broken lines, each interpolation segment is very small within the allowable accuracy range, so this broken line segment can still be approximated as a straight line segment. This is linear interpolation.

Suppose the shaft needs to move from point (X0,Y0) to point (X1,Y1) in the XY plane, the linear interpolation machining process is shown in the figure below.

The distance a single pulse travels on an axis is determined by the characteristics of the motor; different axes have different single pulse travel distances.

(II) Introduction to Ladder Diagram Interpolation Commands

In forward motion ladder diagram programming, there are two forms of interpolation instructions: Zbasic form and PLC form.

Ladder diagrams use Zbasic form interpolation instructions

Ladder diagrams use PLC-style interpolation instructions

1. Introduction to Zbasic interpolation commands

MOVE -- Linear motion

2. Introduction to PLC-based interpolation instructions

MOVE

Instruction Description: The MOVE instruction is a linear interpolation relative motion instruction. Operands:

S1:T,C,D,K,H,Z,V,LV,DT,@

S2: T,C,D,K,H,Z,V,LV,DT,@

...

S8: T,C,D,K,H,Z,V,LV,DT,@

If operands are word registers, the values ​​in the registers must be assigned using floating-point instructions. Programming example:

Use the MOVE instruction directly from the PLC instruction set.

Example of linear interpolation using a three-trapezoidal diagram; introduction to trapezoidal diagrams.

(I) Ladder Diagram Mixed with Zbasic Routine

Demo video

Main loop part

When power is applied, M8002 conducts once, calling the axis initialization function to execute, which is then executed by calling the relative motion function from M0.

Axis initialization section

interpolation motion part

After setting the S-curves for axes 0 and 1, with a smoothing time of 100ms and SRAMP=100,100, the velocity curves are shown in the following figure:

ld m8002exe @Axis_Initldp m0EXE @RelativeMoveendlbl @Axis_Initld m8000EXE @BASE(0,1)EXE @UNITS = 100,100EXE @ACCEL = 1000,1000EXE @DECEL = 1000,1000EXE @SPEED = 100,100EXE @DPOS = 0,0EXE @MPOS = 0,0sretLBL @RelativeMove ld m8000EXE @BASE(0,1)exe @Triggerexe @MOVE(300,400)sret

Ladder diagram corresponding statement list

·

Axis_Init

WHILE 1

IF SCAN_EVENT(MODBUS_BIT(0)) > 0 THEN Axis_Move ENDIFWEND

END

GLOBAL SUB Axis_Init() BASE(0,1) UNITS= 100,100 ACCEL = 1000,1000 DECEL = 1000,1000 SPEED = 100,100 DPOS = 0,0 MPOS = 0,0ENDSUB

GLOBAL SUB Axis_Move() BASE(0,1) TRIGGER MOVE(300,400)ENDSUB

The Zbasic form program is equivalent to this ladder diagram linear interpolation program.

This concludes our sharing of PLC programming for EtherCAT motion controllers (Part 1): Linear interpolation.

This article is original content from Zheng Motion Technology. We welcome everyone to reprint it for mutual learning and to jointly improve China's intelligent manufacturing level. Copyright belongs to Zheng Motion Technology. Please indicate the source if you reprint this article.


Read next

CATDOLL Mimi Hard Silicone Head

The head made from hard silicone does not have a usable oral cavity. You can choose the skin tone, eye color, and wig, ...

Articles 2026-02-22