Bring Values and Sucesses To Our Customers

Home / Support and services / Technical Support

Technical support

Technical Support

Motion Control Quick Start (6) | How to Achieve Data Storage 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 
Now, today, let's start one new thing, how to achieve data storage for motion controller. 
Here, introduce it from 5 parts.

1. Material Preparation

--Materials--

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

(2) One controller.

(3) One 24V DC power supply.

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

(5) A number of controller wiring terminals.

(6) Several network cables.

(7) A number of connecting wires.

In addition, IO equipment, expansion module, HMI, etc. can be selected according to requirements.

 

--Wiring Reference--

image 1.png






2. Basic Program Data Definition

(1) Variable

Variable is the parameter that can be self-defined by users. It is used to temporarily save communication data with external equipment or data that's processed by task inside. Namely, it saves data that is with property, such as, name or data type, etc. There is no need to assign address allocation between variables and memory addresses.

--Variable definition instruction:

There are three kinds of instructions, global variable (GLOBAL), file module variable (DIM) and local variable (LOCAL).

Global variable (GLOBAL): it can be used in any file of project.

File module variable (DIM): it only can be used in file inside project.

Local variable (LOCAL): it is mainly used in the SUB, which means it is invalid in other files.

And variable can be assigned without definition, now variable is the DIM by default.

Example:

GLOBAL   g_var2                  ′define the global variable g_var2

DIM   VAR1                         ′define file module variable VAR1

SUB   aaa()

   LOCAL   v1                      ′define local variable V1

   v1=100

END SUB

 

(2) Constant

CONST defines a constant once time, and the definition and assignment must be the same line. Constant can be defined as global constant GLOBAL CONST. GLOBAL is used in any file, but there is no way to write LOCAL CONST.

Constant is different from variable, it doesn't save the information in memories. There are some common constants, such as, Boolean type, Character String type, Time type, Date type, Integer type, etc.

Example:

CONST    MAX_VALUE = 100000      ′define file constant

GLOBAL CONST    MAX_AXIS = 6     ′define global constant


(3) Array

Array assignment means that the data of the same attribute are collectively defined, and the number of data is designated. The pieces of data that make up the array are called "elements".

GLOBAL and DIM are relative instructions, but LOCAL definition is not supported.

Example:

DIM  array(15)                          ′define file array, valid 15 arrays, number 0~14

GLOBAL  array2(10)                  ′define global array, valid 10 arrays, number 0~9


(4) Subfunction

Use SUB isntruction to define subfunction, and subfunction can be defined as file SUB. or adding GLOBAL instruction in the front to define as SUB process used by global.

Example:

SUB sub1()         'define SUB1, only can be used in current file.

       ?1

      ...

END SUB

GLOBAL SUB g_sub2()        'define global process g_sub2, can be used in any file.

       ?2

       ...

END SUB






3. Controller Internal Register

There are 4 registers for motion controller, they are TABLE, FLASH, VR and MODBUS. Connect to controller through ZDevelop, firstly, then in "Controller"--"State the Controller" window can check each register space, or you could enter "?*max" to view relative information, and controllers are different.

image 2.png

image 3.png

(1) TABLE Array

TABLE is a very large array that comes with the controller, the data type is 32-bit floating point (4 series and above are 64-bit floating point), please note is doesn't support power failure storage.

When writing a program, the TABLE array does not need to be defined again and can be used directly. And the index subscript starts from 0, and it is valid to assign value and read in bulk.

Some instructions of ZBasic can directly read the values in TABLE as parameters, while using TABLE, save parameters in one certain position in TABLE, then call TABLE data through instructions, such as CAM, CAMBOX, CONNFRAME, CONNREFRAME, MOVE_TURNABS, B_SPLINE, CAN, CRC16, DTSMOOTH, PITCHSET, HW_PSWITCH, etc.

Parameters sampled by the oscilloscope are also stored in TABLE. Therefore, in the development and application, pay attention to the allocation and use of multiple TABLE areas, and do not overlap with the data storage area sampled by the oscilloscope.  

1) TABLE instruction reads and writes data:

TABLE(0) = 10                       ′assign TABLE(0) as 10

TABLE(10,100,200,300)           ′mass assignment, assign TABLE(10) as 100, assign TABLE(11) as 200, assign TABLE(12) as 300

 

2) TABLE size can be read by TSIZE instruction, and can be modified (can't be over TABLE max space).

PRINT   TSIZE        ′print controller TABLE size

TSIZE = 10000       ′set TABLE size, which can’t be over max controller TABLE size

 

3) TABLESTRING instruction prints data in TABLE according to character string format.

TABEL(100,68,58,92)

PRINT TABLESTRING(100,3)    ′print data in string form, then convert to ASCII code.

PTINT RESULT: D:\


(2) FLASH

FLASH has a power-down storage function, and the number of reading and writing limit is 100,000 times, and data will not be lost if it is not powered on for a long time.

