14 External Device SER instruction

Last modified by Devin Chen on 2024/03/13 10:14

6.14.1 RS instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
RSSerial data transfer16NoRS S m D n9

RS is a transceiver instruction that automatically sends the data stored in the specific register to the serial port sequentially and stores the data received by serial port in the specific area. It is equivalent to directly access the communication buffer.

OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
m             
D               
n             

COM2 (communication port): it uses RS485, it supports program protocol (PLC protocol), MODBUS protocol (MODBUS-RTU slave, MODBUS-RTU master, MODBUS-ASCII slave, MODBUS-ASCII master), N:N network protocol (so far, only available in LX3VP series PLC). The communication protocol is set by D8126, the communication parameters are set by D8120, the detailed as below.

Communication setting for COM2
ProtocolThe value of D8126Communication parameters
HMI monitor protocol (PLC protocol)0x01Set by D8120
MODBUS-RTU slave0x02Set by D8120
MODBUS-ASCII slave0x03Set by D8120
User-defined protocol0x10Set by D8120
MODBUS-RTU master0x20Set by D8120
MODBUS-ASCII master0x30Set by D8120
ItemParameterBit value of D8120
b7b6b5b4b3b2b1b0
Baud rate (Bps)1152001100----
576001011----
384001010----
192001001----
96001000----
48000111----
Stop bit1 bit----0---
2 bit----1---
ParityNone-----00-
Odd-----01-
Even-----11-
Data bit7 bit-------0
8 bit-------1
Example: the communication format is 9600.1.8.None, b7b6b5b4=1000, b3=0, b2b1=00, b 0=1. D8120=81H ( (10000001)2=81H, 81H means hexadecimal number)

RS (user-defined Protocol) Instruction Description

  • S: the head address of the register where the to be sent data stored in
  • m: the length of the to be sent data (byte), 0 to 256.
  • D: the head address of the register where the receive data stored in
  • n: the length of the receive data(byte),0 to 256

Example

7-13 External Device SER instruction_html_f99ab6b4507ab8d3.jpg

When X1 is ON, the receive data and the sand data is shown as below.

7-13 External Device SER instruction_html_786790195df2bc8c.jpg

The RS (MODBUS mode) instruction automatically sets the M8123 once every time a transmit data is received and the acknowledge operation is received. Using this flag, it is possible to determine whether the RS instruction has been executed.

7-13 External Device SER instruction_html_85ff4d260275024.jpg

In actual programming, you need to do some preparation for serial communication and configuration, such as baud rate, check bit, timeout judgment condition, protocol etc. The same example, a relatively complete set of RS communication procedures are as follows.

7-13 External Device SER instruction_html_8740de6f5aae261a.jpg

RS (MODBUS Protocol) Instruction Description

The definitions of each operand in the RS (MODBUS mode) instruction are different from those of a standard RS instruction (user-defined protocol).

  • S: Slave address (high byte), communication command (low byte, defined by MODBUS protocol);
  • m: Start address of accessing slave;
  • D: Data length, unit: word;
  • n: Start address of data storage, the take up length of the subsequent address defined by D;

7-13 External Device SER instruction_html_4db9718f9518d45c.jpg

Program example

The PLC is set to MODBUS-RTU master mode, it reads data from address 100 of Slave 1, and read the data stored in D10.

7-13 External Device SER instruction_html_49cd20661ddc2025.jpg

6.14.2 RS2 instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
RS2Serial data transfer 216NoRS S m D n n111

This instruction is mainly used for serial data transfer instruction in BD board module.

RS2 is a transceiver instruction that automatically sends the data stored in the specific register to the serial port sequentially and stores the data received by serial port in the specific area. It is equivalent to directly access the communication buffer.

The RS2 instruction is used to configure the communication protocol according to the CPAVL instruction. For details, refer to the LX3V-2RS485-BD User's Manual, LX3V-ETH-BD User's Manual or the CPAVL Instruction Manual.

OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
m             
D               
n             
n1             

In LX3V-2RS485-BD module

  • User-defined protocol

S: Starting address of transmitted data.

m: Length of transmitted data, the range is 0~256

D: Starting address for storage data.

n: Length of received data, the range is 0~256

n1: Serial port Number, 2 means using COM2, 3 means using COM3, 4 means using COM4, 5 means using COM5, 6 means using COM6; Program could write multiple RS2 instructions, but only one RS2 instruction could be triggered at the same time.

