Share this

Stepper grating ruler full closed-loop EtherCAT motion controller ZMC432CL-V2 (Part 2): RTSys programming and debugging

2026-04-06 02:46:50 · · #1

The previous lesson introduced the hardware interface of ZMC432CL-V2 (click for details → Stepper Grating Ruler Full Closed-Loop EtherCAT Motion Controller ZMC432CL-V2 (Part 1): Hardware Interface Introduction). This lesson mainly explains how to debug the pulse closed-loop function of ZMC432CL-V2 using RTSys development software.

I. ZMC432CL-V2 Product Introduction

The ZMC432CL-V2 high-performance multi-axis motion controller is an independent motion controller compatible with EtherCAT bus and pulse-based systems. It features high-speed real-time feedback, supports full closed-loop pulse control, and achieves high-precision, high-response motion control. High-precision positioning effectively eliminates mechanical transmission errors, meeting the requirements of high-precision machining applications.

1. ZMC432CL-V2 Hardware Functions

(1) Rich motion control functions: supports linear, circular, spatial circular, and helical interpolation. (2) Rich hardware interfaces: supports pulse axis (with encoder feedback) and EtherCAT bus axis, with 24 inputs and 12 outputs of general-purpose IO, some of which are high-speed IO, and 2 analog outputs (DA). (3) EtherCAT refresh cycle up to 250us, meeting the requirements of high-speed communication. (4) Supports 4-channel hardware comparison output, hardware timer, and precise output during motion, suitable for multi-channel vision flying photography and other occasions. (5) Supports power-off detection, power-off storage, and multiple program encryption methods, which can effectively prevent system failures, protect project engineering file data, and improve system reliability. (6) Project development is carried out through the pure domestic IDE development environment RTSys, which can perform real-time simulation, online tracking, diagnosis and debugging, is easy to use, and supports secondary development through joint programming of multiple high-level host computer languages.

ZMC432CL-V2 Product Introduction Video

For more details about ZMC432CL-V2, click → Stepper Control Grating Ruler Full Closed-Loop Solution: 32-Axis EtherCAT Bus Motion Controller ZMC432CL-V2.

II. Debugging the pulse closed-loop function of ZMC432CL-V2 using RTSys

1. Create a new RTSys project file

Click on [File] → [New Project] → [Enter File Name] → [Save].

2. Create new RTBASIC and RTHMI files. Click 【New】→【Select Basic/HMI】→【OK】 to complete the creation of the Basic and HMI files. The Basic file is used for writing motion logic, and the HMI file is used for designing the human-machine interface. Right-click the HMI file name under 【Project View】, select 【Set Task Number】 in the pop-up option box, and set it to 0. This means that after the controller starts, task 0 will execute the HMI file program.

3. Write the system initialization function and the periodic scan function in the BasicMain.bas file.

·

'/****************************************************************************'Task Number: None'Function: System Initialization'Input: None'Output: None'Return Value: None'Remarks: None'******************************************************************************/GLOBAL SUB SysInit() 'Test firmware information?Test firmware information: ver 24.8.28 : "version_build, "SERVO_PERIOD: "SERVO_PERIOD 'Axis allocation GLOBAL CONST TestAxisId=0 'Thread allocation GLOBAL CONST IntCycleTask=1 GLOBAL CONST OtherTask=2 'Other variables GLOBAL gvCLStstus,gv_HandMode GLOBAL gv_P,gv_I,gv_D GLOBAL gv_VF,gv_AF,gv_OV 'Axis initialization parameters GLOBAL gv_Speed,gv_Accel,gv_Decel GLOBAL gv_Sramp,gv_Inch GLOBAL gv_Units GLOBAL gv_mpos,gv_input GLOBAL VpMode '*********************Axis parameter initialization********************* gv_Units=2000 gv_mpos =4000 gv_input=-20043 gvCLStstus=0 gv_Speed=2 gv_Accel=100 gv_Decel=100 gv_Sramp=0 gv_Inch=1 gv_HandMode=0 VpMode=0 '**********************System initialization********************** RAPIDSTOP(2) 'Stop all axes WAIT IDLE DELAY(100) DATUM(0) 'Clear axis alarms WAIT IDLE '*******************Axis parameter initialization********************* BASE(TestAxisId) 'Disable closed-loop function SERVO=OFF ENCODER_SERVO=OFF 'After disabling the closed-loop function, remotely switch ATYPE from 0 to 4 ATYPE = 0 DELAY(100) ATYPE = 4 'Clear axis coordinates DPOS=0 MPOS=0 'Update axis parameters UpDataAxisPara() 'Update PID parameters UpDatePid(0) ENDSUB'/*********************************************************************************'Task number: None'Function: HMI scan function'Input: None'Output: None'Return value: None'Remarks: None'**********************************************************************************/GLOBAL SUB SysScan() 'Update closed-loop status IF SERVO(TestAxisId) = ON AND ENCODER_SERVO(TestAxisId)=ON THEN gvCLStstus=1 ELSE gvCLStstus=0 ENDIFENDSUB