It is generally used to store large data that does not require frequent reading and writing, such as processing files.

When reading and writing, pay attention to ensure that the names and order of variables, arrays, etc. to be operated are highly consistent. If they are inconsistent, data will be cluttered.

When FLASH is used, it is numbered as per block, including save data (variables, arrays, etc. ) and read data. The number of blocks can be checked through "FLASH_SECTES" instruction. FLASH blocks and block data size of controllers are different, the size of each are checked through FLASH_SECTSIZE instruction.

Note: data must be written write into FLASH before reading, otherwise an alarm WARN will be prompted.

How to use FLASH:

GLOBAL   VAR                         ′variable definition

GLOBAL   ARRAY1(200)            ′array definition

DIM    ARRAY2(100)

data is stored in FLASH block: Write VAR, ARRAY1, ARRAY2 data into FLASH block 1 in turn

FLASH_WRITE 1, VAR, ARRAY1, ARRAY2

FLASH block data read: read the data of FLASH block 1 into VAR, ARRAY1, ARRAY2 in sequence

FLASH_READ 1, VAR, ARRAY1, ARRAY2  'The reading order is consistent with the writing order

(3) VR

The VR register has a power-down storage function and can be read and written infinitely, but the data space is small, like XPLC006E series controllers, there are 1024 addresses. The VR space of the latest series of controllers is 8000, which is used to save data that needs to be modified continuously, such as axis parameters, coordinates, etc.

The principle of VR's power-off storage is that the controller has a power shortage memory inside, but the data capacity is small, so the data with a large amount of data or data that needs to be saved for a long time is best to be written into the FLASH block or exported to a U disk.

And the data type is 32-bit floating point (4 series and above are 64-bit floating point). But use VR_INT to force an integer with 32-bit, and use VRSTRING to force a string, the saved data is ASCII code, one character occupies one VR.

VR, VR_INT, VRSTRING share a space. Read and write methods are the same.

How to use VR:

VR(0)=10.58                             ′assign

aaa = VR(0)                              ′read

(4) MODBUS

MODBUS register conforms to MODBUS standard communication protocol, there are bit register and word register.

--Bit register: MODBUS_BIT, for touch screen, it is called MODBUS_0X, Boolean type.

--Word register: MODBUS_REG, MODBUS_LONG, MODBUS_IEEE, MODBUS_STRING. For touch screen, it is called MODBUS_4X, see the below:

 1678701698595966.png

 

The MODBUS word register in the controller occupies the same variable space, one LONG occupies two REG addresses, and one IEEE also occupies two REG addresses. When using, pay attention to stagger the word Register No. address.

1678701720965886.png

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, pay attention not to overlap MODBUS_REG, MODBUS_LONG, MODBUS_IEEE addresses in users application programs.

image 6.png

 

MODBUS command

MODBUS communication needs to transfer data in MODBUS registers.

There are special MODBUS communication instructions to read and write the data of MODBUS registers and transfer data between registers.

The MODBUS read/write syntax format is the same, as follows:

MODBUSM_REGGET (startreg, num, local_reg)

        startreg: starting number of the register at the relative station, starting from 0

        num: the number of registers

        local_reg: get the value from the MODBUS register of the local system, the starting number

Example:

MODBUSM_REGGET(0,10,0)

'copy the local bit register 0~9 to the register 0~9 of the communication relative station

The MODBUS command is as follows, and the detailed usage of the command can be found in the Basic manual:

MODBUS_BIT -- bit register

MODBUS_IEEE -- word register - 32-bit floating-point type

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 -- network port communication between controllers

MODBUSM_STATE -- Modbus communication status

MODBUSM_REGSET -- holding register to write corresponding station

MODBUSM_REGGET -- holding register to read corresponding station

MODBUSM_3XGET -- input register to read corresponding station

MODBUSM_BITSET -- write corresponding station coil

MODBUSM_BITGET -- read corresponding station coil

MODBUSM_1XGET -- read the discrete input of the corresponding station






4. Data Type & Conversion

(1) Data Type

image 7.png


(2) Data Conversion

Operations between different types of data will cause the following problems:

A. Data loss:

The decimal part will be lost when the floating-point type is converted to an integer type.

Example:

VR(0)=10.314

MODBUS_REG(0)=0

MODBUS_REG(0)=VR(0)

?MODBUS_REG(0)     'the result is 10

 

B. Convert compusively:

After the integer is stored in the floating-point register, it will become a floating-point type, and the integer operation data may be incorrect.

 

C. Single-precision data has only 7 valid values. If there are long-term accumulated values during the calculation process, it is recommended to use 4 series controllers.




5. Basic Routine

Below are Basic routine and display graphic:

image 8.png

image 9.png





ABOUT ZMOTION

That's all, thank you for your reading -- Motion Control Quick Start (6) | How to Achieve Data Storage.

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