HCFA PAC PLC Debug Tutorial
HCFA PAC PLC Debug Tutorial
TEL:
FAX:
Version: V3.0 ATCCA01
Version Updates
Disclaimer
We have tested the content described in this manual. However, mistakes are inevitable, and there
is no guarantee that it is absolutely correct and fully meets your needs. And the manual may
change without notice, and your improvement suggestions are also welcome.
For any questions, feel free to email:[email protected]
Q1-Series PACs Debugging Tutorial V3.0--------------------------------------------------------------------1
Overview----------------------------------------------------------------------------------------------------1
Files contained in the document---------------------------------------------------------------------------1
Version Updates---------------------------------------------------------------------------------------------1
Disclaimer---------------------------------------------------------------------------------------------------1
Q1-Series PACs Debugging Tutorial-----------------------------------------------------------------------3
1 Create CODESYS project------------------------------------------------------------------------7
2 Select target device and programming language----------------------------------------------7
3 Establish communication with Q1 controller---------------------------------------------------8
4 Create PLC Project-------------------------------------------------------------------------------9
4.1 Add Library---------------------------------------------------------------------------------9
4.2 Task setting-------------------------------------------------------------------------------10
4.3 PLC programming------------------------------------------------------------------------11
4.4 Add Trace to monitor Program Variables-----------------------------------------------14
5 Program download and online monitoring---------------------------------------------------16
5.1 PLC program compiling and download-------------------------------------------------16
5.2 Log in and running-----------------------------------------------------------------------16
5.3 Online monitoring------------------------------------------------------------------------18
5.4 Reset function----------------------------------------------------------------------------19
6 Built-in high-speed IO debugging description------------------------------------------------20
6.1 As the general input/output-------------------------------------------------------------20
6.2 As the high-speed input/output---------------------------------------------------------21
7 Add extension modules (including local extension)------------------------------------------26
8 Creat Motion project---------------------------------------------------------------------------27
8.1 Add SoftMotion project (without adding remote extension modules)----------------27
8.2 Modify EtherCAT master station information and communication parameters-------29
8.3 Single-axis motion control instructions-------------------------------------------------30
2
Q1-Series PACs Debugging Tutorial
The Q1-series PACs are the multifunctional standard controller based on CODESYS programming and
debugging platform. This manual will introduce how to test Q1-series PACs on the CODESYS platform,
including how to use the local high-speed input and output, Q series couplers and remote extension I/O
(currently introduce digital And analog input and output), single-axis and two-axis motion control.
Compared with the V2.0, the main changes are as follows. Refer to Appendix D for the version view
method.
Items V205(Hardware 2.0) V301(Hardware 3.0)
No mounting hook With mounting hook, firmly stuck
Power supply terminal
GND: Close to DIN rail, 24V: Close to indicators
Local extension Not supported Local extension power: Max. 16W
Terminal block Only parallel crimping pliers Not defined, meet the requirement of wire
diameter
COM. port N/A Add the guide plastic sheet
8-ch high-speed inputs, no 8-ch high-speed input, added 8-ch high-
High-speed I/o
high-speed output speed outputs
Serial communication 2-ch RS485 2-ch RS485,added 1-ch RS232
Modbus Support ModbusTCP Tree-type for communication function, as
Support Modbus RTU shown below
Ethernet
cable
3
① RJ45 interface, programming interface, connected to the host PC and supports the Ethernet protocol
② RJ45 interface, programming interface, connected to the host PC and supports the Ethernet protocol
③ EtherCAT master interface,support EtherCAT protocol
④ Run-Stop dial switch,Run on the right
⑤ EC coupler module establish the communication with host CPU unit via network cable through the bottom network port (EtherCAT protocol)
Note
EC coupler module needs the customized network cable, and the
customized network cable and adapter are provided with the EC coupler.
EtherCAT IN
EtherCAT OUT
⑥ Digital I/O module,For channel definition and wiring, please refer to the digital input module channel and wiring
4
⑦ Analog I/O module
Analog input module channel and wiring(24VDC needs to be connected at the top of analog module as the load power
supply)
5
Analog output module channel and wiring(24VDC needs to be connected at the top of analog module as the load power
supply)
6
⑧ EC module network cable
After completing the wiring and power supply, add the PLC program in CODESYS to debug the module and
servo drive.
1 Create CODESYS project
After installing the CODESYS software, find on the desktop. Double-click the software to find the New
Project in the startpage or find File – New Project in the menu.
1 2
Project type
Project description
Project name
Save path
The user can select the desired project type, enter the project name and path, and then click "OK"
2 Select target device and programming language
According to the default guidance of CODESYS, select the target device and the programming language
of the main program PLC_PRG. Then install the Q1 main unit or you cannot select the correct target
device. Refer to Appendix A for the installation steps of the new device description file.
Target device
7
3 Establish communication with Q1 controller
The default IP address of Q1 controller Port1 is: 192.168.188.100 Subnet mask: 255.255.255.0. Modify
the IP to the same network segment in the PC network adapter(Default IP address of Port2:
192.168.88.xxx Subnet mask:255.255.255.0)
2 3
2
Double-click Device→Scan network. After scanning to Q1, select the device and click OK.
2
1
8
The correctly added device is shown as follows.
9
CODESYS can identify the library version automatically and support switching between multiple versions
of library files. If you need to uninstall, just select the library file that needs to be uninstalled → click the
uninstall button.
10
For the new PLC program created by the user, you need to manually configure and call the task,
otherwise the program will not be executed. Double-click Main Task → Add Call → Select the PLC
program to be called and click OK.
Task priority
11
Double-click PLC_PRG to enter the programming interface. From top to bottom, there are Variable
declaration window, Main program window and Message window. The errors, warnings in compilation and
compilation information will shown in the Message window.
Variable declare
Main program
Message window
12
First, declare the variables that need to be used in the program in accordance with the IEC61131-3
programming standard,
The variable declaration: Variable name: Variable data type: = Initial value; The initial value may not be
given, the variable has a default initial value, single-line comments are made through "//", and Chinese
comments are supported, but the cursor position may display incorrectly, so English comments are
recommended to use for the time being.
In the variable declaration window, press Shift+F2 to show the dialog box of Automatic Declaration,
where the name and type must be entered.
Shift F2
Scope:Variable scope
Name:Variable name
Type:Variable data type
Object:Variable application
Initialization:Variable initial value
Address:Mapping between variables and external hardware points
Flags: Variable type can be set to Constant,
Retain and Persistent
Comment:Comment, format (*contents*)
Variable declare 语
Comments
Write the example program in the main program window. The correctly declared variables can be called
by F2 in the main program window. Pay attention to the calling type.
Variable: Single variable, need to be declared
F2
13
Example call: Function block statement, need to be declared
14
Click the configuration button in the upper right corner of the Trace interface to add and delete
monitoring variables and set the sampling period. After opening the Trace page, add and delete
variables through the add/delete variable buttons in the lower left corner.
Click the Task followed by the sampling cycle on the left menu, drop down to select the Main Task for
example.
After completing the basic configuration of Trace, you need to log in the program and run it normally
before you can download and start the trace (Start Trace) anywhere on the Trace interface and observe
the variable running trace. Otherwise, the item is grey by default and cannot be selected
15
5 Program download and online monitoring
5.1 PLC program compiling and download
After the PLC program writing is done, the program needs to be compiled before downloading. The
buliding command will check the grammar and the POU must be added to the Task, or not compiling.
Select the Build→ Build, the compiling result will show in the message window after executing the
compile command, and the information that needs to be viewed can be displayed separately by
selecting errors, warnings and messages.
Compiling results
16
When no errors in compiling the program, we can log in. Find the login-in icon in the toolbar and
enter into the program online monitoring.
A dialog box pop-up: The downloaded application will replace the existing application in the PLC. To
continue to download? Then click "Yes".
Variables/program online
监控状态显示
Running status
17
Right-click anywhere on the Trace page to pause or start the trace. Move the mouse to observe the History
trace and the scroll wheel can zoom in and out of the trace waveform.
18
Choose Monitor 1, click the empty column, you can directly call the variables or global variables in different
POUs by clicking the index, or you can click on the right to expand to add the variables that need to be
monitored online.
After the configuration completed, you can view the real-time value of the variable through the "Monitor 1"
under the message window during the normal operation of the program, and assign values to the current
variable. You can manually add or delete the monitoring variable even during the normal operation.
Online watch
After logging in, you can enter the value you want to write in the next cycle in the preparation value. This
operation can be completed in the Variable declaration window, Main program window and Monitoring
window. After inputting values, choose Debug → Write values to write the correct value. In CODESYS, users
can assign values to variables in two ways: Write value (Ctrl+F7) and Forced value (F7). The value written by
forced value will be identified on the left, which can be restored by releasing the value.
19
Note: X:Retention value O:Initial value
Online VAR VAR RETAIN VAR RETAIN
instruction PERSISTENT
Warm reset O X X
Cold reset O O X
Initial value reset O O O
Download O O X
Online change X X X
20
The wiring method of the local IO in this mode can directly refer to the wiring method of the digital input
module. After adding finished, you can monitor the current local IO status or perform test output under the
General I/O mapping on the right.
Pleased note that when there is no program test, the IO refresh cycle needs to be selected as: Always in the
bus cycle task, otherwise the IO with unmapped variables will not be refreshed, and the current IO will be
refreshed with the program variables if the program variables are mapped.
21
X0
X1
Common
terminal
High-speed input supports PNP and NPN, wiring method depends on the input type of the encoder.
For the input signal of PNP type, connect 0V to the common terminal; If NPN type, connect 24V. And
the common terminal is internally connected.
2)Wiring for high-speed output(No high-speed output function temporarily, will be improved)
At the same time, you can add General IO, but for input (output), only one input (output) method can
be selected. When using the high-speed input, you need to install the device description file contained
in the folder: The file in HIS_Counter_Drv and LocalHSInput.xml. Refer to Appendix A for the installation
steps. After the installation completed, LocalDevice→Add Device→to add high-speed IO in
LocalHSInput.
22
After adding, click LocalHSInput→Add Device to add the high-speed input channel. Max.8 channels
can be added. Refer to the following table for corresponding relationships:
。
HCFA added the corresponding library files for high-speed IO, so you need to install hcfalib.compiled-
library before use. After the installation completed, find the function block named hsi_ref in the library
file. Add this function block to the main program and enter the corresponding port to use high-speed
input. A brief description of the function block is as follows:
23
Right-click in the main program and add Action to the Add Object. In the pop-up dialog box, select
Function Block Diagram (FBD) as the programming language.
Define the variables that need to be used in the function block in the Variable declaration window of the
main program as follows:
24
Find his_cnt in the global variable in the newly-added Action, and configure the channel that to be used.
After the configuration completed, set the corresponding parameters to make the counter work in
different modes. For the description of different modes and test results, please refer to the attachment.
HCQ1- Input test.xlsx
The high-speed input is temporarily an internal test function. If the test results are different or there are
any problems during the test, you can directly contact the HCFA Technology. Please wait for the
subsequent official release of the official version. There are no functional blocks and test reports for the
high-speed output.
25
7 Add extension modules (including local extension)
The Q1 controllers of V301 version support local IO extension on the right side with a maximum power
of 16W. The following table shows the power of extension modules supported by Q1 controllers.(Data
are calculated as 10% to 15% rise, because the metal sheet transmission bus current signal will produce
a certain resistance over time, thus consuming part of the power):
Item Model name for modules Power
1 LocalEtherCATDevice 16W
2 HCQX-EC-D 1.344W
3 HCQX-ID16-D 0.78W
4 HCQX-0D16-D 1.32W
5 HCQX-MD-D 1.032W
6 HCQX-AD04-D 1.044W
7 HCQX-DA04-D 1.056W
Right-click Device→Add Device, select EtherCAT Master SoftMotion in the dialog box to add the device.
After the addition completed, select the correct network card and download it to Q1 controller(login in
Q1 controller). It is recommended that the user select the network by name so that the program can be
matched on more devices (the Mac address of the network port of different devices is different)
26
After login, right-click EtherCAT_Master_SoftMotion to scan device. It is recommended to add the
device by scanning the device. But you also can choose to Add Device.
If an unknown device appears in the scan device dialog box, the user needs to check whether the
description file used matches or not. The correctly scanned module is displayed as follows:
Local extension
Copy all the devices to the project to complete the module adding. It is important to note that the Q1
controller of 3.0 version supports local extension. When manually adding, you need to add
LocalEtherCATDevice to add other modules.
8 Creat Motion project
8.1 Add SoftMotion project (without adding remote extension modules)
Right-clcik Device→Add Device,select EtherCAT Master SoftMotion to add devices.
27
Right-click EtherCAT Master SoftMotion to add device, At this time, you need to add the servo drive
that needs to test in the slave station, select SV-X3E to add device.
Right-click on the added slave station SV-X3E and select Add SoftMotion CiA402 Axis. Click OK when
dialog box pops up.
28
Right-click SM_Drive_GenericDSP402, select Refactoring→Rename ‘SM_Drive_GenericDSP402’, and
modify it to Axis1 so that the relevant axis variables can be called in the PLC program later.
The system will automatically complete the mapping of the axis variable after renaming, click "OK" to
complete the axis renaming.
29
Double-click the added EtherCAT master station. First, you need to select the network adapter for
communication. Select “Browse” on the right of source address, select the network card ECAT1, and
click OK.
Modify the encoder parameter settings in Axis1. For X3E series servo drive, 17-bit encoder, and the
increment is 16#20000.
30
Variable declarations
Main program
Add Motion project in CODESYS, EtherCAT_Task will automatically generate in task configuration.
The user needs to manually set the EtherCAT_Task parameters, otherwise the synchronization cycle will be
lost during the subsequent axis operation. Double-click Application→Task Configuration→EtherCAT_Task,
Call PLC_Motion here. For specific steps, refer to section 4.2 and set the priority to "0".
31
After modifying the hardware setting, log in and run the program. When the servo drive and axis
operate normal, double-click PLC_Motion .
32
After enabling Axis1, set bJogfw to TRUE to positive jogging, and set bJogbw to TRUE to reverse
jogging. For editing and using other axis function blocks, refer to CODESYS Online Help:
https://help.CODESYS.com/
33
Appendix A Installation of Device Description File
The library files required by Q1 controller and its extension modules are currently packaged into a
package. Users only need to double-click the Package Manager and follow the instructions to install the
files, as Method 1. If the user wants to install the XML file separately, please refer to Method 2.
Method 1:
1. Find Tools →Package Manager→Install, to select the corresponding package manager.
Select Customized installation to make it easier to view the files in the installation package, then select
Next.
2. View the files contained in this package in Select Components, and tick the files that need to be installed, and click
Next to install.
34
3. Click Finish to complete the installation.
Method 2: Take Q1 controller as an example for device description file installation, the rest of the
description files are provided in the folder(Including general I/O, X3T servo drive, high-speed counting)
1. Find Tools→Device Repository in the menu bar
35
2. Click to enter the Device library, select the correct device description file, and click Install.
2
3. The other device description files also need to be installed.. After the installation completed, the Q1 controller can be
found in the device library, and the installation information will show in the dialog box, as shown below by the arrow. For
devices that do not need to be used, right-click the device to uninstall it.
36
4. If the user needs to change the PLC program running platform, and the project has been created at this time, you need to
right-click Device→Update Device to switch the PLC program.
Solutions:
Click Build → Clear All, and then rebuild the program to eliminate the error. This is a problem with the
Chinese version of CODESYS, and can be fixed in the next version.
37
Appendix D Check software and hardware version
The hardware version for Q1 controller can be viewed in the first four digits of the P/N on the label, as
shown in the figure: V3.01.
The software version for Q1 controller can be found when scanning to add Q1 controller, as shown in
the figure: V322 .
38