10 External IO Devices

Last modified by Devin Chen on 2024/02/05 15:55

6.10.1 TKY instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
TKYTen key input16NoTKY S D1 D27
DTKY32No13

This instruction could read from 10 consecutive devices (S+0 to S+9) and will store an entered numeric string in device D1.

  • S is the starting input port of pressing key, occupying the following ten bit units (such as X port);
  • D1 is the storage unit for inputted value;
  • D2 is the temp starting unit for state of current pressing key group, occupying the following eleven bit units;
OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S            
D1        
D2             

Program example

7-9 External IO Devices_html_efea9480fc3d5272.jpg

The corresponding hardware wiring is shown in below figure.

7-9 External IO Devices_html_8b22a7970da57e98.jpg

If user want to input "2013", just pressing key 2, 0, 1, 3 in order. The operation of PLC internal variable is shown as below figure. If using 32bit instruction (DTKY), and occupies 32bit variable. For the above case, they are D1, D0, which is higher word and lower word respectively.

7-9 External IO Devices_html_53d8586b11bf8990.jpg

TKY and DTKY instructions could only use one in the same program, set by parameters in an instruction, X0~X11 respectively correspond to numeric keys 0~9; M0~M9 correspond to the status of keys, key output unit will be reset whenever a key is pressed.

Key values are converted to BIN and saved to the designated D1 unit D; D0 will never change even when the power flow turns OFF.

When several keys are pressed simultaneously, the key which is firstly detected is valid; if the number entered is more than 4 digits, the first entered number will overflow and only a 4-digit number is left.

6.10.2 HKY instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
HKYHex key input16NoHKY S D1 D2 D39
DHKY32Yes17

This instruction creates a multiplex of 4 outputs (D1) and 4 inputs (S) to read in 16 different devices. Which are the decimal 0~9 keys and the functional keys of A~F. When the keys are pressed (ON), decimal numbers of 4 bits between 0~9999 or functional keys between A~F could be entered, depending on the sequence of the key press actions. If 32bit instructions are used, decimal numbers of 8 bits between 0~99,999,999 or functional keys between A~F could be entered.

HKY and DHKY instructions could only use one in the same program.

  • S is the input port X of the keys, 4 X ports will be used;
  • D1 is the starting port button of scouldning output Y port, and it uses the four Y ports.
  • D2 is the storage unit for the entered values from the keys, with a range of 0~9999. If 32bit instructions are used, decimal numbers of 8 bits between 0~99,999,999 could be entered.
  • D3 is the address which displays the entering status of the keys, which occupies a variable unit of 8 continuous bits;
OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
D1               
D2          
D3             

Program example

7-9 External IO Devices_html_3c87145d2bff1a2.jpg

  • MT transistor type controller should be used due to large delay in relay output;
  • When driver power flow X20 turns OFF, D0 remains the same and M0~M7 become OFF;
  • It takes 8 scouldning cycles to perform key scouldning. After that, M8029 will be set for 1 scouldning cycle;

7-9 External IO Devices_html_b8d207d1403b5a24.jpg

When using this instruction, the scould period needs to be greater than or equal to the filter time of X0 ~ 7 input. There are two ways:

  1. Using a constant scould period, set the value of D8039 (unit ms) to be equal to or greater than the filtering time (D8020), and then turn M8039 ON;
  2. Add the REFF instruction before this instruction to set the REFF parameter to a value less than or equal to the scould period.

6.10.3 DSW instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
DSWDigital Switch16NoDWS S D1 D2 n9

This instruction multiplexes 4 outputs (D1) through 1 or 2 sets of switches. Each set of switches consists of 4 thumb wheels providing a single digit input.

OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S               
D1               
D2           
nConstant, n=1~2

Program example

7-9 External IO Devices_html_4db90e657c80f9f7.jpg

7-9 External IO Devices_html_2a9e1ee9857a62e7.jpg

