The text of a manual · part 40 of 60
DL205 PLC User Manual, Volume 1 of 2, pages 391 to 400
Pages 391 to 400 of 598
The original document is the PDF (12 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
For the AutomationDirect D2-04TD1, AutomationDirect D2-08TD2, AutomationDirect D2-16ND3-2, AutomationDirect D2-32ND3, Konnect-It D2-04TD1, Koyo D2-04TD1, Konnect-It D2-08TD2, Koyo D2-08TD2, and 5 more models
Page 391
Chapter 5: Standard RLL Instructions In the following example, when X1 is on, the constant value (K6) is loaded into the accumulator using the Load instruction. This value specifies the length of the table and is placed in the first stack location after the Load Address instruction is executed. The octal address 1400 (V1400), which is the starting location for the destination table and table counter, is loaded into the accumulator. The source location (V1500) is specified in the Add to Top instruction. The table counter will be increased by “1” after the instruction is executed. DirectSOFT X1
LD K6 Load the constant value 6 (Hex.) into the lower 16 bits of the accumulator LDA O 1400 Convert octal 1400 to HEX 300 and load the value into the accumulator ATT V1500 Copy the specified value from V1500 to the table
Handheld Programmer Keystrokes $
B
STR
1
SHFT
L ANDST
D
SHFT
L ANDST
D
SHFT
A
T MLR
0
ENT PREV
3 3
A
0
T MLR
G B B
6 1 1
ENT E F
4 5
A A
0 0
A A
For the ATT instruction, the table counter determines the number of additions that can be made before the V1401 instruction will stop executing. So, it is helpful to V1402 understand how the system uses this counter to control V1403 V1404 the execution. V1405 For example, if the table counter was set to 2, and the V1406 table length was 6 words, then there could only be 4 V1407 additions of data before the execution was stopped. This can be calculated easily by: Table length – table counter = number of executions Also, our example uses a normal input contact (X1) to control the execution. Since the CPU scan is extremely fast, and the table counter increments automatically, the data would be moved into the table very quickly. If this is a problem for your applicaton, you have an option of using a one-shot (PD) to add one value each time the input contact transitions from low to high.
ENT
0
ENT
0
Table
Table Counter
0
5
0
0
1
9
9
9
9
2
3
0
7
4
3
8
9
8
9
4
1
0
1
0
5
2
0
4
6
6
X
X X
X
0
0
0
2 V1400
Data Source X
X X
X V1500
( e .g .: 6 - 2 = 4 ) DirectSOFT (optional one-shot method) X1 C0
C0 PD LD K6 Load the constant value 6 (HEX) into the lower 16 bits of the accumulator LDA O 1400 Convert octal 1400 to HEX 300 and load the value into the accumulator. This is the starting table location.
DL205 User Manual, 4th Edition, Rev. D
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D
5-167
Page 392
Chapter 5: Standard RLL Instructions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D
The following diagram shows the scan-by-scan results of the execution for our example program. The table counter is set to 2 initially, and it will automatically increment from 2 to 6 as the instruction is executed. Notice how SP56 comes on when the table counter is 6, which is equal to the table length. Plus, although our example does not show it, we are assuming that there is another part of the program that changes the value in V1500 (data source) prior to the execution of the ATT instruction. Example of Execution Scan N Before ATT Execution Table
After ATT Execution
V1401
0
5
0
0
1
V1402
9
9
9
9
2
V1403
3
0
7
4
3
V1404
8
9
8
9
4
V1405
1
0
1
0
5
V1406
2
0
4
6
6
V1407
X
X X
X
0
0
0
2 V1400
Data Source 1
2
3
Table counter (Automatically Incremented)
Table
Table counter
4 V1500
SP56 SP56 = OFF
V1401
1
2
3
4
1
V1402
0
5
0
0
2
V1403
9
9
9
9
3
V1404
3
0
7
4
4
V1405
8
9
8
9
5
V1406
1
0
1
0
6
V1407
X
X
X
X
1
2
0 3
4
0
0
3 V1400
Data Source 1
2
3
4
V1500
SP56 SP56 =
OFF
Discard Bucket 2046
Scan N+1
After ATT Execution
Before ATT Execution Table counter
Table V1401
1
2
3
4
1
V1402
0
5
0
0
2
V1403
9
9
9
9
3
V1404
3
0
7
4
4
V1405
8
9
8
9
5
V1406
1
0
1
0
6
V1407
X
X
X
X
0
0
0
3 V1400
Data Source 5
6
7
Table counter (Automatically Incremented)
Table
8 V1500
SP56 SP56 = OFF
V1401
5
6
7
8
1
V1402
1
2
3
4
2
V1403
0
5
0
0
3
V1404
9
9
9
9
4
V1405
3
0
7
4
5
V1406
8
9
8
9
6
V1407
X
X
X
X
5
6
V1401
5
V1402
1
2
3
8
1
4
2
V1403
0
5
0
0
3
V1404
9
9
9
9
4
V1405
3
0
7
4
5
V1406
8
9
8
9
6
V1407
X
X
X
X
Table counter 0 0 0 4 V1400 Data Source 4
3
3
4 V1500
SP56 SP56 = OFF
0
0
4 V1400
Data Source 6
7
8 V1500
SP56 SP56 =
OFF
Discard Bucket
After ATT Execution
Before ATT Execution Table 6 7
8
5
1010
Scan N+2
0 7
Table counter (Automatically Incremented)
V1401
Table 4 3 4
3
1
V1402
5
6
7
8
2
V1403
1
2
3
4
3
V1404
0
5
0
0
4
V1405
9
9
9
9
5
V1406
3
0
7
4
6
V1407
X
X
X
X
4
3
0 4
3
0
0
5 V1400
Data Source 4
3
4
3 V1500
SP56 SP56 = OFF Discard Bucket 8989
Scan N+3
Before ATT Execution
V1401
4
Table 3 4
V1402
5
6
7
After ATT Execution
Table counter
Table
(Automatically Incremented)
Table counter 3
1
8
2
V1403
1
2
3
4
3
V1404
0
5
0
0
4
V1405
9
9
9
9
5
V1406
3
0
7
4
6
V1407
X
X
X
X
0
0
0
5 V1400
Data Source 7
7
7
7 V1500
SP56 SP56 = OFF
V1401
7
7
7
7
1
V1402
4
3
4
3
2
V1403
5
6
7
8
3
V1404
1
2
3
4
4
V1405
0
5
0
0
5
V1406
9
9
9
9
6
V1407
X
X
X
X
7
0 7
7
DL205 User Manual, 4th Edition, Rev. D
0
0
6 V1400
Data Source 7
7
7
7 V1500
SP56
Discard Bucket 3074
5-168
7
SP56 = ON until end of scan or next instruction that uses SP56
Page 393
Chapter 5: Standard RLL Instructions
Table Shift Left (TSHFL)
1 2 The Table Shift Right instruction shifts all the bits in a V-memory 3 table to the right a specified number of bit positions. TSHFR Vaaa 4 The following description applies to both the Table Shift Left and Table Shift Right instructions. A table is a range of V-memory 5 locations. The Table Shift Left and Table Shift Right instructions shift bits serially throughout the entire table. Bits are shifted out the end of one word and into the opposite end of an adjacent word. At the ends of the table, bits are either discarded, or zeros are shifted into the 6 table. The example tables below are arbitrarily four words long. 7 8 9 10 11 Step 1: L oad the length of the table (number of V-memory locations) into the first level of the accumulator stack. This parameter must be a HEX value, 0 to FF. Step 2: L oad the starting V-memory location for the table into the accumulator. This parameter 12 must be a HEX value. You can use the LDA instruction to convert an octal address to hex. Step 3: nsert the Table Shift Left or Table Shift Right instruction. This specifies the number of bit 13 positions you wish to shift the entire table. The number of bit positions must be in octal. Helpful hint: Remember that each V-memory location contains 16 bits. The bits of the first word of the table are numbered from 0 to 17 octal. If you want to shift the entire table by 20 14 bits, that is 24 octal. Flag 53 will be set if the number of bits to be shifted is larger than the total bits contained within the table. Flag 67 will be set if the last bit shifted (just before it is A discarded) is a “1”. Operand Data Type DL260 Range B aaa C D
Table Shift Left instruction shifts all the bits in a V-memory 230 The table to the left a specified number of bit positions. 240 250-1 260 Table Shift Right (TSHFR)
230 240 250-1 260
DS Used HPP Used
Table Shift Left
Table Shift Right
Shift in zeros
V - xxxx
TSHFL Vaaa
Discard Bits
V - xxxx + 1
V - xxxx + 2
Discard Bits
Shift in zeros
V-memory
V
All (See page 3-56)
DL205 User Manual, 4th Edition, Rev. D
5-169
Page 394
Chapter 5: Standard RLL Instructions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D
Discrete Bit Flags
Description
SP53
On when the number of bits to be shifted is larger than the total bits contained within the table
SP67
On when the last bit shifted (just before it is discarded) is a “1”
5-170
NOTE: Status flags are only valid until:, the end of the scan, or another instruction that uses the same flag is executed.
V 3000
V 3000
1 2 3 4
6 7 8 1
5 6 7 8
1 2 2 5
The example table to the right contains BCD data 1 1 2 2 3 4 4 1 as shown (for demonstration purposes). Suppose we want to do a table shift right by 3 BCD digits (12 bits). 3 3 4 4 5 6 6 3 Converting to octal, 12 bits is 14 octal. Using the Table 0 0 0 5 Shift Right instruction and specifying a shift by octal 14, 5 5 6 6 we have the resulting table shown at the far right. Notice that the 2–3–4 sequence has been discarded, and the 0–0–0 sequence has been shifted in at the bottom. The following ladder example assumes the data at V3000 to V3004 already exists as shown above. We will use input X0 to trigger the Table Shift Right operation. First, we will load the table length (5 words) into the accumulator stack. Next, we load the starting address into the accumulator. Since V3000 is an octal number we have to convert it to hex by using the LDA command. Finally, we use the Table Shift Right instruction and specify the number of bits to be shifted (12 decimal), which is 14 octal. DirectSOFT X0
Load the constant value 5 (Hex.) into the lower 16 bits of the accumulator.
LD K5
Convert octal 3000 to HEX and load the value into the accumulator. This is the table beginning.
LDA O 3000
Do a table shift right by 12 bits, which is 14 octal.
TSHFR O 14
Handheld Programmer Keystrokes $
A
STR
SHFT
L ANDST
D
SHFT
L ANDST
D
SHFT
T MLR
0
ENT PREV
3 3
SHFT
A
D
0
S RST
F
H
7
F
5 3 5
DL205 User Manual, 4th Edition, Rev. D
ENT A
0
R ORN
A
0
A
0
NEXT
ENT B
1
E
4
ENT
Page 395
Chapter 5: Standard RLL Instructions
AND Move (ANDMOV)
ANDMOV Vaaa
1 2 ORMOV Vaaa 3 OR Move (ORMOV) The Or Move instruction copies data from a table to the 4 specified memory location, ORing each word with the XORMOV accumulator contents as it is written. Vaaa 5 Exclusive OR Move (XORMOV) The Exclusive OR Move instruction copies data from a table to 6 the specified memory location, XORing each word with the accumulator value as it is written.
The following description applies to the AND Move, OR Move, and Exclusive OR Move 7 instructions. A table is just a range of V-memory locations. These instructions copy the data of a table to another specified location, preforming a logical operation on each word with the 8 accumulator contents as the new table is written. Step 1: the length of the table (number of V-memory locations) into the first level of the accumulator stack. This parameter must be a HEX value, 0 to FF. 9 Step 2: the starting V-memory location for the table into the accumulator. This parameter must be a HEX value. You can use the LDA instruction to convert an octal address to hex. 10 Step 3: the BCD/hex bit pattern into the accumulator which will be logically combined with the table contents as they are copied. 11 Step 4: the AND Move, OR Move, or XOR Move instruction. This specifies the starting location of the copy of the original table. This new table will automatically be the same length as the original table. 12 Operand Data Type DL260 Range 13 aaa 14 The example table to the right contains BCD data as shown (for demonstration purposes). Suppose we want to move a table of two words at V3000 and AND it with A K6666. The copy of the table at V3100 shows the result of the AND operation for each word. B The program on the next page performs the ANDMOV operation example above. It assumes that the data in the table at V3000 – V3001 already exists. First we load the table length (two words) into the accumulator. Next we load the C starting address of the source table, using the LDA instruction. Then we load the data into the accumulator to be ANDed with the table. In the ANDMOV command, we specify the table D destination, V3100. 230 240 250-1 260
The AND Move instruction copies data from a table to the specified memory location, ANDing each word with the accumulator data as it is written.
230 240
250-1 260
DS Used HPP Used
V-memory
V
All (See page 3-56)
V 3000
3 3 3 3
V 3100
ANDMOV K 6666
F F F F
DL205 User Manual, 4th Edition, Rev. D
2 2 2 2
6 6 6 6
5-171
Page 396
Chapter 5: Standard RLL Instructions DirectSOFT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D 5-172
Handheld Programmer Keystrokes $ STR
A
0
SHFT
L D 3 ANDST
SHFT
L D 3 ANDST
SHFT
L D 3 ANDST
V AND
SHFT
M ORST
X0
LD
ENT
K2 PREV
A
D
0 PREV
O INST#
C
2
A
3
G
6
V AND
Load the constant value 2 (Hex.) into the lower 16 bits of the accumulator.
ENT
0
G
6
D
3
A G B
0 6 1
A G A
0 6 0
ENT
LDA
ENT A
0
0 3000 Convert otal 3000 to HEX and load the value into the accumulator. This is the table beginning.
ENT
The example to the right shows a table of two words at V3000 and logically ORs it with K8888. The copy of the table at V3100 shows the result of the OR operation for each word. The program to the right performs the ORMOV example above. It assumes that the data in the table at V3000 – V3001 already exists. First we load the table length (two words) into the accumulator. Next we load the starting address of the source table, using the LDA instruction. V 3000 Then we load the data into the accumulator to be ORed with the table. In the ORMOV command, we specify 1 1 1 1 the table destination, V3100.
LD K6666 Load the constant value 6666 (Hex.) into the lower 16 bits of the accumulator. ANDMOV 0 3100 Copy the table to V3100, ANDing its contents with the accumulator as it is written.
V 3100 OR MOV K 8888
9 9 9 9
1 1 1 1 DirectSOFT 32
Handheld Programmer Keystrokes A
$ STR
0
SHFT
L D ANDST 3
SHFT
L D ANDST 3
SHFT
L D ANDST 3
Q
SHFT
OR
M ORST
X0
ENT PREV A
C D
0 PREV
O INST#
9 9 9 9
V AND
I
LD K2
ENT
2 3 8
A I D
0 8 3
A I B
0 8 1
A I A
0 8 0
Load the constant value 2 (Hex) into the lower 16 bits of the accumulator.
ENT
LDA
ENT A
0 3000 0
ENT
Convert octal 3000 to HEX and load the value into the accumulator. This is the table beginning.
The example to the right shows a table of two words at V3000 and logical XORs it with K3333. The copy of the table at V3100 shows the result of the XOR operation for each word. The ladder program example for the XORMOV is similar to the one above for the ORMOV. Just use the XORMOV instruction. On the Handheld Programmer, you must use the SHFT key and spell “XORMOV” explicitly.
LD K8888 Load the constant value 8888 (Hex.) into the lower 16 bits of the accumulator. ORMOV 0 3100 Copy the table to V3100, ORing its contents with the accumulator as it is written.
V 3000 1 1 1 1 1 1 1 1
DL205 User Manual, 4th Edition, Rev. D
V 3100 X OR MOV K 3333
2 2 2 2 2 2 2 2
Page 397
Chapter 5: Standard RLL Instructions
Find Block (FINDB)
1 2 stored in the accumulator. If the block is not found, flag SP53 3 will be set. Operand Data Type DL260 Range 4 A aaa 5 6 Discrete Bit Flags Description 7 The steps below are necessary to program the Find Block function. Step 1: the number of bytes in the block to be located. This parameter must be a decimal value 8 from 1 to 256. Step 2: the length of a table (number of words) to be searched. The Find Block will search multiple tables that are adjacent in V-memory. This parameter must be a decimal value from 9 1 to 128. Step 3: the ending location for all the tables into the accumulator. This parameter must be a 10 HEX value. You can use the LDA instruction to convert an octal address to hex. Step 4: the table starting location for all the tables into the accumulator. This parameter must be 11 a HEX value. You can use the LDA instruction to convert an octal address to hex. Step 5: the Find Block instruction. This specifies the starting location of the block of data you 12 are trying to locate. 13 14 A B C D
Find Block instruction searches for an occurrence of a 230 The specified block of values in a V-memory table. The function 240 parameters are loaded into the first and second levels of the 250-1 accumulator stack and the accumulator by three additional 260 instructions. If the block is found, its starting address will be
DS Used HPP N/A
V-memory V-memory
V2000 V2017 V2020 V2037 V2040 V2057
Sample Program of FINDB
V2777
End Addr.
X1
Table 1
16 words
Table 2
16 words
Start Addr.
Table 3
16 words
V3000
Table 32
LD
Block
LD
32 bytes
V3017
V2760
All (See page 3 - 56) All (See page 3 - 56)
On when the Find Block instruction was executed but did not find the block of data in table specified.
SP53
Start Addr.
V P
FINDB Aaaa
K32 K16
LDA O2777 LDA O2000
16 words
FINDB V3000
END
DL205 User Manual, 4th Edition, Rev. D
5-173
Page 398
Chapter 5: Standard RLL Instructions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D
Swap (SWAP)
230 240 250-1 260 DS Used HPP Used
5-174
The Swap instruction exchanges the data in two tables of equal length.
SWAP V aaa
The following steps apply to both the Set Bit and Reset Bit table instructions. Step 1: L oad the length of the tables (number of V-memory locations) into the first level of the accumulator stack. This parameter must be a HEX value, 0 to FF. Remember that the tables must be of equal length. Step 2: L oad the starting V-memory location for the first table into the accumulator. This parameter must be a HEX value. You can use the LDA instruction to convert an octal address to hex. Step 3: nsert the Swap instruction. This specifies the starting address of the second table.
Helpful hint: The data swap occurs within a single scan. If the instruction executes on multiple consecutive scans, it will be difficult to know the actual contents of either table at any particular time. So, remember to swap just on a single scan. Operand Data Type DL260 Range aaa V-memory
V
All (See page 3-56)
The example to the right shows a table of two words at V3000. We will swap its contents with another table of two words at V3100 by using the Swap instruction.
V 3000
V 3100
1 2 3 4
A B C D
S WAP
5 6 7 8
0 0 0 0
The example program below uses a PD contact (triggers for one scan for off-to-on transition). First, we load the length of the tables (two words) into the accumulator. Then we load the address of the first table (V3000) into the accumulator using the LDA instruction, converting the octal address to hex. Note that it does not matter which table we declare “first,” because the swap results will be the same. DirectSOFT X0
Load the constant value 2 (Hex.) into the lower 16 bits of the accumulator.
LD K2
Convert octal 3000 to HEX and load the value into the accumulator. This is the table beginning.
LDA O 3000
Swap the contents of the table in the previous instruction with the one at V3100.
SWAP V 3100 Handheld Programmer Keystrokes $
STR
SHFT
P
SHFT
L ANDST
D
SHFT
L ANDST
D
SHFT
S RST
CV
D
PREV
3 3
SHFT
A
3
A
D
0
W ANDN
C
A
0
P
0 2 3 CV
DL205 User Manual, 4th Edition, Rev. D
ENT ENT A
0
A D
0 3
A B
0 1
ENT A
0
A
0
ENT
Page 399
Chapter 5: Standard RLL Instructions
Clock/Calendar Instructions
1 The Date instruction can be used to set the date in the CPU. DATE 2 The instruction requires two consecutive V-memory locations V aaa (Vaaa) to set the date. If the values in the specified locations are not valid, the date will not be set. The current date can be 3 read from 4 consecutive V-memory locations (V7771–V7774). 4 V-memory Location (BCD) Date Range (READ Only) Year 5 Month Day 6 Day of Week 7 Operand Data Type DL250-1 Range DL260 Range 8 aaa aaa 9 In the following example, when C0 is on, the constant value (K94010301) is loaded into the accumulator using the Load Double instruction (C0 should be a contact from a one shot (PD) instruction). The value in the accumulator is output to V2000 using the Out Double 10 instruction. The Date instruction uses the value in V2000 to set the date in the CPU. 11 12 13 14 A B C D
Date (DATE)
230 240 250-1 260 DS Used HPP Used
0-99 1-12 1-31 0-06
V7774 V7773 V7772 V7771
The values entered for the day of week are: 0=Sunday, 1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday, 6=Saturday.
V-memory
V
All (See page 3-55)
DirectSOFT
All (See page 3-56)
Constant (K)
C0
9
4
0
1
0
3
0
1
Acc. 9
4
0
1
0
3
0
1
9
4
0
1
0
3
0
1
9
4
0
1
0
3
0
1
LDD
In this example, the Date instruction uses the value set in V2000 and V2001 to set the date in the appropriate V memory locations (V7771-V7774).
K94010301
Load the constant value (K94010301) into the accumulator
Acc.
OUTD
V2000
Copy the value in the accumulator to V2000 and V2001
V2001
V2000
DATE
V2000
9
Set the date in the CPU using the value in V2000 and 2001
STR
NEXT
NEXT
D
SHFT
L ANDST
D
A
D
A
0
3
GX OUT
SHFT
D
SHFT
D
A
3
3
0
B
0
NEXT
3
1
T MLR
0
NEXT
A
PREV
J
A
A
0
9
V2000
1
Month
0
3
Day
0
1
Day of Week
ENT
E
4
A
0
B
1
ENT
ENT
C
3
4
Year
Handheld Programmer Keystrokes $
Format
V2001
E
2
4
0
C
0
2
A A
0
0
ENT
A
0
A
0
ENT
DL205 User Manual, 4th Edition, Rev. D
5-175
Page 400
Chapter 5: Standard RLL Instructions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D
Time (TIME) Time instruction can be used to set the time (24-hour TIME 230 The clock) in the CPU. The instruction requires two consecutive V aaa 240 V-memory locations (Vaaa) which are used to set the time. If 250-1 the values in the specified locations are not valid, the time will 260 not be set. The current time can be read from memory locations V7747 and V7766–V7770. DS Used HPP Used
5-176
Date
Range
1/100 seconds (10ms) Seconds Minutes Hour
V-memory Location (BCD) (READ Only)
0-99 0-59 0-59 0-23
V7747 V7766 V7767 V7770
Operand Data Type
DL250-1 Range
DL260 Range
V-memory
V aaa aaa
All (See page 3-55)
All (See page 3-56)
In the following example, when C0 is on, the constant value (K73000) is loaded into the accumulator using the Load Double instruction (C0 should be a contact from a one shot (PD) instruction). The value in the accumulator is output to V2000 using the Out Double instruction. The Time instruction uses the value in V2000 to set the time in the CPU. DirectSOFT
Constant (K)
C0
0
0
0
7
3
0
0
0
Acc. 0
0
0
7
3
0
0
0
Acc. 0
0
0
7
3
0
0
0
0
0
0
7
3
0
0
0
LDD
The Time instruction uses the value set in V2000 and V2001 to set the time in the appropriate Vmemory locations (V7766–V7770)
K73000 Load the constant value (K73000) into the accumulator OUTD V2000 Copy the value in the accumulator to V2000 and V2001
V2001
Format
V2000
V2001
TIME
0
V2000
0
0
V2000 7
3
0
0
0
Set the time in the CPU using the value in V2000 and V2001
Not Used
Handheld Programmer Keystrokes $
NEXT
NEXT
L ANDST
D
D
GX OUT
SHFT
D
SHFT
T MLR
SHFT
STR
SHFT
3
NEXT
3 C
3 I
8
2
M ORST
NEXT
A
PREV
H
A
A
E
0 4
0 7 0
ENT D A C
3 0 2
DL205 User Manual, 4th Edition, Rev. D
A
0
A
0
A
Hour Minutes
0
ENT
ENT A
0
A
0
A
0
ENT
Seconds