欢迎图片

6.14 Data Table Operation instructions

Version 1.2 by Iris on 2025/10/21 11:41

SFRD/Shift Read

SFRD(P)

Data read instructions for first-in, first-out and control.

-[SFRD  (s)  (d)  (n)]

Content, range and data type

ParameterContentRangeData typeData type (label)
(s)

The start word device number storing data

(The start is a pointer, and the data starts from (s)+1)

-Signed BIN 16 bitANY16
(d)The word device number storing the first-out data-Signed BIN 16 bitANY16
(n)It should be specified as the value of the number of points + 1 of the stored data. +1 is pointer2 to 512Signed BIN 16 bitANY16

Device used

instructionParameterDevicesIndex modification

Pulse

extension

XYMSSMT(bit)C(bit)LC(bit)HSC(bit)D.bKnXKnYKnMKnSTCDRSDLCHSCKHE[D]XXP
SFRDParameter 1               
Parameter 2                
Parameter 3             

Features

Transfer (s)+1 written sequentially to (d) by SFWR instruction, shift up each point (n)-1 by one word from (s)+1. The number of  stored data of (s) subtracts one.

The content of (s)+1 is transferred (read) to (d). At the same time, the content of the pointer (s) decreases, and the data is shifted up by 1 word each. (In the continuous execution instruction SFRD, each operation cycle will shift, so the pulse execution instruction SFRDP should be used for programming).

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps2.jpg

Related device 

DevicesNameContent
SM153Zero bitData readout usually starts from (s)+1, but when the pointer (s) is 0, the zero bit SM153 will operate.

✎Note: 

The data after reading would not change the content of (s)+(n) due to reading.

In the case of continuous execution (SFRD) instructions, each scan time (operation cycle) will be read sequentially, but the content of (s) + (n) would not change. When the pointer (s) is 0, it would become no processing, and the content of (d) would not change.

Error code

Error codeContent
4084HWhen the value set in (n) is other than the following. 2≤(n)≤512
A negative value is specified in (s).
4085HWhen the device specified in the read application instruction (s) and (n) exceeds the corresponding device range.
4086HWhen the device specified in the write application instruction (s) and (d) exceeds the corresponding device range.

Example

The following examples illustrate the use of shift write (SFWR) and shift read (SFRD) instructions.

(1) Action content

  1. While registering the product number, in order to realize the first-in-first-out principle, the following introduces an example of a ladder ladder diagram that outputs the current product number.
  2. The product number is a hexadecimal number with 4 digits or less, and the maximum inventory is below 99 points.

(2) Program 

  1. Program 1

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps3.pngfile:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps4.pngfile:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps5.pngfile:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps6.png file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps7.jpg

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps8.jpg

  1. Program 2

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps9.jpg  First-in-first-out data read instruction

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps10.jpg

Turn X0 from OFF to ON, and this instruction acts according to the following numbers 1 to 3. (The content of D10 remains unchanged),

  • The content of D2 is read out and sent to D20.
  • D10 to D3 all shift one register to the right.
  • The contents of pointer D1 are reduced by 1.

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps11.png6.14.2 POP/Read From the Back of the Data Table

POP(P)

Read the last data written by the shift write instruction (SFWR) for first in first out/first in last out control.  

-[POP  (s)  (d)  (n)]

Content, range and data type

ParameterContentRangeData typeData type (label)
(s)The start device number that stores the first-in data (including pointer data) (the start word device number that stores data)-Signed BIN 16 bitANY16
(d)The device number that stores the last-out data-Signed BIN 16 bitANY16
(n)The points of stored data2 to 512Signed BIN 16 bitANY16

Device used

instructionparameterDevicesIndex modification

Pulse

extension

XYMSSMT(bit)C(bit)LC(bit)HSC(bit)D.bKnXKnYKnMKnSTCDRSDLCHSCKHE[D]XXP
POPParameter 1                
Parameter 2                
Parameter 3             

Features

For the word device of "(s) to (s)+(n)-1", the device of "(s) + instruction data (s)" will be read to (d) ( The last data written by the shift write instruction (SFWR) for first-in first-out control is read to (d)). (N) Specifies 2 to 512.

The value of pointer data (s) is reduced by one.

First-in-last-out control data

 Content