4. To edit the HMI (Human Machine Interface) file, first click on the Hmi.hmi file in the Project View. In the pop-up Properties window, enter the function names for the Initialization Function and the Periodic Function. After the Hmi.hmi file runs, it will first execute the Initialization Function once to complete the system initialization operation. After the Initialization Function finishes running, the Hmi.hmi file will periodically execute the Periodic Function and periodically scan the operation status of buttons and other controls on the HMI interface.

Click on the [Control Box] to drag and drop the [Controls] in the Control Box onto the Hmi window to design the human-computer interface.

5. How do buttons in the HMI (Human Machine Interface) call functions in the BAS file?

(1) Click the [Full Closed Loop Switch] button to turn the pulse full closed loop function on and off.

First, create a new function in the BasicMain.bas file to complete the logic program for the fully closed-loop function switch.

·

'/*****************************************************************************'Task Number: None'Function: Full Closed-Loop Function Switch'Input: Mode: 0 Turn on/off closed-loop function 1: Update closed-loop Pid parameters'Output: None'Return Value: None'Remarks: None'**************************************************************************/GLOBAL SUB ClosedLoop(Mode) IF Mode=0 THEN IF gvCLStstus= 0 THEN 'Configure pulse axis TestAxisId for full closed-loop function'Configure PID parameters BASE(TestAxisId) P_Gain = gv_P 'P: Proportional gain I_GAIN = gv_I 'I: Integral gain D_GAIN = gv_D 'D: Differential gain VFF_GAIN = gv_VF 'Feedforward gain for velocity feedback AFF_GAIN = gv_AF 'Feedforward gain for acceleration feedback OV_GAIN = gv_OV 'Speed ​​gain' Enable closed-loop function AXIS_ENABLE = ON 'Only effective for full closed-loop when single-axis enable is on ENCODER_SERVO = ON '0-Not enabled (default). 1-Enable closed-loop function'Important, before enabling servo, after enabling encoder_servo' 'Atype must be changed from 0 to 4, otherwise it will report axis:0 config not support Servo. 'Cannot enable closed-loop control, reason unknown ATYPE = 0 DELAY(20) ATYPE = 4 'Pulse output + quadrature encoding feedback SERVO = ON '0-Not enabled (default). 1-Enable closed-loop function DELAY(20) IF SERVO = ON THEN 'Closed-loop parameter configuration completed, closed-loop control is enabled' ELSE 'Closed-loop parameter configuration completed, closed-loop control failed to open, please check axis configuration.' ENDIF ELSE BASE(TestAxisId) SERVO = OFF ENCODER_SERVO = OFF 'After disabling ENCODER_SERVO, an ATYPE switch from 0 to 4 needs to be completed to ensure the closed-loop function is completely disabled. ATYPE = 0 DELAY(100) ATYPE = 4 'Closed-loop control switch is disabled, open-loop movement is used' ENDIF ELSEIF gvCLStstus=1 THEN 'Configure pulse axis TestAxisId as full closed-loop function BASE(TestAxisId) P_Gain = gv_P 'P: Proportional gain I_GAIN = gv_I 'I: Integral gain D_GAIN = gv_D 'D: Differential gain VFF_GAIN = gv_VF 'Feedforward gain for velocity feedback AFF_GAIN = gv_AF 'Feedforward gain for acceleration feedback OV_GAIN = gv_OV 'Velocity gain?'PID parameters have been updated' ENDIFENDSUB

Click the "Full Closed-Loop Switch" button control, and enter the name of the function to be called in the "Click to Call Function" field of the properties interface. At the same time, the function parameters will be passed.

(2) Implementation of manual button function.

First, create a new function in the BasicMain.bas file to complete the logic program for the manual button.

·

'/********************************************************************'Task ID: None'Function: Inching motion and testing'Input: Mode: 1 indicates inching motion, 0 indicates manual motion'Input: Dir: Motion direction 1 positive motion -1 negative motion 0 stop motion'Output: None'Return value: None'Remarks: None'*********************************************************************/GLOBAL SUB InchAndSub(Mode,Dir) BASE(TestAxisId) SPEED = gv_Speed ​​ACCEL = gv_Accel DECEL = gv_DEcel SRAMP = gv_Sramp IF Mode=1 THEN 'Inching motion MOVE(gv_Inch*Dir) AXIS(TestAxisId) 'Inching motion' ELSE IF Dir=1 THEN 'Manual motion positive direction MOVEABS(FS_LIMIT(TestAxisId)) ELSEIF Dir=-1 THEN 'Manual motion in negative direction MOVEABS(RS_LIMIT(TestAxisId)) ELSE 'Stop axis movement when manual motion button is released CANCEL(2) ENDIF ENDIFENDSUB

