The text of a manual · part 14 of 39
Series 90-30/20/Micro PLC CPU Instruction Set Reference Manual: Chapter 6 - Math Functions, pages 114 to 121
Pages 114 to 121 of 337, from Series 90-30/20/Micro PLC CPU Instruction Set Reference Manual
The original document is the PDF (4.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 GE Fanuc IC692CPU211D / IC692MDR541C, Fanuc IC692CPU211D / IC692MDR541C, GE IC692CPU211D / IC692MDR541C and GE Fanuc IC693CPU311X
Page 114
6
SQRT
(INT, DINT, REAL) The Square Root (SQRT) function is used to find the square root of a value. When the function receives power flow, the value of output Q is set to the integer portion of the square root of the input IN. The output Q must be the same data type as IN. The SQRT function operates on these types of data: Data Type
Description
INT
Signed integer.
DINT
Double precision signed integer.
REAL
Floating Point.
For data types INT and DINT, only the whole number portion of the square root will be output. The fractional portion will be dropped. For example, the square root of 2 or 3 will be 1, and the square root of 5, 6, 7, or 8 will be 2.
Note The REAL data type is only available on 35x and 36x series CPUs, Release 9.00 or later, and on all releases of CPU352 and CPU37x. The default data type is signed integer; however, it can be changed after selecting the function. For more information on data types, please refer to chapter 2, section 2, “Program Organization and User References/Data.” OK is set ON if the function is performed without overflow. If one of the following invalid operations occurs, OK is set OFF: •
IN < 0
•
IN is NaN (Not a Number) SQRT
Enable
OK
INT Input
IN
Data Type Q
Output
Parameters Parameter enable
GFK-0467M
Description When the function is enabled, the operation is performed.
IN
IN contains a constant or reference for the value whose square root is to be calculated. If IN is less than zero, the function will not pass power flow.
ok
The ok output is energized when the function is performed without overflow, unless an invalid operation occurs.
Q
Output Q contains the square root of IN. However, for INT and DINT, only the whole number portion will be kept; any fractional portion will be discarded.
Chapter 6 Math Functions
6-9
Page 115
6 Valid Memory Types Parameter flow enable
•
IN ok o †
%Q
%M
%T o o o o o o
%S
%G
%R
%AI %AQ const o o
•
•
• o o
•
•
•
•
Q •
%I none
•† •
Valid reference or place where power may flow through the function. Valid reference for INT data only; not valid for DINT and REAL. Constants are limited to values between –32,768 and +32,767 for double precision signed integer operations.
Examples In the following example, the square root of the integer number located at %R0008 is placed into the %R0009 register whenever %I0001 is ON. %I0001 OK
SQRT INT %R0008 +00019
Q
IN
%R0009 +00004
As an alternative to the previous example, the same function can be performed with a REAL-type SQRT instruction, which gives a more precise result as shown in the next figure. %I0001 OK
SQRT REAL %R0008 +19.00000
6-10
IN
Q
%R0009 +4.358899
Series 90™-30/20/Micro PLC CPU Instruction Set Reference Manual – May 2002
GFK-0467M
Page 116
6
Trig Functions
(SIN, COS, TAN, ASIN, ACOS, ATAN)
The SIN, COS, and TAN functions are used to find the trigonometric sine, cosine, and tangent, respectively, of its input. When one of these functions receives power flow, it computes the sine (or cosine or tangent) of IN, whose units are radians, and stores the result in output Q. Both IN and Q are floating-point values. The ASIN, ACOS, and ATAN functions are used to find the inverse sine, cosine, and tangent, respectively, of its input. When one of these functions receives power flow, it computes the designated function on the value at the IN input, and stores the result in output Q, whose units are radians. Both IN and Q are floating-point values. The SIN, COS, and TAN functions accept a broad range of input values, where –263 < IN <+263, (263 ≈ 9.22x1018). The ASIN and ACOS functions accept a narrow range of input values, where – 1 ≤ IN ≤ 1. Given a valid value for the IN parameter, the ASIN_REAL function will produce a result Q such that:
π ≤ Q ≤ 2
ASIN (IN) =
π 2
The ACOS_REAL function will produce a result Q such that:
ACOS (IN)
0 ≤ Q ≤ π
=
The ATAN function accepts the broadest range of input values, where – ∞ ≤ IN ≤ + ∞. Given a valid value for the IN parameter, the ATAN_REAL function will produce a result Q such that:
π ≤ Q ≤ 2
ATAN (IN) =
π 2
_____ | | (enable), | SIN_| - (ok) | | | REAL| | | (input parameter IN), |IN Q| - (output parameter Q) |_____|
Note The TRIG functions are only available on the 35x and 36x series CPUs, Release 9 or later, and on all releases of CPU352 and CPU37x.
GFK-0467M
Chapter 6 Math Functions
6-11
Page 117
6
Parameters Parameter
Description enable
When the function is enabled, the operation is performed.
IN
IN contains the constant or reference real value to be operated on.
ok
The ok output is energized when the function is performed without overflow, unless an invalid operation occurs and/or IN is NaN.
Q
Output Q contains the trigonometric value of IN.
Valid Memory Types Parameter flow enable IN
• ok
•
%I
%Q
%M
%T
%S
%G
•
Q •
%R
%AI
%AQ const
•
•
• none
• •
•
•
Valid reference or place where power may flow through the function.
Example In the following example, the COS of the value in %R0001 is placed in %R0033. | _____ |ALW_ON | | | - - ] [ - - - - - - - - - | COS_| - | | | | | REAL| | | | | %R0001 - |IN Q| - %R0033 | | | | +3.141500|_____| -1.000000 |
6-12
Series 90™-30/20/Micro PLC CPU Instruction Set Reference Manual – May 2002
GFK-0467M
Page 118
6
Logarithmic/Exponential Functions (LOG, LN, EXP, EXPT) The LOG, LN, and EXP functions have two input parameters and two output parameters. When the function receives power flow, it performs the appropriate logarithmic/exponential operation on the real value in input IN and places the result in output Q. •
For the LOG function, the base 10 logarithm of IN is placed in Q.
•
For the LN function, the natural logarithm of IN is placed in Q.
•
For the EXP function, e is raised to the power specified by IN and the result is placed in Q. (NOTE: e is a constant used in logarithmic calculations. It has an approximate value of 2.71828.)
•
For the EXPT function, the value of input I1 is raised to the power specified by the value I2 and the result is placed in output Q. (The EXPT function has three input parameters and two output parameters.)
The ok output will receive power flow, unless IN is NaN (Not a Number) or is negative. _____ | | (enable), | LOG_| - (ok) | | | REAL| | | | | (input parameter IN), |IN Q| - (output parameter Q) |_____|
Parameters Parameter enable
Description When the function is enabled, the operation is performed.
IN
IN contains the real value to be operated on.
ok
The ok output is energized when the function is performed without overflow, unless an invalid operation occurs and/or IN is NaN or is negative.
Q
Output Q contains the logarithmic/exponential value of IN.
Note The LOG, LN, EXP and EXPT functions are only available on the 35x and 36x series CPUs, Release 9 or later, and on all releases of CPU352 and CPU37x.
Note When the input value, IN, for the EXP function is negative infinity (-∞), the function returns a value of 0, as expected. In this case, for the CPU352, the function does not pass power. For all other 90-30 CPUs, the function does pass power, even though the output is 0. (A value of -∞ results from dividing a negative value by zero. It will appear on a Logicmaster screen as −OVERFLOW.)
GFK-0467M
Chapter 6 Math Functions
6-13
Page 119
6 Valid Memory Types Parameter flow enable
•
IN* ok
•
%I
%Q
%M
%T
%S
%G
%R
%AI
%AQ const
•
•
•
•
• • •
• • •
• • •
Q I1* I2* * • none
• • •
For the EXPT function, input IN is replaced by input parameters I1 and I2. Valid reference or place where power may flow through the function.
Example In the following example, the value of %AI0001, +3.000000, is raised to the power of +2.500000, and the result, +15.58846, is placed in %R0001.
| _____ |ALW_ON | | | - - ] [ - - - - - - - - - |EXPT_| - | | | | | REAL| | | | | | | | %AI0001 - |I1 Q| - %R0001 | +3.000000 | | +15.58846 | | | | | | | CONST, |I2 | | +2.500000 |_____| |
6-14
Series 90™-30/20/Micro PLC CPU Instruction Set Reference Manual – May 2002
GFK-0467M
Page 120
6
Radian Conversion
(RAD, DEG)
When the function receives power flow, the appropriate conversion (RAD_TO_DEG or DEG_TO_RAD, i.e., Radian to Degree or vice versa) is performed on the real value in input IN and the result is placed in output Q. The ok output will receive power flow unless IN is NaN (Not a Number). _____ | | (enable), | RAD_| - (ok) | | | TO_ | | | | DEG | | | (input parameter IN), |IN Q| - (output parameter Q) |_____|
Parameters Parameter
Description enable
When the function is enabled, the operation is performed.
IN
IN contains the real value to be operated on.
ok
The ok output is energized when the function is performed without overflow, unless IN is NaN.
Q
Output Q contains the converted value of IN.
Note The Radian conversion functions are only available on the 35x and 36x series CPUs, Release 9 or later, or on all releases of CPU352 and CPU37x.
Valid Memory Types Parameter flow enable
•
IN ok
•
%I
%Q
%M
%T
%S
%G
Q •
GFK-0467M
%R
%AI
%AQ const
•
•
•
•
•
•
• none
•
Valid reference or place where power may flow through the function.
Chapter 6 Math Functions
6-15
Page 121
6
Example In the following example, +1500 is converted to DEG and is placed in %R0001. | _____ |ALW_ON | | | - - ] [ - - - - - - - - - - - - - - - - - - - - - - - - - - - | RAD_| | | | | | TO_| | | | | | DEG | | CONST | | | +1500.000, |IN Q| - %R0001 | |_____| 85943.66
6-16
Series 90™-30/20/Micro PLC CPU Instruction Set Reference Manual – May 2002
GFK-0467M