(S)Pointer data (the number of stored data)
(S)+1

Data field

(Data entered by shift write instruction (SFWR))

(S) +2
(S) +3
......
(S)+(n)-3
(S)+(n)-2
(S)+(n)-1

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps12.jpg

✎Note: 

If the POP(P) instruction is programmed in continuous execution type, the instruction will be processed per cycle. Therefore, it may not be possible to achieve the desired action. Generally, POP(P) instruction programming should be executed with "pulse execution type" or "pulse specified contact".

When the current value of pointer (s) is 0, the zero flag SM153 turns on, and the POP(P) instruction becomes no processing.

When the current value of pointer (s) is 1, write 0 to (s), and the zero flag SM153 turns on.

Error code

Error codeContent
4084H(s)>(n)-1
(s)<0
Data outside the specified range is entered in (n).  2≤(n)≤512
4085HWhen the device specified in the read application instruction (s) and (n) exceeds the corresponding device range
4086HWhen the device specified in the write application instruction (s) and (d) exceeds the corresponding device range

Example

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps13.jpg

Each time M1 is ON, for the values of D20 input first in D101 to D106, the last saved value would be saved in D10, and then the data saved number (pointer D100) will be reduced by 1.

When the data entered first is the content in the table below.

PointerD100K3
DataD101H1234
D102H5678
D103HABCD
D104H0000
D105H0000
D106H0000

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps14.png

6.14.3 SFWR/Shift Write

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps15.pngSFWR(P)

Data writing instructions for first-in-first-out and control.

-[SFWR  (s)  ( d)  (n)]

Content, range and data type

ParameterContentRangeData typeData type (label)
(s)The word device number that stores the data you want to enter first-Signed BIN 16 bitANY16
(d)The start word device number for storing data and shifting (the start is pointer, and data starts from (d)+1)-Signed BIN 16 bitANY16
(n)The value of points + 1 of stored data should be specified2 to 512Signed BIN 16 bitANY16

Device used

instructionParameterDevicesIndex modification

Pulse

extension

XYMSSMT(bit)C(bit)LC(bit)HSC(bit)D.bKnXKnYKnMKnSTCDRSDLCHSCKHE[D]XXP
SFWRParameter 1             
Parameter 2                
Parameter 3             

Features

Start from (d)+1, write the contents of (s) to point (n)-1, and the stored data of (d) add one. For example, if (d)=0, write to (d) +1, (d)=1, write to (d)+2.

Through the first execution, the content of (s) is stored to (d)+1 and becomes the value of (s).

If the content of (s) is changed and executed for the second time, the content of (s) is stored to (d)+2, and the content of (d)+2 becomes (s) (in the continuous execution instruction SFWR, each operation cycle will be stored sequentially, so the pulse execution instruction SFWRP should be used for programming). After that, the data will be filled in sequentially from the right, and the number of data storage points is displayed by the content of the pointer (d).

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps16.jpg

Related device

DevicesNameContent
SM151carryWhen the content of pointer (s) exceeds (n)-1, it becomes no processing (no writing), and the carry flag SM151 turns ON.

✎Note: 

In the continuous execution type (SFWR) instruction, you should be noted that each scan time (operation cycle) will be stored (overwritten) sequentially.

Error code

Error codeContent
  4084HWhen the value set in (n) is other than the following. 2≤(n)≤512
A negative value is specified in (d).
4085HWhen the device specified in the read application instruction (s), (d) and (n) exceeds the corresponding device range.
4086HWhen the device specified in the write application instruction (d) exceeds the corresponding device range.

Example

The following examples illustrate the use of shift write (SFWR) and shift read (SFRD) instructions.

7.14.4 (1) Action content

  1. While registering the product number, in order to realize the first-in-first-out principle, the following introduces an example of a ladder ladder diagram that outputs the current product number.
  2. The product number is a hexadecimal number with 4 digits or less, and the maximum inventory is below 99 points.

(2) Program 

  1. Program 1

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps17.pngfile:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps18.pngfile:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps19.pngfile:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps20.png file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps21.jpg

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps22.jpg

  1. Program 2

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps23.jpg  First-in-first-out data read instruction

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps24.jpg

