The text of a manual · part 42 of 53
DL06 Micro PLC User Manual, Volume 1 of 2, pages 410 to 419
Pages 410 to 419 of 524
The original document is the PDF (6.4 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 Direct Logic DL06 and Koyo DL06 D0-06DD1
Page 410
Chapter 5: Intelligent Box (IBox) Instructions
BCD to Real with Implied Decimal Point (BCDTOR) (IB-560)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D
DS5
Used
HPP
N/A
BCD to Real with Implied Decimal Point converts the given 4 digit WORD BCD value to a Real number, with the implied number of decimal points (K0-K4). For example, BCDTOR K1234 with an implied number of decimal points equal to K1, would yield R123.4
BCDTOR Parameters • Value (WORD BCD): specifies the word or constant that will be converted to a Real number • Number of Decimal Points: specifies the number of implied decimal points in the Result DWORD • Result (DWORD REAL): specifies the location where the Real number will be placed
Parameter Value (WORD BCD) . . . . . . . . . . . . . . . . . . V,P,K Number of Decimal Points . . . . . . . . . . . . . . . K Result (DWORD REAL) . . . . . . . . . . . . . . . . . . . V
DL06 Range K0-9999; See DL06 V-memory map - Data Words K0-4 See DL06 V-memory map - Data Words
BCDTOR Example
5–256
In the following example, the BCDTOR instruction is used to convert the 16-bit data in V2000 from a 4-digit BCD data format to a 32-bit REAL (floating point) data format and stored into V3000 and V3001. K2 in the Number of Decimal Points implies the data will have two digits to the right of the decimal point.
DL06 Micro PLC User Manual, 3rd Edition Rev. A
Page 411
Chapter 5: Intelligent Box (IBox) Instructions
Double BCD to Real with Implied Decimal Point (BCDTORD) (IB-562) DS5 HPP
Double BCD to Real with Implied Decimal Point converts the given 8 digit DWORD BCD value to a Real number, given an implied number of decimal points (K0-K8). For example, BCDTORD K12345678 with an implied number of decimal points equal to K5, would yield R123.45678
1 2 3 4 BCDTORD Parameters • Value (DWORD BCD): specifies the Dword or constant that will be converted to a Real number 5 • Number of Decimal Points: specifies the number of implied decimal points in the Result DWORD • Result (DWORD REAL): specifies the location where the Real number will be placed 6 7 Parameter DL06 Range 8 9 BCDTORD Example In the following example, the BCDTORD instruction is used to convert the 32-bit data in 10 V2000 from an 8-digit BCD data format to a 32-bit REAL (floating point) data format and stored into V3000 and V3001. 11 K2 in the Number of Decimal Points implies the data will have two digits to the right of the decimal point. 12 13 14 A B C D Used
N/A
Value (DWORD BCD) . . . . . . . . . . . . . . . . . V,P,K Number of Decimal Points . . . . . . . . . . . . . . . K Result (DWORD REAL) . . . . . . . . . . . . . . . . . . . V
K0-99999999; See DL06 V-memory map - Data Words K0-8 See DL06 V-memory map - Data Words
DL06 Micro PLC User Manual, 3rd Edition Rev. A
5–257
Page 412
Chapter 5: Intelligent Box (IBox) Instructions
Math - BCD (MATHBCD) (IB-521)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D
DS5
Used
HPP
N/A
5–258
Math - BCD Format lets you enter complex mathematical expressions like you would in Visual Basic, Excel, or C++ to do complex calculations, nesting parentheses up to 4 levels deep. In addition to + - * /, you can do Modulo (% aka Remainder), Bit-wise And (&) Or (|) Xor (^), and some BCD functions - Convert to BCD (BCD), Convert to Binary (BIN), BCD Complement (BCDCPL), Convert from Gray Code (GRAY), Invert Bits (INV), and BCD/HEX to Seven Segment Display (SEG). Example: ((V2000 + V2001) / (V2003 K100)) * GRAY(V3000 & K001F) Every V-memory reference MUST be to a single word BCD formatted value. Intermediate results can go up to 32 bit values, but as long as the final result fits in a 16 bit BCD word, the calculation is valid. Typical example of this is scaling using multiply then divide, (V2000 * K1000) / K4095. The multiply term most likely will exceed 9999 but fits within 32 bits. The divide operation will divide 4095 into the 32-bit accumulator, yielding a result that will always fit in 16 bits. You can reference binary V-memory values by using the BCD conversion function on a V memory location but NOT an expression. That is BCD(V2000) is okay and will convert V2000 from Binary to BCD, but BCD(V2000 + V3000) will add V2000 as BCD, to V3000 as BCD, then interpret the result as Binary and convert it to BCD - NOT GOOD. Also, the final result is a 16 bit BCD number and so you could do BIN around the entire operation to store the result as Binary. MATHBCD Parameters • WORD Result: specifies the location where the BCD result of the mathematical expression will be placed (result must fit into 16 bit single V-memory location) • Expression: specifies the mathematical expression to be executed and the result is stored in specified WORD Result. Each V-memory location used in the expression must be in BCD format.
Parameter WORD Result . . . . . . . . . . . . . . . . . . . . . . . . . . V Expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
DL06 Range See DL06 V-memory map - Data Words Text
DL06 Micro PLC User Manual, 3rd Edition Rev. A
Page 413
Chapter 5: Intelligent Box (IBox) Instructions
MATHBCD Example In the following example, the MATHBCD instruction is used to calculate the math expression which multiplies the BCD value in V1200 by 1000 then divides by 4095 and loads the resulting value in V2000.
DL06 Micro PLC User Manual, 3rd Edition Rev. A
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D
5–259
Page 414
Chapter 5: Intelligent Box (IBox) Instructions
Math - Binary (MATHBIN) (IB-501)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D
DS5
Used
HPP
N/A
5–260
Math - Binary Format lets you enter complex mathematical expressions like you would in Visual Basic, Excel, or C++ to do complex calculations, nesting parentheses up to 4 levels deep. In addition to + - * /, you can do Modulo (% aka Remainder), Shift Right (>>) and Shift Left (<<), Bit-wise And (&) Or (|) Xor (^), and some binary functions Convert to BCD (BCD), Convert to Binary (BIN), Decode Bits (DECO), Encode Bits (ENCO), Invert Bits (INV), HEX to Seven Segment Display (SEG), and Sum Bits (SUM). Example: ((V2000 + V2001) / (V2003 K10)) * SUM(V3000 & K001F) Every V-memory reference MUST be to a single word binary formatted value. Intermediate results can go up to 32 bit values, but as long as the final result fits in a 16 bit binary word, the calculation is valid. Typical example of this is scaling using multiply then divide, (V2000 * K1000) / K4095. The multiply term most likely will exceed 65535 but fits within 32 bits. The divide operation will divide 4095 into the 32-bit accumulator, yielding a result that will always fit in 16 bits. You can reference BCD V memory values by using the BIN conversion function on a Vmemory location but NOT an expression. That is, BIN(V2000) is okay and will convert V2000 from BCD to Binary, but BIN(V2000 + V3000) will add V2000 as Binary, to V3000 as Binary, then interpret the result as BCD and convert it to Binary - NOT GOOD. Also, the final result is a 16 bit binary number and so you could do BCD around the entire operation to store the result as BCD. MATHBIN Parameters • WORD Result: specifies the location where the binary result of the mathematical expression will be placed (result must fit into 16 bit single V-memory location) • Expression: specifies the mathematical expression to be executed and the result is stored in specified WORD Result. Each V-memory location used in the expression must be in binary format.
Parameter WORD Result . . . . . . . . . . . . . . . . . . . . . . . . . . V Expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
DL06 Range See DL06 V-memory map - Data Words Text
DL06 Micro PLC User Manual, 3rd Edition Rev. A
Page 415
Chapter 5: Intelligent Box (IBox) Instructions
MATHBIN Example In the following example, the MATHBIN instruction is used to calculate the math expression which multiplies the Binary value in V1200 by 1000 then divides by 4095 and loads the resulting value in V2000.
DL06 Micro PLC User Manual, 3rd Edition Rev. A
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D
5–261
Page 416
Chapter 5: Intelligent Box (IBox) Instructions
Math - Real (MATHR) (IB-541)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D
DS5
Used
HPP
N/A
Math - Real Format lets you enter complex mathematical expressions like you would in Visual Basic, Excel, or C++ to do complex calculations, nesting parentheses up to 4 levels deep. In addition to + - * /, you can do Bitwise And (&) Or (|) Xor (^), and many Real functions - Arc Cosine (ACOSR), Arc Sine (ASINR), Arc Tangent (ATANR), Cosine (COSR), Convert Radians to Degrees (DEGR), Invert Bits (INV), Convert Degrees to Radians (RADR), HEX to Seven Segment Display (SEG), Sine (SINR), Square Root (SQRTR), Tangent (TANR). Example: ((V2000 + V2002) / (V2004 R2.5)) * SINR(RADR(V3000 / R10.0)) Every V-memory reference MUST be able to fit into a double word Real formatted value. MATHR Parameters • DWORD Result: specifies the location where the Real result of the mathematical expression will be placed (result must fit into a double word Real formatted location) • Expression: specifies the mathematical expression to be executed and the result is stored in specified DWORD Result location. Each V-memory location used in the expression must be in Real format.
Parameter DWORD Result . . . . . . . . . . . . . . . . . . . . . . . . V Expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
DL06 Range See DL06 V-memory map - Data Words Text
MATHR Example
5–262
In the following example, the MATHR instruction is used to calculate the math expression which multiplies the REAL (floating point) value in V1200 by 10.5 then divides by 2.7 and loads the resulting 32-bit value in V2000 and V2001.
DL06 Micro PLC User Manual, 3rd Edition Rev. A
Page 417
Chapter 5: Intelligent Box (IBox) Instructions
Real to BCD with Implied Decimal Point and Rounding (RTOBCD) (IB-561) Real to BCD with Implied Decimal Point and Rounding converts the absolute value of the given Real number to a 4 digit BCD number, compensating for an implied number of decimal points (K0-K4) and performs rounding. For example, RTOBCD R56.74 with an implied number of decimal points equal to K1, would yield 567 BCD. If the implied number of decimal points was 0, then the function would yield 57 BCD (note that it rounded up). If the Real number is negative, the Result will equal its positive, absolute value.
1 2 3 4 5 RTOBCD Parameters 6 • Value (DWORD Real): specifies the Real Dword location or number that will be converted and rounded to a BCD number with decimal points 7 • Number of Decimal Points: specifies the number of implied decimal points in the Result WORD • Result (WORD BCD): specifies the location where the rounded/implied decimal points BCD value will be placed 8 Parameter DL06 Range 9 10 11 RTOBCD Example In the following example, the RTOBCD instruction is used to convert the 32-bit REAL (floating point) data format in V3000 and V3001 to the 4-digit BCD data format and stored 12 in V2000. 13 K2 in the Number of Decimal Points implies the data will have two implied decimal points. 14 A B C D
DS5
Used
HPP
N/A
Value (DWORD Real) . . . . . . . . . . . . . . . . . V,P,R Number of Decimal Points . . . . . . . . . . . . . . . K Result (WORD BCD) . . . . . . . . . . . . . . . . . . . . . V
R ; See DL06 V-memory map - Data Words K0-4 See DL06 V-memory map - Data Words
DL06 Micro PLC User Manual, 3rd Edition Rev. A
5–263
Page 418
Chapter 5: Intelligent Box (IBox) Instructions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D
Real to Double BCD with Implied Decimal Point and Rounding (RTOBCDD) (IB-563) DS5
Used
HPP
N/A
Real to Double BCD with Implied Decimal Point and Rounding converts the absolute value of the given Real number to an 8 digit DWORD BCD number, compensating for an implied number of decimal points (K0K8) and performs rounding. For example, RTOBCDD R38156.74 with an implied number of decimal points equal to K1, would yield 381567 BCD. If the implied number of decimal points was 0, then the function would yield 38157 BCD (note that it rounded up). If the Real number is negative, the Result will equal its positive, absolute value. RTOBCDD Parameters • Value (DWORD Real): specifies the Dword Real number that will be converted and rounded to a BCD number with decimal points • Number of Decimal Points: specifies the number of implied decimal points in the Result DWORD • Result (DWORD BCD): specifies the location where the rounded/implied decimal points DWORD BCD value will be placed
Parameter Value (DWORD Real) . . . . . . . . . . . . . . . . . V,P,R Number of Decimal Points . . . . . . . . . . . . . . . K Result (DWORD BCD) . . . . . . . . . . . . . . . . . . . . V
DL06 Range R ; See DL06 V-memory map - Data Words K0-8 See DL06 V-memory map - Data Words
RTOBCDD Example
5–264
In the following example, the RTOBCDD instruction is used to convert the 32-bit REAL (floating point) data format in V3000 and V3001 to the 8-digit BCD data format and stored in V2000 and V2001. K2 in the Number of Decimal Points implies the data will have two implied decimal points.
DL06 Micro PLC User Manual, 3rd Edition Rev. A
Page 419
Chapter 5: Intelligent Box (IBox) Instructions
Square BCD (SQUARE) (IB-523) DS5
Used
HPP
N/A
Square BCD squares the given 4-digit WORD BCD number and writes it in as an 8-digit DWORD BCD result. SQUARE Parameters • Value (WORD BCD): specifies the BCD Word or constant that will be squared • Result (DWORD BCD): specifies the location where the squared DWORD BCD value will be placed
Parameter Value (WORD BCD) . . . . . . . . . . . . . . . . . . V,P,K Result (DWORD BCD) . . . . . . . . . . . . . . . . . . . . V
DL06 Range K0-9999 ; See DL06 V-memory map - Data Words See DL06 V-memory map - Data Words
SQUARE Example In the following example, the SQUARE instruction is used to square the 4-digit BCD value in V2000 and store the 8-digit double word BCD result in V3000 and V3001
DL06 Micro PLC User Manual, 3rd Edition Rev. A
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C D
5–265