Wiki source code of 05 Data operation
Last modified by Wecon on 2025/09/03 21:03
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
1.1 | 1 | = **ZRST instruction** = |
| 2 | |||
| 3 | **Instruction description** | ||
| 4 | |||
| 5 | (% border="1" %) | ||
| 6 | |(% style="width:109px" %)**Name**|(% style="width:586px" %)**Function**|**Bits**|**Pulse type**|**Instruction format**|**Step** | ||
| 7 | |(% style="width:109px" %)ZRST|(% rowspan="2" style="width:586px" %)Reset a range of like devices in one operation|16|No|(% rowspan="2" %)ZRST D,,1,, D,,2,,|5 | ||
| 8 | |(% style="width:109px" %)ZRSTP|16|Yes|5 | ||
| 9 | |||
| 10 | The range of devices, including those specified as the two destinations are reset, D,,1,, and D,,2,, could be word or bit(Y, M or S). D,,1,, and D,,2,, must be the same kind device. | ||
| 11 | |||
| 12 | The number of D,,1,, should be smaller than D,,2,,. If D,,1,, is 32bit counter, then D,,2,, must be 32bit counter too. | ||
| 13 | |||
| 14 | (% border="1" %) | ||
| 15 | |(% rowspan="2" %)**Operand**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device** | ||
| 16 | |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z | ||
| 17 | |D,,1,,| |√|√|√| | | | | | | |√|√|√|√| | ||
| 18 | |D,,2,,| |√|√|√| | | | | | | |√|√|√|√| | ||
| 19 | |||
| 20 | **Program example** | ||
| 21 | |||
| 22 | (% style="text-align:center" %) | ||
| 23 | [[image:7-4Data operation_html_b9a390356830a8cc.jpg||height="256" width="300" class="img-thumbnail"]] | ||
| 24 | |||
| 25 | 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 | ||
| 26 | |||
| 27 | (% style="text-align:center" %) | ||
| 28 | [[image:7-4Data operation_html_b8258ee6d85abca6.jpg||height="127" width="300" class="img-thumbnail"]] | ||
| 29 | |||
| 30 | = **DECO instruction** = | ||
| 31 | |||
| 32 | **Instruction description** | ||
| 33 | |||
| 34 | (% border="1" %) | ||
| 35 | |**Name**|**Function**|**Bits**|**Pulse type**|**Instruction format**|**Step** | ||
| 36 | |DECO|(% rowspan="2" %)Source data value Q identifies the Qth bit of the destination device which will be turned ON|16|No|(% rowspan="2" %)DECO S D n|7 | ||
| 37 | |DECOP|16|Yes|7 | ||
| 38 | |||
| 39 | 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. | ||
| 40 | |||
| 41 | * If n=0, the instruction is not executed, if n is not equal to 0~~8, then an error will occur. | ||
| 42 | * When n=8 and the D1, D2 are bit devices, means the points are 256. | ||
| 43 | * When the drive input is OFF, the instruction is not executed and the decoded output of the action is not changed. | ||
| 44 | * When the D parameter is a word device, the range of n is 1 ~~ 4 | ||
| 45 | |||
| 46 | Generally, DECOP is used in the real application. | ||
| 47 | |||
| 48 | (% border="1" %) | ||
| 49 | |(% rowspan="2" %)**Operand**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device** | ||
| 50 | |**X**|**Y**|**M**|**S**|**K**|**H**|**E**|**KnX**|**KnY**|**KnM**|**KnS**|**T**|**C**|**D**|**V**|**Z** | ||
| 51 | |S|√|√|√|√|√| | | | | | |√|√|√|√|√ | ||
| 52 | |D| |√|√|√| | | | | | | |√|√|√| | | ||
| 53 | |n|(% colspan="16" %)Constant, n=1~~8, if n=0, the instruction is not executed, if n is not equal to 0~~8, then an error will occur. | ||
| 54 | |||
| 55 | **Program example** | ||
| 56 | |||
| 57 | (% style="text-align:center" %) | ||
| 58 | [[image:7-4Data operation_html_301cb54a6a229e9.jpg||height="194" width="600" class="img-thumbnail"]] | ||
| 59 | |||
| 60 | = **ENCO instruction** = | ||
| 61 | |||
| 62 | **Instruction description** | ||
| 63 | |||
| 64 | (% border="1" %) | ||
| 65 | |**Name**|**Function**|(% style="width:155.412px" %)**Bit**|(% style="width:190.588px" %)**Pulse type**|**Instruction format**|**Step** | ||
| 66 | |ENCO|(% rowspan="2" %)Encode|(% style="width:155.412px" %)16|(% style="width:190.588px" %)No|(% rowspan="2" %)ENCO S D n|7 | ||
| 67 | |ENCOP|(% style="width:155.412px" %)16|(% style="width:190.588px" %)Yes|7 | ||
| 68 | |||
| 69 | 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). | ||
| 70 | |||
| 71 | (% border="1" %) | ||
| 72 | |(% rowspan="2" %)**Operand**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device** | ||
| 73 | |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z | ||
| 74 | |S|√|√|√|√|√|√| | | | | |√|√|√|√|√ | ||
| 75 | |D| |√|√|√| | | | | | | |√|√|√| | | ||
| 76 | |n|(% colspan="16" %)Constant, n=1~~8, if n=0, the instruction is not executed | ||
| 77 | |||
| 78 | **Points to note** | ||
| 79 | |||
| 80 | * 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. | ||
| 81 | * 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. | ||
| 82 | * 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. | ||
| 83 | * When the D parameter is a word device, the range of n is 1 ~~ 4 | ||
| 84 | |||
| 85 | **Program example** | ||
| 86 | |||
| 87 | (% style="text-align:center" %) | ||
| 88 | [[image:7-4Data operation_html_117a6600b0ed252.jpg||height="529" width="500" class="img-thumbnail"]] | ||
| 89 | |||
| 90 | = **SUM instruction** = | ||
| 91 | |||
| 92 | **Instruction description** | ||
| 93 | |||
| 94 | (% border="1" %) | ||
| 95 | |**Name**|**Function**|**Bit**|**Pulse type**|**Instruction format**|**Step** | ||
| 96 | |SUM|(% rowspan="4" %)The number (quantity) of active bits in the source data is stored in the destination device|16|No|(% rowspan="4" %)SUM S D|5 | ||
| 97 | |SUMP|16|Yes|5 | ||
| 98 | |DSUM|32|No|9 | ||
| 99 | |DSUMP|32|Yes|9 | ||
| 100 | |||
| 101 | 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. | ||
| 102 | |||
| 103 | (% border="1" %) | ||
| 104 | |(% rowspan="2" %)**Operand**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device** | ||
| 105 | |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z | ||
| 106 | |S| | | | | | | |√|√|√|√|√|√|√|√|√ | ||
| 107 | |D| | | | | | | | |√|√|√|√|√|√|√|√ | ||
| 108 | |||
| 109 | **Program example** | ||
| 110 | |||
| 111 | (% style="text-align:center" %) | ||
| 112 | [[image:7-4Data operation_html_5ff4d82d3a538ed2.jpg||height="104" width="600" class="img-thumbnail"]] | ||
| 113 | |||
| 114 | = **BON instruction** = | ||
| 115 | |||
| 116 | **Instruction description** | ||
| 117 | |||
| 118 | (% border="1" %) | ||
| 119 | |**Name**|**Function**|**Bit**|**Pulse type**|**Instruction format**|**Step** | ||
| 120 | |BON|(% rowspan="4" %)The status of the specified bit in the source device is indicated at the destination|16|No|(% rowspan="4" %)BON S D n|7 | ||
| 121 | |BONP|16|Yes|7 | ||
| 122 | |DBON|32|No|13 | ||
| 123 | |DBONP|32|Yes|13 | ||
| 124 | |||
| 125 | Determine the nth bit state of S and save the value to D. | ||
| 126 | |||
| 127 | (% border="1" %) | ||
| 128 | |(% rowspan="2" %)**Operand**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device** | ||
| 129 | |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z | ||
| 130 | |S| | | | |√|√| |√|√|√|√|√|√|√|√|√ | ||
| 131 | |D| |√|√|√| | | | | | | | | | | | | ||
| 132 | |n|(% colspan="16" %)N=0~~15 (16-bit); n=0~~31(32bit) | ||
| 133 | |||
| 134 | **Program example** | ||
| 135 | |||
| 136 | (% style="text-align:center" %) | ||
| 137 | [[image:7-4Data operation_html_f040e329f4c8efd4.jpg||height="237" width="600" class="img-thumbnail"]] | ||
| 138 | |||
| 139 | When M10 turns from On to OFF, M10 keeps the initial value. | ||
| 140 | |||
| 141 | = **MEAN instruction** = | ||
| 142 | |||
| 143 | **Instruction description** | ||
| 144 | |||
| 145 | (% border="1" %) | ||
| 146 | |**Name**|**Function**|**Bits(bits)**|**Pulse type**|**Instruction format**|**Step** | ||
| 147 | |MEAN|(% rowspan="4" %)((( | ||
| 148 | Calculates the | ||
| 149 | |||
| 150 | mean of a range of devices | ||
| 151 | )))|16|No|(% rowspan="4" %)MEAN S D n|7 | ||
| 152 | |MEANP|16|Yes|7 | ||
| 153 | |DMEAN|32|No|13 | ||
| 154 | |DMEANP|32|Yes|13 | ||
| 155 | |||
| 156 | 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. | ||
| 157 | |||
| 158 | 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. | ||
| 159 | |||
| 160 | (% border="1" %) | ||
| 161 | |(% rowspan="2" %)**Operand**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device** | ||
| 162 | |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z | ||
| 163 | |S| | | | | | | |√|√|√|√|√|√|√| | | ||
| 164 | |D| | | | | | | | |√|√|√|√|√|√|√|√ | ||
| 165 | |n|(% colspan="16" %)Constant, n=1~~64 | ||
| 166 | |||
| 167 | **Program example ** | ||
| 168 | |||
| 169 | (% style="text-align:center" %) | ||
| 170 | [[image:7-4Data operation_html_df5d3bdcf1124cdf.jpg||height="67" width="400" class="img-thumbnail"]] | ||
| 171 | |||
| 172 | (D10+D11+D12+D13)/4=D20 | ||
| 173 | |||
| 174 | For example, D10=K5,D11=K5,D12=K15,D13=D52 , then D20=K19,the remainder 1 is ignored. | ||
| 175 | |||
| 176 | = **ANS instruction** = | ||
| 177 | |||
| 178 | **Instruction description** | ||
| 179 | |||
| 180 | (% border="1" %) | ||
| 181 | |**Name**|**Function**|**Bits**|**Pulse type**|**Instruction format**|**Step** | ||
| 182 | |ANS|(Timed) Annunciator Set|16|No|ANS S m D|7 | ||
| 183 | |||
| 184 | 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. | ||
| 185 | |||
| 186 | 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. | ||
| 187 | |||
| 188 | (% border="1" %) | ||
| 189 | |(% rowspan="2" %)**Operand**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device** | ||
| 190 | |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z | ||
| 191 | |S| | | | | | | | | | | |√| | | | | ||
| 192 | |D| | | |√| | | | | | | | | | | | | ||
| 193 | |m|(% colspan="16" %)Constant, n=1~~32767 (unit: 1000ms) | ||
| 194 | |||
| 195 | **Program example ** | ||
| 196 | |||
| 197 | (% style="text-align:center" %) | ||
| 198 | [[image:7-4Data operation_html_f20ed27813409ffd.jpg||height="76" width="400" class="img-thumbnail"]] | ||
| 199 | |||
| 200 | 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. | ||
| 201 | |||
| 202 | 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. | ||
| 203 | |||
| 204 | = **ANR instruction** = | ||
| 205 | |||
| 206 | **Instruction description** | ||
| 207 | |||
| 208 | (% border="1" %) | ||
| 209 | |**Name**|**Function**|**Bits(bits)**|**Pulse type**|**Instruction format**|**Step** | ||
| 210 | |ANR|(% rowspan="2" %)The lowest active annunciator is reset on every operation of this instruction|16|No|(% rowspan="2" %)ANR|1 | ||
| 211 | |ANRP|32|Yes|1 | ||
| 212 | |||
| 213 | ANR is used for reset the alarm signal, e.g. | ||
| 214 | |||
| 215 | (% style="text-align:center" %) | ||
| 216 | [[image:7-4Data operation_html_eae692d63df64c1f.jpg||height="72" width="300" class="img-thumbnail"]] | ||
| 217 | |||
| 218 | 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. | ||
| 219 | |||
| 220 | If X3 is ON again, then the next alarm signal from S900 to S999 will be reset. Generally, we will use ANRP instruction. | ||
| 221 | |||
| 222 | **Program example** | ||
| 223 | |||
| 224 | (% style="text-align:center" %) | ||
| 225 | [[image:7-4Data operation_html_bfeead386d8f9800.png||height="145" width="300" class="img-thumbnail"]] | ||
| 226 | |||
| 227 | |||
| 228 | (% style="text-align:center" %) | ||
| 229 | [[image:7-4Data operation_html_15e4de2ec167843e.jpg||height="356" width="300" class="img-thumbnail"]] | ||
| 230 | |||
| 231 | 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. | ||
| 232 | |||
| 233 | = **SQR instruction** = | ||
| 234 | |||
| 235 | **Instruction description** | ||
| 236 | |||
| 237 | (% border="1" %) | ||
| 238 | |**Name**|**Function**|**Bits**|**Pulse type**|**Instruction format**|**Step** | ||
| 239 | |SQR|(% rowspan="4" %)Performs a mathematical square root|16|No|(% rowspan="4" %)SQR S D|5 | ||
| 240 | |SQRP|16|Yes|5 | ||
| 241 | |DSQR|32|No|9 | ||
| 242 | |DSQRP|32|Yes|9 | ||
| 243 | |||
| 244 | 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. | ||
| 245 | |||
| 246 | (% border="1" %) | ||
| 247 | |(% rowspan="2" %)**Operand**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device** | ||
| 248 | |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z | ||
| 249 | |S| | | | | | | | | | | | | |√| | | ||
| 250 | |D| | | | | | | | | | | | | |√| | | ||
| 251 | |||
| 252 | **Program example ** | ||
| 253 | |||
| 254 | (% style="text-align:center" %) | ||
| 255 | [[image:7-4Data operation_html_33b7e8fcbb83f854.jpg||height="98" width="300" class="img-thumbnail"]] | ||
| 256 | |||
| 257 | If D0=K100, then when X2 is ON, D12=K10; | ||
| 258 | |||
| 259 | If D0=K110, then when X2 is ON, D12=K10, decimal is ignored. | ||
| 260 | |||
| 261 | = **FLT instruction** = | ||
| 262 | |||
| 263 | **Instruction description** | ||
| 264 | |||
| 265 | (% border="1" %) | ||
| 266 | |**Name**|**Function**|**Bit**|**Pulse type**|**Instruction format**|**Step** | ||
| 267 | |FLT|(% rowspan="4" %)Used to convert data to floating point format|16|No|(% rowspan="4" %)FLT S D|5 | ||
| 268 | |FLTP|16|Yes|5 | ||
| 269 | |DFLT|32|No|9 | ||
| 270 | |DFLTP|32|Yes|9 | ||
| 271 | |||
| 272 | 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) | ||
| 273 | |||
| 274 | (% border="1" %) | ||
| 275 | |(% rowspan="2" %)**Operand**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device** | ||
| 276 | |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z | ||
| 277 | |S| | | | | | | | | | | | | |√| | | ||
| 278 | |D| | | | | | | | | | | | | |√| | | ||
| 279 | |||
| 280 | **Program example ** | ||
| 281 | |||
| 282 | (% style="text-align:center" %) | ||
| 283 | [[image:7-4Data operation_html_bc78eb3124779c74.jpg||height="91" width="300" class="img-thumbnail"]] | ||
| 284 | |||
| 285 | When M8=ON, D10 (16bit BIN) will be converted to binary floating number and saved in D120 and D121. | ||
| 286 | |||
| 287 | When M10=ON, D20 (32bit BIN) will be converted to binary floating number and saved in D130 and D131. | ||
| 288 | |||
| 289 | = **SWAP instruction** = | ||
| 290 | |||
| 291 | **Instruction description** | ||
| 292 | |||
| 293 | (% border="1" %) | ||
| 294 | |**Name**|**Function**|**Bit**|**Pulse type**|**Instruction format**|**Step** | ||
| 295 | |SWAP|(% rowspan="4" %)The high and low byte of the designated devices are exchanged|16|No|(% rowspan="4" %)SWAP S|3 | ||
| 296 | |SWAPP|16|Yes|3 | ||
| 297 | |DSWAP|32|No|5 | ||
| 298 | |DSWAPP|32|Yes|5 | ||
| 299 | |||
| 300 | In single word (16-bit) operation the upper and lower byte of the source device are exchanged. | ||
| 301 | |||
| 302 | In double word (32-bit) operation the upper and lower byte of each or the two 16-bit devices are exchanged. | ||
| 303 | |||
| 304 | (% border="1" %) | ||
| 305 | |(% rowspan="2" %)**Operand**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device** | ||
| 306 | |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z | ||
| 307 | |S| | | | | | | |√|√|√|√|√|√|√|√|√ | ||
| 308 | |||
| 309 | **Program example** | ||
| 310 | |||
| 311 | (% style="text-align:center" %) | ||
| 312 | [[image:7-4Data operation_html_b15434454358db91.jpg||height="204" width="600" class="img-thumbnail"]] | ||
| 313 | |||
| 314 | In the left demo, the upper and lower byte of D20 is exchanged. | ||
| 315 | |||
| 316 | In the right demo, the upper and lower byte of D20 and D21 are exchanged. |