When X0=1, the content of D0 is stored in D2, and the content of D1 becomes 1. When X0 changes from OFF to ON again, the content of D0 is stored in D3, the content of D1 becomes 2, and so on. If the content of D1 exceeds n-1, the instruction is not processed, and the carry flag M8022 will be set to 1.

6.14.4 FINS/Data Table Data Insertion

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps25.pngFINS(P)

Insert the BIN 16-bit data specified in (s) into the number (n) of the data table specified in (d). After the instruction is executed, the data starting with number (n) in the data table will be postponed downward one by one.

-[FINS  (s)  (d)  (n)]

Content, range and data type

ParameterContentRangeData typeData type (label)
(s)The start number of device storing the inserted data-Signed BIN 16 bitANY16
(d)The starting number of table-wordANY16
(n)The position of the inserted table1-512Signed BIN 16 bitANY16

Device used

instructionParameterDevicesIndex modification

Pulse

extension

XYMSSMT(bit)C(bit)LC(bit)HSC(bit)D.bKnXKnYKnMKnSTCDRSDLCHSCKHE[D]XXP
FINSParameter 1             
Parameter 2                   
Parameter 3             

Features

Insert the BIN 16-bit data specified in (s) into the number (n) of the data table specified in (d). After the instruction is executed, the data starting with number (n) in the data table will be postponed downward one by one.

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps26.jpg

  • N: the number of data storage;
  • DTr: data table range;
  • When (n)=2, it will be inserted into (d)+2.

✎Note: 

✎The range of device used in the data table is managed by user.

✎The range of the data table is (d) started from device (d) +1) after the number of data (d).

Error code

Error codeContent
4084HFINS(P) instruction is executed when the value of (d) is 0.
The storage data of the table of (d) exceeds 512.
When the data set in (n) is other than the following, 1≤(n)≤512.
When the FINS(P) instruction is executed, the table position (n) of the inserted data is greater than data storage number.
4085HWhen the device specified in the read application instruction (s), (d) and (n) exceeds the corresponding device range.
4086HWhen the device specified in the write application instruction (d) exceeds the corresponding device range.

Example

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps27.jpg

When X10=ON, insert the data of D100 into No. 3 of the data table of D0 to D4.

However, when the number of saved data exceeds 7, the FINS(P) instruction is not executed (the device range used in the data table is D0 to D7).

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps28.png

6.14.5 FDEL/Data Deletion of Data Sheet

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps29.pngFDEL(P)

Delete the (n)th data of the data table specified in (d) and store it in the device specified in (s). After the instruction is executed, the data after (n)+1 in the data table will be postponed forward one by one.

-[FDEL  (s)  (d)  (n)]

Content, range and data type

ParameterContentRangeData typeData type (label)
(s)The start number of the device stored deleted data-Signed BIN 16 bitANY16
(d)The starting number of the table-wordANY16
(n)The position of the deleted table1-512Signed BIN 16 bitANY16

Device used

instructionParameterDevicesIndex modification

Pulse

extension

XYMSSMT(bit)C(bit)LC(bit)HSC(bit)D.bKnXKnYKnMKnSTCDRSDLCHSCKHE[D]XXP
FDELParameter 1               
Parameter 2                   
Parameter 3             

Features

Delete the (n)th data of the data table specified in (d) and store it in the device specified in (s). After the instruction is executed, the data after (n)+1 in the data table will be postponed forward one by one.

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps30.jpg

✎Note:

The user is responsible for the management of the device range used in the data sheet.

The range of the data table is (d) after the data storage number (d) of the device ((d) + 1).

Error code

CodeContent
4084HFDEL(P) instruction is executed when the value of (d) is 0.
The storage data of the table of (d) exceeds 512.
When the data set in (n) is other than the following, 1≤(n)≤512.
When the FDEL(P) instruction is executed, the table position (n) of the deleted data is greater than data storage number.
4085HWhen the device specified in the read application instruction (d) and (n) exceeds the corresponding device range.
4086HWhen the device specified in the write application instruction (s) and (d) exceeds the corresponding device range.

Example

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps31.jpg

When X10 is ON, delete the second data in the data table of D100 to D105, and save the deleted data in D0. However, when the number of data saved is 0, do not execute the FDEL instruction. (The device range used in the data table is D100 to D107.)

file:///C:\Users\Administrator\AppData\Local\Temp\ksohtml7696\wps32.png