05 Data operation

Last modified by Wecon on 2025/09/03 21:03

ZRST instruction

Instruction description

NameFunctionBitsPulse typeInstruction formatStep
ZRSTReset a range of like devices in one operation16NoZRST D1 D25
ZRSTP16Yes5

The range of devices, including those specified as the two destinations are reset, D1 and D2 could be word or bit(Y, M or S). D1 and D2 must be the same kind device.

The number of D1 should be smaller than D2. If D1 is 32bit counter, then D2 must be 32bit counter too.

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
D1         
D2         

Program example

7-4Data operation_html_b9a390356830a8cc.jpg

Bit device( Y, M, S) and word device(T, C, D) could be set by RST; KnY, KnM and KnS and T, C , D could also be clear by FMOV, e.g

7-4Data operation_html_b8258ee6d85abca6.jpg

DECO instruction

Instruction description

NameFunctionBitsPulse typeInstruction formatStep
DECOSource data value Q identifies the Qth bit of the destination device which will be turned ON16NoDECO S D n7
DECOP16Yes7

The lower n bits (n ≤ 4) of the source address are decoded to the destination address. When n ≤ 3, the high bit of the destination address will be 0.

  • If n=0, the instruction is not executed, if n is not equal to 0~8, then an error will occur.
  • When n=8 and the D1, D2 are bit devices, means the points are 256.
  • When the drive input is OFF, the instruction is not executed and the decoded output of the action is not changed.
  • When the D parameter is a word device, the range of n is 1 ~ 4

Generally, DECOP is used in the real application.

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S      
D          
nConstant, n=1~8, if n=0, the instruction is not executed, if n is not equal to 0~8, then an error will occur.

Program example

7-4Data operation_html_301cb54a6a229e9.jpg

ENCO instruction

Instruction description

NameFunctionBitPulse typeInstruction formatStep
ENCOEncode16NoENCO S D n7
ENCOP16Yes7

The highest active bit within the readable range has its location noted as a numbered offset from the source head address (S). This is stored in the destination register (D).

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S     
D          
nConstant, n=1~8, if n=0, the instruction is not executed

Points to note

  • The readable range is defined by the largest number storable in a binary format within the number of destination storage bits specified by n, i.e. if n was equal to 4 bits a maximum number within the range 0 to 15 could be written to the destination device. Hence, if bit devices were being used as the source data, 16-bit devices would be used, i.e. the head bit device and 15 further, consecutive devices.
  • If the stored destination number is 0 (zero) then the source head address bit is ON, i.e. The active bit has a 0 (zero) offset from the head address. However, if NO bits are ON within the source area, 0 (zero) is written to the destination device and an error is generated.
  • When the source device is a data or word device n must be taken from the range 1 to 4 as there are only 16 source bits available within a single data word.
  • When the D parameter is a word device, the range of n is 1 ~ 4

Program example

7-4Data operation_html_117a6600b0ed252.jpg

SUM instruction

Instruction description

NameFunctionBitPulse typeInstruction formatStep
SUMThe number (quantity) of active bits in the source data is stored in the destination device16NoSUM S D5
SUMP16Yes5
DSUM32No9
DSUMP32Yes9

The numbers of active (ON) bits within the source device (S), i.e. bits which have a value of “1" are counted. The count is stored in the destination register (D). If a double word format is used, both the source and destination devices use 32-bit, double registers. The destination device will always have its upper 16-bit set to 0 (zero) as the counted value could never be more than 32.

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S       
D        

Program example

7-4Data operation_html_5ff4d82d3a538ed2.jpg

BON instruction

Instruction description

NameFunctionBitPulse typeInstruction formatStep
BONThe status of the specified bit in the source device is indicated at the destination16NoBON S D n7
BONP16Yes7
DBON32No13
DBONP32Yes13

Determine the nth bit state of S and save the value to D.

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S     
D             
nN=0~15 (16-bit); n=0~31(32bit)

Program example

7-4Data operation_html_f040e329f4c8efd4.jpg

When M10 turns from On to OFF, M10 keeps the initial value.

MEAN instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
MEAN

Calculates the

mean of a range of devices

16NoMEAN S D n7
MEANP16Yes7
DMEAN32No13
DMEANP32Yes13

The range of source data is defined by operands S and n. S is the head address of the source data and n specifies the number of consecutive source devices used.

The value of all the devices within the source range is summed and then divided by the number of devices summed, i.e. n. This generates an integer mean value which is stored in the destination device (D). The remainder of the calculated mean is ignored.

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S         
D        
nConstant, n=1~64