Click on the relevant control for the [Manual Button], and in the properties interface, click on the [Action Bar] to select the function to call when the button is pressed and released. In the [Action Function Name] and [Release Call Function] fields, enter the function you want to call when the button is pressed and released, respectively, and enter the formal parameters of the corresponding function (the formal parameters of the function can be immediate values, global variables, or registers).

6. Download the program to test the code logic.

After connecting to the controller via the network port IP by clicking 【Connect】, click 【Download to RAM】 (program will not be saved if power is lost) or 【Download to ROM】 (program will be saved if power is lost) to complete the program download.

Click on [Tools] → [Plugins] → [Xplc Screen] to display the human-computer interface on your computer and test related functions.

III. Comparison of open-loop control and fully closed-loop control using an RTSys oscilloscope

For instructions on using an oscilloscope, please refer to the previous post by Zheng Motion Assistant, "Get a clearer and more detailed view of motion control! An introduction to the functions of the RTSys oscilloscope."

1. Analysis of Open-Loop Control

Tests revealed that the open-loop control of the stepper driver maintained a follow-up error (the difference between the planned position and the feedback position from the grating ruler) of approximately 0.02 user units (one user unit, or unit, is set to 1 mm) throughout the motion. At the end of the motion, the feedback position of the grating ruler and the planned position differed by approximately 0.0025 user units, which translates to 0.0025 * user units = 5 pulses. 2. Closed-loop control analysis

Tests revealed that the closed-loop control of the stepper driver maintained a follow-up error (the difference between the planned position and the grating ruler feedback position) of around 0 pulse equivalents during motion, except during start-up and stop.

Compared to open-loop control, this represents a significant improvement. When the motion ends, the feedback position of the grating ruler and the planned position of the command are equal.

IV. Summary

1. When enabling controller closed-loop, note the following: After enabling ENCODER_SERVO, before enabling servo, you must switch the ATYPE from 0 to 4. This is necessary for the controller closed-loop function to be enabled correctly. 2. Enabling controller closed-loop also requires enabling single-axis_enable. This ensures the controller closed-loop function is enabled correctly.

·

'Open closed-loop function BASE(TestAxisId) AXIS_ENABLE = ON 'Only when single-axis enable is on, full closed-loop is effective ENCODER_SERVO = ON '0-Not enabled (default). 1-Enable closed-loop function'Important, before enabling servo, after enabling encoder_servo', 'you must complete an atype switch from 0 to 4, otherwise it will report axis: 0 config not support Servo.ATYPE = 0DELAY(20)ATYPE=4 'Pulse output + quadrature encoding feedback SERVO = ON '0-Not enabled (default). 1-Enable closed-loop function DELAY (20)IF SERVO = ON THEN 'Closed-loop parameter configuration is complete, closed-loop control is on, use move command to move, and monitor motion parameters in oscilloscope.'ELSE 'Closed-loop parameter configuration is complete, closed-loop control failed to open, please check axis configuration.'ENDIF

3. To ensure the complete shutdown of the controller's closed-loop function: After disabling ENCODER_SERVO, an ATYPE switch from 0 to 4 needs to be performed to ensure the complete shutdown of the controller's closed-loop function.

·

BASE(TestAxisId)SERVO = OFFENCODER_SERVO =OFF'After turning off ENCODER_SERV0, an ATYPE switch from 0 to 4 needs to be completed to ensure that the closed-loop function is completely turned off. ATYPE = 0DELAY(100)ATYPE = 4?"The closed-loop control switch is turned off, use open-loop movement."

Full code download address

This concludes our sharing of the second part of our series on the ZMC432CL-V2 full-loop EtherCAT motion controller for stepping grating rulers using positive motion technology: RTSys programming and debugging.

For more exciting content, please follow the "Zheng Motion Assistant" WeChat official account. For related development environment and example code, please contact Zheng Motion's technical sales engineer: 400-089-8936.

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

Discussion on the Integration and Upgrading of DCS Control Systems

1. Process Status and Automation System Background of Nantong Acetate Fiber Co., Ltd. Nantong Acetate Fiber Co., Ltd. (h...

Articles 2026-02-22