7-13 External Device SER instruction_html_a4079aa3cd82e7eb.jpg

In this example, n1 is set K2, so the RS2 instruction is used in COM2. When X1 is triggered program will transfer data as below shows.

7-13 External Device SER instruction_html_ca7e65648e2980fe.jpg

  • MODBUS protocol

The definitions of each operand in the RS2 (MODBUS mode) instruction are different from those of a standard RS instruction (user-defined protocol).

S: Slave station address (high byte), communicational command (low byte, define by MODBUS protocol);

M: Register start address of call on slave station;

D: Data length will be read or write, units is word;

N: Memory units original address for read or write data, engross continuous address units, length decided by D;

n1: Serial port Number, 2 means using COM2, 3 means using COM3, 4 means using COM4, 5 means using COM5, 6 means using COM6; Program could write multiple RS2 instructions, but only one RS2 instruction could be triggered at the same time.

7-13 External Device SER instruction_html_dfa23bea9dee8a88.jpg

In this example, n1 is set K2, so the RS2 instruction is used in COM2. When X1 is triggered program will transfer data as below shows.

7-13 External Device SER instruction_html_6acd67cc98548727.png

7-13 External Device SER instruction_html_7fc920c883b7f391.jpg

In LX3V-ETH-BD module

  • MODBUS TCP protocol

S: The address of slave (high byte) and communication command (low byte, defined by MODBUS protocol);

m: The starting address number of the slave

D: The length of the data (read or writes), the unit is word. (The specific setting is shown in the following table)

Function codeLengthLength (HEX)
Write coils19680x7B0
Read coils20000x7D0
Write registers1230x7B
Read registers1250x7D

n: The starting address of the storage unit for reading or writing data, occupying the subsequent address unit, and the length is determined by the D

n1: The connection number corresponding to the Ethernet port connection number (specific settings is shown as the following table)

Ethernet port 1Connection numberEthernet port 2Connection number
7-13 External Device SER instruction_html_73c5c45307d9b823.pngConnection 110007-13 External Device SER instruction_html_73c5c45307d9b823.pngConnection 11100
Connection 21001Connection 21101
Connection 31002Connection 31102
Connection 41003Connection 41103
Connection 51004Connection 51104
Connection 61005Connection 61105
Connection 71006Connection 71106
Connection 81007Connection 81107

7-13 External Device SER instruction_html_d344a5e717691faa.jpg

In this example n1 is set as K1002, then RS2 is configured for Ethernet port 1, connection 3. When x1 is ON, the data is shown as below.

7-13 External Device SER instruction_html_a993395de96a215.png

7-13 External Device SER instruction_html_5fcfd4f1bba9596b.jpg

6.14.3 RSLIST instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
RSLISTFormulated communication instructions16NoRSLIST S1 S2 m19
OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S1               
S2               
m1               

Only LX3VP series and above plc (advanced series) support RSLIST instruction, and major version number and this version number of LX3VP series plc must be "25103" and "16001" and above edition, while major version number and this version number of LX3VPE series plc must be "25201" and "16001" and above edition.

This instruction is the one tabulating RS instruction, which replaces communication protocol by changing D8126 (communication protocol). Most of its functions are the same as the ones of RS instruction, but with simplified cumbersome engineering writing, in which, parameters of each transmission command are directly set by table.

S1 is the starting device address controlled by table, with value range of D0~D7999; The addresses of starting device between S1~S4+4+n*6 couldnot be occupied by other instructions. (As far as possible, store data in power-down save (latched) (D200-D7999) to avoid data loss).

Communication table of RSLIST instruction (MODBUS protocol)
AddressNameFunction description
S1+0HeaderHeader = 50h, correct MODBUS and MODBUSASC protocol communication form. ( No modification )
S1+1Communication command numberCommunication command number: A transmission needs to use six devices to describe, that is, six devices describe a data transmission. ( No modification )
S1+2Check bit of header and communication command numberCheck header and communication command number ( No modification )
S1+3Error replication number (retry times) (for all commands)

Error replication number (retry times)

(0-255)

S1+4Slave station number of current communicationFunction code

Station number: 0 ~ 255 (0 means that the master station broadcast to all slave station, while slave station does not respond to the received information.)