Program example  

7-4Data operation_html_df5d3bdcf1124cdf.jpg

(D10+D11+D12+D13)/4=D20

For example, D10=K5,D11=K5,D12=K15,D13=D52 , then D20=K19,the remainder 1 is ignored.

ANS instruction

Instruction description

NameFunctionBitsPulse typeInstruction formatStep
ANS(Timed) Annunciator Set16NoANS S m D7

This instruction, when energized, starts a timer (S) for n, 100 ms. when the timer completes its cycle the assigned annunciator (D) is set ON.

If the instruction is switched OFF during or after completion of the timing cycle the timer is automatically reset. However, the current status of the annunciator coil remains unchanged.

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
D               
mConstant, n=1~32767 (unit: 1000ms)

Program example  

7-4Data operation_html_f20ed27813409ffd.jpg

If X1 and X2 are set for more than 1 second, S900 is set ON. After that, S900 will keep ON, even if X1 or X2 is reset (but T10 will be reset). If X1 and X2 are connected for less than 1 second, X1 or X2 becomes OFF. Then the timer will reset.

If M8049 (signal alarm is available) is set, the lowest number of S900~S999 that is set ON will be saved at D8049 (The lowest S number with the ON state). when any signal in S900~S999 is ON then M8048 is ON.

ANR instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
ANRThe lowest active annunciator is reset on every operation of this instruction16NoANR1
ANRP32Yes1

ANR is used for reset the alarm signal, e.g.

7-4Data operation_html_eae692d63df64c1f.jpg

If X3 is ON, then the alarm signal from S900 to S999 will be reset. If there are more than one alarm signal, then the alarm signal with the smallest number will be reset.

If X3 is ON again, then the next alarm signal from S900 to S999 will be reset. Generally, we will use ANRP instruction.

Program example

7-4Data operation_html_bfeead386d8f9800.png

7-4Data operation_html_15e4de2ec167843e.jpg

If S910, S911 and S912 all are ON, then when X5 turns from OFF to ON, S910 will be reset, when X5 turns from OFF to ON for the next time, S911 will be reset and the like.

SQR instruction

Instruction description

NameFunctionBitsPulse typeInstruction formatStep
SQRPerforms a mathematical square root16NoSQR S D5
SQRP16Yes5
DSQR32No9
DSQRP32Yes9

This instruction performs a square root operation on source data (S) and stores the result at destination device (D). The operation is conducted entirely in whole integers rendering the square root answer rounded to the lowest whole number. For example, if (S) = 154, then (D) is calculated as being 12. M8020 is set ON when the square root operation result is equal to zero. Answers with rounded values will activate M8021.

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
D               

Program example  

7-4Data operation_html_33b7e8fcbb83f854.jpg

If D0=K100, then when X2 is ON, D12=K10;

If D0=K110, then when X2 is ON, D12=K10, decimal is ignored.

FLT instruction

Instruction description

NameFunctionBitPulse typeInstruction formatStep
FLTUsed to convert data to floating point format16NoFLT S D5
FLTP16Yes5
DFLT32No9
DFLTP32Yes9

The instruction coverts the decimal data S to floating digits, and saves the result in D and D+1. Please note that two consecutive devices (D and D+1) will be used to store the converted float number. This is true regardless of the size of the source data (S), i.e. whether (S) is a single device (16-bit) or a double device (32-bit) has no effect on the number of destination devices (D) used to store the floating point number. (The instruction INT: Convert floating point value to decimal value)

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
D               

Program example  

7-4Data operation_html_bc78eb3124779c74.jpg

When M8=ON, D10 (16bit BIN) will be converted to binary floating number and saved in D120 and D121.

When M10=ON, D20 (32bit BIN) will be converted to binary floating number and saved in D130 and D131.

SWAP instruction

Instruction description

NameFunctionBitPulse typeInstruction formatStep
SWAPThe high and low byte of the designated devices are exchanged16NoSWAP S3
SWAPP16Yes3
DSWAP32No5
DSWAPP32Yes5

In single word (16-bit) operation the upper and lower byte of the source device are exchanged.

In double word (32-bit) operation the upper and lower byte of each or the two 16-bit devices are exchanged.

OperandBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S       

Program example

7-4Data operation_html_b15434454358db91.jpg

In the left demo, the upper and lower byte of D20 is exchanged.

In the right demo, the upper and lower byte of D20 and D21 are exchanged.