Previously, Zheng Motion Technology shared with everyone the firmware upgrade of motion controllers, ZBasic program development, ZPLC program development, communication with touch screens, and the application of input/output IO.
Today, we will explain the application of data and storage in the positive motion technology motion controller.
Video Tutorial: " Video Tutorial: How to Apply Motion Controller Data and Storage?"
I. Material Preparation and Controller Wiring Reference
Materials preparation:
1. One computer with ZDevelop software version 3.01 or later installed.
2. One controller
3. One 24V DC power supply
4. Several bus drivers + motors (or stepper drivers + motors)
5. Several controller wiring terminals
6. Several network cables
7. Several connecting wires
Additionally: I/O devices, expansion modules, touchscreens, etc., can be selected according to requirements.
II. Basic Programming Data Definition
1. Variable definition
Variables are user-defined variables used to temporarily store communication data with external devices or data needed for internal task processing. In other words, they are used to store data with attributes such as name and data type, without needing to specify the allocation between the variable and memory address.
1) Variable definition instructions:
They are divided into three types: global variables (GLOBAL), file module variables (DIM), and local variables (LOCAL).
Global variables can be used in any file within the project;
File module variables can only be used within the same program file;
Local variables are primarily used in SUB files and cannot be used in other files.
Variables can be assigned values directly without being defined; in this case, the variable defaults to a file module variable.
2) Example:
GLOBAL g_var2 'Defines the global variable g_var2
DIM VAR1 'Define file variable VAR1
SUB aaa()
LOCAL v1 'Defines local variable V1
v1=100
END SUB
2. Definition of constants
The CONST directive defines constants. Only one data type can be defined at a time, and the definition and assignment must be on the same line. Constants can be defined as global constants (GLOBAL CONST). Global constants can be used in any file within the project; there is no LOCAL CONST syntax.
Unlike variables, constants are not information stored in memory. Common constants include Boolean, string, time, date, and integer types.
Example:
CONST MAX_VALUE = 100000 'Define file constants'
GLOBAL CONST MAX_AXIS=6 'Define a global constant
3. Array definition
Array specification refers to grouping data with the same attributes together, defining them uniformly, and specifying the number of data items. Each data item that makes up an array specification is called an "element".
The array definition-related instructions are GLOBAL and DIM, but LOCAL definition is not supported.
Example:
DIM array1(15) 'Defines a file array, where the available array space numbers are 0~14, for a total of 15 spaces.
GLOBAL array2(10) 'Define a global array
4. Sub-function definition
Use the SUB directive to define sub-functions. Sub-functions can be defined as file SUBs or defined as globally used SUB procedures by adding the GLOBAL directive. Sub-functions that are called across files must be defined as global SUB procedures.
Example:
SUB sub1() 'Defines procedure SUB1, which can only be used in the current file.
?1
...
END SUB
GLOBAL SUB g_sub2() 'Defines the global procedure g_sub2, which can be used in any file.
?2
...
END SUB
III. Controller Internal Registers
The controller's registers mainly include TABLE, FLASH, VR, and MODBUS registers. After connecting the ZDevelop software to the controller, you can view the size of each register through the "Controller" to "Controller Status" window in the ZDevelop software menu bar. Alternatively, you can use the online command function to enter "?*max" in the "Command and Output" window to view the number of registers. Different controllers have different storage capacities.
1. TABLE array
TABLE is a very large array that comes with the controller. The data type is 32-bit floating point (64-bit floating point for series 4 and above). It is not saved when power is lost.
When writing programs, the TABLE array does not need to be redefined and can be used directly, with the index starting from 0.
Some ZBasic commands can directly read values from a TABLE as parameters. When using a TABLE, the parameters are first stored in a specific location within the TABLE, and then the TABLE data is retrieved using the command parameters. Examples include commands such as CAM, CAMBOX, CONNFRAME, CONNREFRAME, MOVE_TURNABS, B_SPLINE, CAN, CRC16, DTSMOOTH, PITCHSET, and HW_PSWITCH.
The parameters sampled by the oscilloscope are stored at the end of the TABLE array. Therefore, in application development, attention should be paid to the allocation and use of the TABLE area to avoid overlap with the data storage area of the oscilloscope samples.
The TABLE command reads and writes data. Example:
TABLE(0) = 10 'table(0) is assigned the value 10
TABLE(10,100,200,300) 'Batch assignment, table(10) is assigned 100, table(11) is assigned 200, table(12) is assigned 300
The TSIZE command can read the size of a TABLE and also modify its size (but cannot exceed the maximum TABLE size). Example:
PRINT TSIZE 'Prints the size of the controller table'
TSIZE=10000 'Sets the size of the table; it cannot exceed the maximum size of the controller table.'
The TABLESTRING command prints data from a TABLE in string format. Example:
TABLE(100,68,58,92)
PRINT TABLESTRING(100,3) 'Prints string data, converts it to ASCII code.'
Print result: D:\
2. FLASH
FLASH has a power-off storage function, with a read/write cycle limit of about 100,000 times, and data will not be lost even if the power is not turned on for a long time.
It is generally used to store large amounts of data that do not require frequent reading and writing, such as processing technology documents. A processing technology document can be stored in one sector or several sectors.
When reading and writing, be sure to ensure that the names and order of the variables, arrays, etc. being operated on are consistent. Inconsistency will lead to data corruption.
When using FLASH, it is numbered by block. The number of blocks can be viewed using the FLASH_SECTES command. Different controllers have different numbers of FLASH blocks and different block data sizes. The size of each block data can be viewed using the FLASH_SECTSIZE command.
How to use Flash:
GLOBAL VAR
GLOBAL ARRAY1(200)
DIM ARRAY2(100)
'Data storage to FLASH block: Write the VAR, ARRAY1, and ARRAY2 data into FLASH block 1 sequentially.'
FLASH_WRITE 1, VAR, ARRAY1, ARRAY2
'FLASH block data reading: Read the data of FLASH block 1 into VAR, ARRAY1, and ARRAY2 sequentially.'
FLASH_READ 1, VAR, ARRAY1, ARRAY2 'The read order is consistent with the write order.
3. VR Register
The VR register has a power-off storage function and can be read and written an unlimited number of times, but its data capacity is small, usually only 1024 or less. It is used to store data that needs to be modified constantly, such as axis parameters and coordinates.
The VR's power-off data retention principle is based on the ferroelectric memory inside the controller, but the data capacity is small. Therefore, for large amounts of data or data that needs to be stored for a long time, it is best to write it to the FLASH block or export it to a USB flash drive.
VR storage data type is 32-bit floating point (64-bit floating point for 4 series and above). VR_INT is used to force storage as a 32-bit integer, and VRSTRING is used to force storage as a string. It stores ASCII code, and one character occupies one VR.
VR, VR_INT, and VRSTRING share the same memory space. Register read and write methods are the same.
How to use VR:
VR(0) = 10.58 'Assign value
aaa = VR(0) 'Read
4. MODBUS Register
MODBUS communication data is stored in MODBUS registers. The controller's MODBUS registers conform to the MODBUS standard communication protocol and are divided into two categories: bit registers and word registers.
Bit register: MODBUS_BIT, commonly referred to as MODBUS_0X on touchscreens, Boolean type.
Word registers include MODBUS_REG (16-bit integer), MODBUS_LONG (32-bit integer), MODBUS_IEEE (32-bit floating-point), and MODBUS_STRING (8-bit byte). Touchscreens typically use MODBUS_4X.
In the controller, the MODBUS word registers occupy the same system variable space. One LONG register occupies two REG addresses, and the other IEEE register also occupies two REG addresses. When using them, care should be taken to stagger the word register number addresses.
MODBUS_LONG(0) occupies two REG addresses, MODBUS_REG(0) and MODBUS_REG(1).
MODBUS_LONG(1) occupies two REG addresses, MODBUS_REG(1) and MODBUS_REG(2).
MODBUS_IEEE(0) occupies two REG addresses, MODBUS_REG(0) and MODBUS_REG(1).
MODBUS_IEEE(1) occupies two REG addresses, MODBUS_REG(1) and MODBUS_REG(2).
Therefore, it is important to note that the MODBUS_REG, MODBUS_LONG, and MODBUS_IEEE addresses must not overlap in user applications.
The controller's MODBUS storage space is arranged as follows:
MODBUS commands
MODBUS communication requires data to be placed in MODBUS registers for transmission.
There are dedicated MODBUS communication instructions for reading and writing data in MODBUS registers and transferring data between registers.
MODBUS read/write syntax is the same, as shown below:
MODBUSM_REGGET (startreg, num, local_reg)
startreg: The starting register number on the other end, starting from 0.
num: Number of registers
local_reg: Value retrieved from the local system MODBUS register, starting number.
Example:
MODBUSM_REGGET(0,10,0) 'Copies local bit registers 0-9 to registers 0-9 on the communication peer's registers.
The MODBUS commands are as follows. For detailed usage instructions, please refer to the Basic manual:
MODBUS_BIT -- Bit Register
MODBUS_IEEE -- Word register - 32-bit floating-point
MODBUS_LONG -- Word register - 32-bit integer
MODBUS_REG -- Word register - 16-bit integer
MODBUS_STRING -- Word register-byte
MODBUSM_DES -- Modbus communication connection
MODBUSM_DES2 -- Inter-controller network communication
MODBUSM_STATE -- Modbus communication status
MODBUSM_REGSET -- Write to the peer holding register
MODBUSM_REGGET -- Read the peer holding register
MODBUSM_3XGET -- Read the peer input register
MODBUSM_BITSET -- Write to the opposite coil
MODBUSM_BITGET -- Read the opposite coil
MODBUSM_1XGET -- Read the discrete input from the other end
IV. Data Types and Data Conversion
1. Data types
The data types stored in common registers and the value range of each data storage unit are shown in the table below:
2. Data Conversion
Operations between different types of data can cause the following problems:
A. Data loss: The fractional part will be lost when converting from a floating-point number to an integer.
Example:
VR(0) = 10.314
MODBUS_REG(0)=0
MODBUS_REG(0) = VR(0)
?MODBUS_REG(0) 'Result is 10
B. Forced conversion: After an integer is stored in a floating-point register, it becomes a floating-point number, and using integer operations on it may result in incorrect data.
C. Single-precision data has only 7 significant digits. If there are long-term accumulated values during the calculation process, it is recommended to use a 4-series controller.
V. Basic Example Programs
The following are sample basic programs and oscilloscope demonstration diagrams.
Task 1 runs, executes the cam table instruction, and the waveform is shown in the following figure:
Today, we've shared our insights on the application of motion controller data and storage in ZhengMotion Technology. For more exciting content, please follow our official WeChat account. (Add a sentence before the oscilloscope diagram.)
This article was originally created by Zheng Motion Assistant. We welcome everyone to reprint it for mutual learning and to improve China's intelligent manufacturing capabilities. Copyright belongs to Zheng Motion Technology. Please indicate the source if you reprint this article.
Zheng Motion Technology is a national high-tech enterprise specializing in the research and application of motion control technology. It mainly engages in the research, development, production, sales and service of a series of products such as motion controllers, motion control cards, IO expansion modules and motion display and control all-in-one machines.
The company has gathered outstanding talents from companies such as Huawei and ZTE. While adhering to independent innovation, it actively collaborates with major universities to dedicate itself to the research and application of motion control technology. It is one of the fastest-growing companies in the domestic industrial control field and also one of the companies in China that has fully mastered the core technologies of motion control and real-time industrial control software platform technology.