Function code: please check the table below.

S1+5Start address of Slave dataWord is valid. Define start address of Slave.
S1+6Data lengthWord is valid, range: 1~126 (word data), 1 ~ 2039 (bit data).
S1+7Master stores data starting deviceWord is valid. Define Master to receive the start address of data.
S1+8Sending control bitSending control bit: no running temporarily as long as it’s 0. (when it is not 0, no execution)
S1+9Single error replication number(retry times)Single error replication number (retry times)(0-255)
S1+10Slave station numberFunction codeDescription of second data transmission
S1+11Start address of Slave data
S1+12Data length
S1+13Master stores data starting device
S1+14Sending control bit
S1+15Single error replication number (Retry times)
S1+4+n*6SaveN is the total number of data transmission commands
Communication table of RSLIST instruction (User-defined protocol)
AddressNameFunction description
S1+0HeaderHeader = 51h, correct MODBUS and MODBUSASC protocol communication form. ( No modification )
S1+1Communication command numberCommunication command number: A transmission needs to use six devices to describe, that is, six devices describe a data transmission. ( No modification )
S1+2Check bit of header and communication command numberCheck header and communication command number ( No modification )
S1+3Error replication number (retry times) (for all commands)

Error replication number (retry times)

(0-255)

S1+4Master sends data starting deviceReceive the start address of data.
S1+5Data length of MasterWord is valid. PLC determines data length according to cache block. (LX3VP:0~528)
S1+6Master receives data starting deviceWord is valid. Define Master to send the start address of data.
S1+7Data length of slave stationWord is valid. PLC determines data length according to cache block. (LX3VP:0~528)
S1+8Sending control bitSending control bit: no running temporarily as long as it’s 0. (when it is not 0, no execution)
S1+9Single error replication number (Retry times)Single error replication number(Retry times) (0-255)
S1+10Data length of MasterDescription of second data transmission.
S1+11Data length of Slave
S1+12Master sends data starting device
S1+13Master receives data starting device
S1+14Sending control bit
S1+15Single error replication number (Retry time)
S1+4+n*6SaveN is the total number of data transmission commands

S2 is the starting device address of table cache, with value range of D0~D7999; the addresses of cache starting device between S2~S2+12 couldnot be occupied by other instructions.

Note: any random data in the above operation-forbidden area will lead to communication anomalies.

AddressHigh byteLow byteOperated
S2+0Operation serial number: indicate which command is operating at present.No
S2+1

Result code:

= 0, normal;

= Other value, abnormal

No
S2+2Slave station device numberFunction codeNo
User-defined Protocol: master station sends starting deviceNo
S2+3

Start address of Master device

(User-defined protocol: Master receives the start address of data)

No
S2+4

Received or sent data size