Perform the operation to scould and read the digit switches setting if X20=ON

  • The setting values for the first set of digit switches are converted to BIN and saved to D0;
  • The setting values for the second set of digit switches are converted to BIN and saved to D1;
  • M8029 will be set for scouldning cycle after one-time reading is completed;

Note for use

  • It is recommended that transistor output units are used with this instruction.
  • A digital switch set to read operation requires multiple scould cycle to complete, if the use of keystrokes to start the read operation, it is recommended to use the following program to ensure the integrity of the readable cycle:

7-9 External IO Devices_html_9f3d5902e4815ce5.jpg

When using this instruction, the scould period needs to be greater than or equal to the filter time of X0 ~ 7 input. There are two ways:

  1. Using a constant scould period, set the value of D8039 (unit ms) to be equal to or greater than the filtering time (D8020), and then turn M8039 ON;
  2. Add the REFF instruction before this instruction to set the REFF parameter to a value less than or equal to the scould period.

6.10.4 SEGD instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
SEGDSeven segment decoder16NoSEGD S D5
SEGDP16Yes5

A single hexadecimal digit occupying the lower 4 bits of source device S is decoded into a data format used to drive a seven segment display. A representation of the hex digit is then displayed. The decoded data is stored in the lower 8 bits of destination device D. The bit devices indicate:

  • S: The source data remaining to be decoded (b0 to b3)
  • D: The variable used to store the decoded data
OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S     
D        

Program example

7-9 External IO Devices_html_568802a17e7d3545.jpg

When X20 is triggered, a single hexadecimal digit occupying the lower 4 bits of D0 is decoded into a data format, and then output to Y10~Y17. The decoded format as below

7-9 External IO Devices_html_a1365b2a934b6a0.jpg

6.10.5 SEGL instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
SEGLSeven segment with latch16NoSEGL S D n7

SEGL uses 8 or 12 Y port to drive 4 bits or 8 bits seven-segment digital tube. Tube is display by scould PLC programming manual 4.

  • S: The data to be displayed, it will not be displayed until the value is converted to BCD;
  • D: The beginning number of the Y port that used to drive digital tube;
  • n: The number of display groups, signal positive and negative logic, and other related set values;
OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S     
D               
nConstant, n=0~7

Program example

7-9 External IO Devices_html_f6c0b167db5640a0.jpg

Corresponding hardware connection is as follows. The contents of D0 are displayed in the first group of digital tube, the contents of D1 are displayed in the second group of digital tube and the procedure operation will run error when D0 or D1's numerical reading exceeds 9999:

7-9 External IO Devices_html_27b3ce722db43aca.jpg

The digital tubes in the wiring diagram come with the data show's latch, decoding and driving of 7 segment digital tube, negative logic type (the input data is considered as 1, or strobe when input port is low ) 7-segment digital display tubes. In the display processing, PLC's Y4 ~ Y7 port will automatically scould cycle and only one port is ON and as a bit strobe. In this moment, the data of Y0~Y3 port is the BCD code data sent to the corresponding bits and when bit strobe signal change from the ON → OFF, it will be latched to the latch of digital tube. The digital tubes will display the number after internal decoding and driving. PLC systems will deal with Y4 ~ Y7 cycle in turn and by the same process until all the 4 bits has been processed. Similarly, Y10 ~ Y13 is the second group data output port of 4-bit digital tubes and share Y4 ~ Y7 bit strobe line, so the process is in the same and both groups' display is processed at the same time. For the example, the first group will display 2468 and the second group willdisplay9753whenD0=K2468, D1=K9753.

The SEGL instruction takes 12 program scoulds to complete one output cycle regardless of the number of display sets used. On completion, the execution complete flag M8029 is set.

If there is one group has 4 digits, n=0~3.If there are two groups have 4 digits, n=4~7.

Displayed numberFirst groupSecond group
Polarity of Y outputPNPNPNPNPNPN
Strobe and data polaritySameOppositeSameOppositeSameOppositeSameOpposite
Value of n01234567

The SEGL instruction may be used TWICE on LX3V series PLC.