(User-defined protocol: data size received by master

No
S2+5Error replication number(Retry times) of current commandNo
S2+6Error times recordNo
S2+7

Bit0 = 1, Port has been occupied, this command waits for data transmission rights;

Bit4, communication transmission output indication is represented by "M1";

Bit5, communication error output indication is represented by "M1 + 1";

Bit6, communication completion output indication is represented by "M1 + 2".

No
S2+8Select which command to implementYes
S2+9Select which command to open and close: which commandYes
S2+10

Select which command to open and close:

0: none, 1: close, 2: open;

Yes
S2+11(System occupancy)No
NameNumerical valueFunction description
Function code01HRead the state of consecutive multiple single-points from Slave
03HRead data of consecutive multiple registers from Slave
05HWrite the state of individual single-point into Slave
06HWrite data of single register into Slave
0FHWrite the state of consecutive multiple single-points into Slave
10HWrite data of consecutive multiple registers into Slave

Result code

(error code)

0x00successful communication transaction
0x01frame error
0x02illegal communication table (header error)
0x04Data length error (the position read or written by command is beyond range of device size)
0x05the set read and write length range is beyond device range (starting device plus the length is beyond the range of D0-D7999)
0x06Function code error (incorrect function code or not supporting this function code).
0x07Slave station number error
0x08Slave address error
0x09No response in Slave ( abnormal time-out)
0x0AAbnormal communications (receive erroneous data or slave station responses to error message).
0x0Bselected commands exceed maximum number of commands
0x0FSkip this command (the sending control bit of this command is not 0)

m1 is the start address of communication flag, with value range of M0 ~ M3068; (m1~m1+2) couldnot be used by other instructions.

AddressFunction
m1+0Transmission flag
m1+1Error flag
m1+2Completion flag

Other related settings are listed below:

ItemParameterBit value of D8120
b7b6b5b4b3b2b1b0
Baud rate (Bps)1152001100----
576001011----
384001010----
192001001----
96001000----
48000111----
Stop bit1 bit----0---
2 bit----1---
ParityNone-----00-
Odd-----01-
Even-----11-
Data bit7 bit-------0
8 bit-------1
Example: the communication format is 9600.1.8.None, b7b6b5b4=1000, b3=0, b2b1=00, b 0=1. D8120=81H ( (10000001)2=81H, 81H means hexadecimal number)
AddressDescription
D8120Com2 port communication format, interface configuration settings (see the above table for details).
D8122

User-defined protocol: send remaining data (for RS instruction only);

MODBUS protocol: command sending interval, 0 = 5ms. Unit 0.1ms

D8124starting character STX (only for RS user-defined protocol)
D8125terminating character ETX (only for RS user-defined protocol)
D8126Communication protocol settings, interface configuration settings
D8129

MODBUS: determine the time of communication timeout, interface configuration settings, the default is 10 (10ms)

RS user-defined protocol: inter-character timeout, interface configuration settings, the default is 10 (10ms)

D8172

First character timeout, interface configuration settings, the default is 10 (10ms)

First character timeout is not calculated when M8172 is 0. (only for RS user-defined protocol)

Create new RSLIST table

Right click (Project Manager -> Project Property -> Extended Function -> RSLIST Table) to create or edit table, as shown below:

7-13 External Device SER instruction_html_4ff024f75d9314f7.jpg

  • Table setting interface as below
  • Communication protocol: should be consistent with the configuration of communication protocol control address (D8126, etc.) (Modbus Master / RS user-defined protocol).
  • Default error repeat count: use the replication number (retry times)of a single error when it is not 0; use the error replication number (retry times) set in header when it is 0; default 3 times when both are 0. The set replication number includes number of times for the first run, that is, repeat errors only for two times and then turn to the next when the set replication number is 2.
  • Table initial address: should be consistent with in the corresponding RSLIST instruction.
  • Address allocation: Table space could be automatically configured or selected as fixed length (4 + n * 6), where n is the number of communication commands.

7-13 External Device SER instruction_html_50413327a9995482.jpg

✎Note: Number of table commands should be less than 255. And do address planning to avoid data confusion caused by repeatedly occupied addresses.

Modbus Protocol Configuration

  • Ladder configuration

7-13 External Device SER instruction_html_7db6be9bc094da69.jpg

  • Table configuration

7-13 External Device SER instruction_html_9e317e72b272a62c.jpg

Table start address is D300, which corresponds to the RSLIST instruction in ladder.

When M1 = ON, RSLIST instruction starts execution. When "YES" in "whether to enable command” is selected as instruction in the table ", number 1 and 3 instructions in execution table are executed cyclically; when “No” is selected, execution is controlled by “S2+8”=D208. As shown in the above ladder, D208 = 2 is triggered every 500ms, that is, number 2 instruction in the table is executed every 500ms. (Read data of 20 addresses starting from station 100 and store the read data in D500-D519 separately).

  • Communication command configuration

7-13 External Device SER instruction_html_470675f5c972bfff.jpg

Slave station number: (limited between 0-255). Account 0 is used as broadcast and will not receive. See "Function Code List".

The data start address (D device) range in master station is (D0-D7999). Store relevant data in power-down save (D200-D7999) to avoid data loss. Store data start address in slave station.

Byte of data: (bit length in bits, word length in words), range 1 to 126 (word data), 1 to 2039 (bit data).

Error repeat time: 0 indicates that this error replication number (retry times) is the same as the one in table edit.

Default starting command:

Yes: execute cyclically when RSLIST is started;

No: execute only when +8 is in action.

RS User-defined Protocol

  • Ladder configuration

7-13 External Device SER instruction_html_6676db814338fe9c.jpg

  • Table configuration

7-13 External Device SER instruction_html_5a81c6af47197dac.jpg

The table start address is D800, which corresponds to the RSLIST instruction in ladder.

When M2=ON, RSLIST instruction starts execution. When "YES" in "whether to enable command” is selected as instruction in the table ", number 2 instructions in execution table are executed cyclically; when “No” is selected, execution is controlled by“S2+8”=D208. As shown in the above ladder, D708 = 1 is triggered every 500ms, that is, number 1 instruction in the table is executed every 500ms. (Send data of the 20 addresses starting from D1000 to device and store the returned data in the 20 addressed starting from D1020.)

  • Communication command configuration

7-13 External Device SER instruction_html_781f373e7a5f9a60.jpg

Starting address of delivery (D device) range is (D0-D7999). Store relevant data in power-down save (D200-D7999) to avoid data loss.

Sending length: the length here is in BYTE (range LX3VP: 0-528). No sending when the sent data length is 0.The receiving start address (D device) range is (D0-D7999). Store relevant data in power-down save (D200-D7999) to avoid data loss.

Receiving length: the length here is in BYTE (range LX3VP: 0-528). No receiving when the received data length is 0.

Error repeat count: 0 indicates that this error replication number (retry times)is the same as the one in table edit.

Default starting command:

Yes: execute cyclically when RSLIST is started;

No: execute only when +8 is in action;

6.14.4 CPAVL instruction (Ethernet port)

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
CPAVLCommunication port setting16NoCPAVL S D M7
  • S: The starting address of “D” device;
  • D: The starting address of “M” device;
  • M: Serial port Number, 0 means using COM0, 1 means using COM1, 2 means using COM2, 3 means using COM3, 4 means using COM4, 5 means using COM5, 6 means using COM6; Program could write multiple RS2 instructions, but only one RS2 instruction could be triggered at the same time.
OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
D               
m              
Connection number description
CPAVL instructionPortConnection number
Ethernet port 11000
Ethernet port 21100

✎Note: 

Only need one CPAVL instruction to configure multiple connections. The RS instruction needs to be used for the corresponding connection.

Address definition

  • M device (Bit)
Bit addressDescriptionConnectionBit addressDescriptionConnection
D+0ReservedConnection 1 ConfigurationD+10ReservedConnection2 Configuration
D+1Instruction executionD+11Instruction execution
D+2Instruction execution stateD+12Instruction execution state
D+3Communication error flagD+13Communication error flag
D+4ReservedD+14Reserved
D+5ReservedD+15Reserved
D+6ReservedD+16Reserved
D+7ReservedD+17Reserved
D+8ReservedD+18Reserved
D+9Timeout flagD+19Timeout flag
D+20D+30
  • D device (Word)
Word AddressDescription DDetailed descriptionOther instructionsRead and write features
0 Version numberBD Board parameter settingsR
1BD Board IP AddressIP First 1 SectionR/W
2IP First 2 SectionR/W
3IP First 3 SectionR/W
4IP First 4 SectionR/W
5Port 0 default K502R/W
6GatewayGateway first 1 SectionR/W
7Gateway first 2 SectionR/W
8Gateway first 3 SectionR/W
9Gateway first 4 SectionR/W
10Subnet maskSubnet mask first 1 SectionR/W
11Subnet mask first 2 SectionR/W
12Subnet mask first 3 SectionR/W
13Subnet mask first 4 SectionR/W
14MACMAC First 1 SectionR
15MAC First 2 SectionR
16MAC First 3 SectionR
17MAC First 4 SectionR
18MAC First 5 SectionR
19MAC First6 SectionR
20(Reserved) R/W
21(Reserved) R/W
22Number of connectionsHow many connections are required to set the number of connectionsR/W
23Protocol ProtocolConnection 1 ConfigurationR/W
24Slaves IPIP First 1 SectionR/W
25IP First 2 SectionR/W
26IP First 3 SectionR/W
27IP First 4 SectionR/W
28Port 0 default K502R/W
29(Reserved) R/W
30Instruction sending intervalSet the instruction sending interval. Unit: 0.1msR/W
31(Reserved) R/W
32(Reserved) R/W
33(Reserved) R/W
34Timeout  R/W
35Protocol Communication protocolConnection 2 ConfigurationR/W
36Slaves IPIP First 1 SectionR/W
37IP First 2 SectionR/W
38IP First 3 SectionR/W
39IP First 4 SectionR/W
40Port0 default K502R/W
41(Reserved) R/W
42(Reserved) R/W
43(Reserved) R/W
44(Reserved) R/W
45(Reserved) R/W
46Timeout  R/W
47R/W

Program example

7-13 External Device SER instruction_html_1eee36136b02fca0.jpg

Use the Ethernet port 1, and the parameter table start from D300 and M300.

  • The Ethernet parameter setting of LX3V-ETH-BD

7-13 External Device SER instruction_html_c12c82215871e47.jpg

  • MODBUS protocol setting

7-13 External Device SER instruction_html_4533fce5143a0c70.jpg

6.14.5 CPAVL instruction (Serial port)

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
CPAVLCommunication port setting16NoCPAVL S D M7
  • S: The starting address of “D” device;
  • D: The starting address of “M” device;
  • M: Serial port Number, 0 means using COM0, 1 means using COM1, 2 means using COM2, 3 means using COM3, 4 means using COM4, 5 means using COM5, 6 means using COM6; Program could write multiple RS2 instructions, but only one RS2 instruction could be triggered at the same time.
OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
D               
m              

Address definition

7-13 External Device SER instruction_html_6744c256b2335f3f.jpg

Setting the parameters of COM4 are in 20 consecutive addresses beginning of D0 and M0.

Bit addressContentWord addressContent
D+0RetentionS+0Communication format, defined is 0
D+1Sending(RS2)S+1Station number, defined is 0
D+2

Sending flag (RS2)

Instruction state (MODBUS)

S+2

Remaining amount of data transmission(RS2)

Interval of sending(MODBUS)

D+3

Receiving flag(RS2)

Communication error flag (MODBUS)

S+3The number of receiving data (RS2)
D+4Receiving (RS2)S+4Starting code STX(RS2)
D+5RetentionS+5Ending code ETX(RS2)
D+6RetentionS+6Communication protocol
D+7RetentionS+7Retention
D+8RetentionS+8Retention
D+9Timeout flagS+9Timeout, defined is 10 (10ms)
D+10~ D+19RetentionS+10~ S+19Retention

Program example

  • MODBUS RTU Master

7-13 External Device SER instruction_html_5ea4c300a73b396.png

7-13 External Device SER instruction_html_38257913ae8790.jpg

Users could set MODBUS RTU master communication by RS2 instruction, as above example shows. RS2 is a communication instruction, which could send data in the specified register area to the serial port and store receive data to specified register. Equivalent to the user program directly access the communication cache, with the help of the user program processing of the communication cache, to achieve the communication. RS instruction only is available in COM2 port, but RS2 instruction could be available in COM3/ COM4/ COM5/ COM6 ports.

  • MODBUS ASCII Slave

7-13 External Device SER instruction_html_3b9c39db83816a1f.png

7-13 External Device SER instruction_html_4ac69501b2ed2704.jpg

When plc switches from stop to run state, PLC performs MODBUS RTU Slave communication; the function code and address mapping are consistent with COM2.

PLC internal addressMODBUS addressNumberDescription
D0~D82550 (0)8256 
T0~T2550x F000 (61440)256 
C0~C1990x F400 (62464)200 
C200~C2550x F700 (63232)5632-bit register
  • User-defined

7-13 External Device SER instruction_html_f0db03b2b0d7e1d2.png

7-13 External Device SER instruction_html_7ba0af683d7db0f6.png

7-13 External Device SER instruction_html_caaa523850bdac20.png

7-13 External Device SER instruction_html_93f45ee150331274.jpg

6.14.6 PRUN instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
PRUNTransmission of Octal bits16NoPRUN S D5
PRUNP16Yes5
DPRUN32No9
DPRUNP32Yes9

The instruction is used for coping the bit variables (the width unit is of octal) of the continuous addresses starting with S to the bit variable set starting with D in batch.

  • S: The starting address of the bit variables to be copied, where the unit digit of the addresses must be 0, such as X10, M20;
  • D: The starting address of the target bit variables, where the unit digit of the addresses must be 0, such as X10, M20;
OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S              
D              

Program example

Example 1

7-13 External Device SER instruction_html_3293776174646ccf.jpg

7-13 External Device SER instruction_html_5b80287b320b1cc0.jpg

Example 2

7-13 External Device SER instruction_html_af1ed04131e3732.jpg

7-13 External Device SER instruction_html_c58911b98d6888db.jpg

6.14.7 ASCI instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
ASCIConverts a data value from hexadecimal to ASCII16NoASCI S D n7
ASCIP16Yes7

This instruction reads n hexadecimal data characters from head source address (S) and converts them in to the equivalent ASCII code.

  • S: The source address;
  • D: The store address;
  • n: The data length;
OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S     
D          
nConstant, n=1~256

Program example

7-13 External Device SER instruction_html_66c5cfc4713bdf0b.jpg

The M8161 flag determines the width mode of the target variable for calculation result storage. When M8161=OFF, it is 16bit mode, which means the higher byte and lower byte are saved respectively. When M8161=ON, it is 8bit mode, which means that only the lower byte is used to save result and the actual variable range length is longer.

7-13 External Device SER instruction_html_bfac61ddc96b9a82.jpg

7-13 External Device SER instruction_html_151fd06affcbc3b8.jpg

  • When M8161=OFF

7-13 External Device SER instruction_html_c5eb9280902d1523.jpg

When M8161=ON

7-13 External Device SER instruction_html_657f7883d3e7bd87.jpg

Points to note

Instructions such as RS / HEX / ASCI / CCD share the M8161 mode flag, please pay attention on it when programming.

6.14.8 HEX instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
HEXConverts a data value from hexadecimal to ASCII16NoHEX S D n7
HEXP16Yes7

This instruction reads n ASCII data bytes from head source address (S) and converts them in to the equivalent Hexadecimal character, and saved result in D.

  • S: The variable address or constant to be converted. If it is a register variable, the conversion interval will has a width of a 32bit variable.
  • D: The starting address for storing the ASCII code.
  • n: The data length;
OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S     
D          
nConstant, n=1~256

Program example

7-13 External Device SER instruction_html_5c5559d29754df6a.jpg

For example, the following data is starting from D100.

7-13 External Device SER instruction_html_c75a66125ec0cf6.jpg

7-13 External Device SER instruction_html_90be70230a6898d2.jpg

The M8161 flag determines the width mode of the target variable for calculation result storage. When M8161=OFF, it is 16bit mode, which means the higher byte and lower byte are saved respectively. When M8161=ON, it is 8bit mode, which means that only the lower byte is used to save result and the actual variable range length is longer.

  • When M8161=OFF

7-13 External Device SER instruction_html_d9179ef38213328e.jpg

  • When M8161=ON

7-13 External Device SER instruction_html_e0c12c92f19a1236.jpg

Points to note

  • Instructions such as RS / HEX / ASCI / CCD share the M8161 mode flag, please pay attention on it when programming;
  • S data area of the source data must be ASCII characters, or error occur when conversion;
  • If the output data is in BCD format please do BCD-BIN conversion after HEX conversion, then users could get correct value;

6.14.9 CCD instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
CCDCheck Code16NoCCD S D n7
CCDP16Yes7

This instruction looks at a byte stack of data from head address (S) for n bytes and checks the vertical bit pattern for parity and sums the total data stack. These two pieces of data are then stored at the destination (D).

  • S: The starting address of variables, which are to be checked and calculated;
  • D: Respectively used for saving “SUM” result (D+1) is respectively used for saving “XOR” result;
  • n: The bit number occupied by variables for checking
OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S         
D          
nConstant, n=1~256

Program example

7-13 External Device SER instruction_html_e0a2ba4435f0dc1a.jpg

7-13 External Device SER instruction_html_22098ca4de465ce7.jpg

The M8161 flag determines the width mode of the target variable for calculation result storage. When M8161=OFF, it is 16bit mode, which means the higher byte and lower byte are saved respectively. When M8161=ON, it is 8bit mode, which means that only the lower byte is used to save result and the actual variable range length is longer.

The “SUM” is quite simply a summation of the total quantity of data in the data stack.

The "XOR" logical calculation means:

  • The involved variables are converted to binary format.
  • Then it counts the number of variables with bit0=1. If it is even, the calculation result of bit0 is 0. If it is odd, the calculation result of bit0 is 1.
  • Then it counts the number of variables with bit1=1. If it is even, the calculation result of bit1 is 0; if it is odd, the calculation result of bit1 is 1.
  • In the same way, calculation is implemented from bit2 to bit7. After that, the binary HEX value converted from binary is the “XOR” result (polarity value).

Note for use

  • Instructions such as RS / HEX / ASCI / CCD share the M8161 mode flag, please pay attention on it when programming;

6.14.10 PID instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
PIDPID operation16NoPID S1 S2 S3 D9

This instruction is for PID operation; it is used for control of close-loop system parameter. PID control is widely used in mechanical equipment, pneumatic equipment, constant pressure water supply, electronic equipment and so on.

  • S1: The predefined set value;
  • S2: The current value;
  • S3: The operation parameter, it takes the next 25 addresses, the value range is D0 ~ D7975, it is best to specify the retentive memory, for saving parameter when power OFF;
  • D: The destination device, it is better to specify the non-retentive memory, otherwise users need to initialize it before executing instruction;
OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S1               
S2               
S3               
D               

Program example

7-13 External Device SER instruction_html_7b436597fadf66dc.jpg

D9 is target value, D10 is current value, the unit for D9 and D10 must be the same.

D200~D224 are used for storing the set value and process value of PID operation. These values must be set item by item before executing PID operation.

D130 is used for storing the calculated value, it is used for controlling the implementation of the action.

Operation parameters (S3+N)
UnitFunctionDescription
S3Sample time(Ts)

Setting range 1~32767(ms), but must longer than scouldning cycle of plc

program

S3+1

Reaction

direction(ACT)

bit0: 0=positive action; 1=negative action;

bit3: 0=one way; 1=two way;

bit4: 0=disable self-tuning; 1=enable self-tuning;

Others couldnot be used.

S3+2

Maximum

climbing(Delta T)

Setting range 0~320
S3+3Proportional gain(Kp)Setting range: 0~32767, note:this value is magnified 256 times, actual value is Kp/256
S3+4Integral gain(Ki)Setting range: 0~32767, Ki=16384Ts/Ti, Ti is integral time
S3+5Derivative gain(Kd)Setting time: 0~32767, Kd≈Td/Ts, Td is derivative time
S3+6Filter (C0)Range: 0~1024
S3+7Output lower limitRecommended range: -2000~2000, when S3+1 bit3=0, please set 0; S3+1 bit3=1, please set -2000
S3+8Output upper limitRecommended values: 2000
S3+9Retain Retain
  • Self-tuning example

7-13 External Device SER instruction_html_2337238c0f91917.jpg

Error code

If an error occurs in the set value of the control parameters or in the PID operation, the operation error flag M8067 turns on and the following data is stored in D8067 according to the error details.

Error codeError contentStateProcessing method
K6705

Operand of application instruction

outside of target device

Stop PID operationPlease check data for PID operation
K6706

Operand of application instruction

outside of target device

K6730

(TS< 0 )

Sampling time(TS) outside of target device (TS< 0 )

K6731Filter (C0) outside (C0<0 or 1024≤C0)
K6732Maximum rate of raise(DeltaT) outsideΔT<0 or 320≤ΔT
K6733Proportional gain(KP) outside of target range
K6734

Integral gain (KI)outside of target

range(KI<0)

K6735Derivative gain outside of target range(KD<0)
K6740Sampling time≤ operation cycleContinue PID operation
K6742Variation of measured value exceed ((PV<-32768 or 32767 < ( PV )
K6751Direction of Self-tuning isn’t matchContinue PID self-tuningThe action direction between set value and current value are not match. Please correct the target value, self-tuning output, estimated value, then self-tuning.
K6752Self-tuning action is improperSelf-tuningSelf-tuning measured value couldnot be correct action, due to changes in the upper and lower. Please make the sampling time is much greater than the output change cycle, increase the input filter constant. After changing the setting, please perform auto-tuning again.

Note for use

The correct measured value must be read into the PID measured value (PV) before the PID operation is executed. In particular, pay attention to the conversion time when performing PID operation on the value of the analog input module.

PID instruction could be used multiple times and executed at the same time, but variable area of PID instruction couldnot overlap; it also could be used in step instruction, jump instruction, timer interruption, subroutine, but please delete S3+9 cache unit before execute PID instruction.

The maximum error of sampling time TS is - (1 execution cycle+ l ms)~ +(1 execution cycle). If sampling time TS≤1 execution cycle OF PLC, then will have below PID operational error (K6740), and execute PID algorithm as TS = execution cycle, in that case, it is better to use constant scouldning mode or use the PID instruction in timer interrupt (16□□~18□□)