Note for use

  • It is recommended that transistor output units are used with this instruction.
  • This instruction is executed concurrently with the scould period (operation cycle) of the programmable controller. In order to perform a series of display, the scould cycle of PLC needs more than 10ms; when less than 10ms, using a constant scould mode, please make sure the scould cycle is more than 10ms to run regularly;
  • The voltage of the transistor output of the programmable controller is about 1.5V;

6.10.6 ARWS instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
ARWSArrow Switch16NoARWS S D1 D2 n7

This instruction displays the contents of a single data device D1 on a set of 4 digits, seven segment displays. The data within D1 is actually in a standard decimal format but is automatically converted to BCD for display on the seven segment units. Each digit of the displayed number could be selected and edited. The editing procedure directly changes the value of the device specified as D1.

OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S            
D1           
D2               
nConstant, n=0~3

Program example

7-9 External IO Devices_html_d5025917aea8bbdc.jpg

The corresponding hardware wiring is shown in the following figure, in which PLC is the transistor output type.

7-9 External IO Devices_html_a4d4422f9ddf2089.jpg

Operating procedures

  • The tube shows a figure value of D0. Press X10~X13 to modify the value, which should be within the 0~9999 range;
  • When the X20 is ON, the cursor digit is shown as kilobits. Each time the cursor right (X12) is pressed, the specified bit switches in the order of "thousand→hundred→ten→thousand"; When pressing the cursor left (X13), the switch order reverses; and the digit cursor is indicated by the LED which is connected with the gating pulse signal (Y004 ~Y007.
  • The cursor digit number switches in the order of 0 → 1→ 2→……8→9→0→1 when the increment key (X11) is pressed, when pressing the decrement key (X10), the number switches in the order of 0→9→8→7→…… 1→0→9,and the modified value becomes operative at once.

Note for use

If the scould time of user program, please run in constant scould time or at a fixed time interval within a timed interrupt.

6.10.7 ASC instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
ASCASCII Code16NoASC S D11
  • S: The source data string, it consists of up to 8 characters taken from the printable ASCII character set;
  • D: The start address to saved code. It occupies four (M8161=0) or eight(M8161=1) variable addresses;
OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
SOnly one, 8 character string may be entered at any one time.
D             

Program example

7-9 External IO Devices_html_9b5b2d51017d9594.jpg

7-9 External IO Devices_html_3e9125ec16c8289c.png

7-9 External IO Devices_html_b2fac8e5c76c9f69.jpg

7-9 External IO Devices_html_a761cf8ee52d7641.png

7-9 External IO Devices_html_57d2265569249b0e.jpg

ASCII code table

DecimalASCII (Hex)DecimalASCII (Hex)
030535
131636
232737
333838
434939
English letterASCII (Hex)English letterASCII (Hex)
A41N4E
B42O4F
C43P50
D44Q51
E45R52
F46S53
G47T54
H48U55
I49V56
J4AW57
K4BX58
L4CY59
M4DZ5A
CodeASCII (Hex)CodeASCII (Hex)
STX02ETX03

6.10.8 PR instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
PRASCII Code print16NoPR S D5

Source data (stored as ASCII values) is read byte by byte from the source data devices. Each byte is mapped directly to the first 8 consecutive destination devices D +0 to D +7). The final two destination bits provide a strobe signal (D +10, numbered in octal) and an execution/busy flag (D +11, in octal)

OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S             
D               

Program example

7-9 External IO Devices_html_394cd1c738252c56.jpg

If the ASCII code in D200~D203 is "Stopped", the corresponding output port signal and its timing are shown below.

7-9 External IO Devices_html_2ed70b313ccd51c9.jpg

Note for use

  • This instruction should only be used on transistor output PLC’s;
  • The PR instruction will not automatically repeat its operation unless the drive input has been turned OFF and ON again;
  • 16-byte operation requires the special auxiliary flag M8027 to be driven ON, unless 8-byte operation will be executed;
  • Once the PR instruction is activated it will operate continuously until all 16 bytes of data have been sent or the value 00H (null) has been sent. M8029 the execution complete flag is set.
  • If the scould time of user program, please run in constant scould time or at a fixed time interval within a timed interrupt.

6.10.9 FROM instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
FROMRead data from BFM16NoFROM m1 m2 D n9
FROMP16Yes9
DFROM32No17
DFROMP32Yes17

The FROM instruction reads data from BFM of the special function block.

  • m1: The special function block with the logical block position;
  • m2: The BFM memory address;
  • D: The start address for stored data;
  • n: Data length;
OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
D        
m1, m2= 0~32767; n=1~514(16-bit),1~257(32-bit); D= K1~K4 (16-bit) or K1~K8 (32-bit); m1, m2, n couldn’t support D device;

Program example

7-9 External IO Devices_html_61262a7e8b76e0e7.jpg

When X0 is triggered, PLC reads data from BFM20 of #1 special function block, and stores data in D200, the data length is 1;

When using instructions in 32-bit, addresses designated by D are the low 16-bit addresses; addresses designated by D+1 are the high 16-bit addresses;

n means data length, in 16-bit mode, n=2 means 2 words, but in 32bit mode, n=1 means 2 words.

7-9 External IO Devices_html_d7aec9fa856d3df8.jpg

6.10.10 TO instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
TOWrite data to BFM16NoTO m1 m2 D n9
TOP16Yes9
DTO32No17
DTOP32Yes17

The TO instruction writes data to BFM of the special function block.

  • m1: The special function block with the logical block position;
  • m2: The BFM memory address;
  • D: The start address for stored data;
  • n: Data length;
OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
D        
m1, m2= 0~32767; n=1~514(16-bit),1~257(32-bit); D= K1~K4 (16-bit) or K1~K8 (32-bit); m1, m2, n couldn’t support D device;

Program example

7-9 External IO Devices_html_a7d505a9c7aca463.jpg

When X1 is triggered, PLC writes data from D220 to BFM24 of #1 special function block, and stores, the data length is 1;

When using instructions in 32-bit, addresses designated by D are the low 16-bit addresses; addresses designated by D+1 are the high 16-bit addresses;

n means data length, in 16-bit mode, n=2 means 2 words, but in 32bit mode, n=1 means 2 words.

Points to note about FROM/TO instruction

Accessing the expansion module with the FROM/TO instruction is a time-consuming operation, so the scould cycle will be extended if there were many FROM/TO instructions. In order to prevent running timeout, users could add WDT instruction before FROM/TO, or stagger the execution time of the FROM/TO instruction, or using pulse type instruction.

7-9 External IO Devices_html_4486943e53f4af44.jpg

6.10.11 GRY instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
GRYGray code conversion16NoGRY S D5
GRYP16Yes5
DGRY32No9
DGRYP32Yes9

The binary integer value in S is converted to the GRAY CODE equivalent and stored at D.

OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S     
D        

BIN → GRY Mathematical algorithm: from the right one, in turn, each bit do the XOR operation with the left bit (XOR), as the corresponding GRY bit of the value, the left one unchanged (equivalent to the left is 0);

Program example

7-9 External IO Devices_html_4f71abda7ddefcf8.jpg

[Result]:

7-9 External IO Devices_html_d87aad66ad80baae.jpg

7-9 External IO Devices_html_50c215dedd83c88a.jpg

6.10.12 GBIN instruction

Instruction description

NameFunctionBits(bits)Pulse typeInstruction formatStep
GBINCalculates the gray code value of an integer16NoGBIN S D5
GBINP16Yes5
DGBIN32No9
DGBINP32Yes9

The GRAY CODE value in S is converted to the normal binary equivalent and stored at D.

OperandsBit deviceWord device
XYMSKHEKnXKnYKnMKnSTCDVZ
S     
D        

GRY → BIN Mathematical algorithm: from the left of the second place, each bit with the left side of a decoded value of XOR, as the bit after decoding the value (the left one is still the same).

Program example

7-9 External IO Devices_html_83ab2762525369a2.jpg

[Result]

7-9 External IO Devices_html_d1c446a0dca61b55.jpg