ICS Regent+Plus ® PD-7043 Math Package for W INTERPRET Floating Point Math Function Block (T7833) Issue 1, March, 06 The Math package for WINTERPRET is an add-in software package which allows the user to create Floating Point Math function blocks for Regent application programs. When installed on the PC, the math package is seamlessly integrated with the base WINTERPRET software.
Math Package for W INTERPRET (T7833) 1. Insert the WINTERPRET base package distribution disk into drive A: or B: 2. Start Windows (if it isn’t already running). 3. Choose Run from the Program Manager’s File menu. 4. Type a:\setup.exe in the text box. (if you inserted the WINTERPRET base package disk in drive B: type b:\setup.exe.) Choose OK or press ENTER. 5.
Math Package for W INTERPRET (T7833) Using Floating Point Math Statements In floating point math function blocks you enter mathematical equations and expressions in the form of statements. Each line can contain one statement that calculates the result of a mathematical equation. For example, consider the quadratic equation below. y = 1.6x2 +8x -22.4 Using floating point math the statement representing this equation would be: Y = 1.6*X^2 + 8*X - 22.
Math Package for W INTERPRET (T7833) Arithmetic Operations Table 1 shows the arithmetic operators recognized by floating point math listed in their default order of precedence. Table 1. Arithmetic Operators. Operator Operation ^ Exponentiation * Multiplication / Division + Addition - Subtraction Note: Multiplication and division have equal precedence from left to right, as do addition and subtraction.
Math Package for W INTERPRET (T7833) ROOT1 = (-B + SQRT(B^2 - 4*A*C)) / (2*A) Note: The exponentiation operator (Y^X) can only raise Y to an integer power X. If you need to calculate YX for non-integer values of X you can use the LN(X) and EXP(X) functions as shown below. Y_2_THE_X = EXP(X*LN(Y)) Conditional Statements The statements available in the floating point math let you alter program flow based on testing of conditions.
Math Package for W INTERPRET (T7833) • • ENDW If the expression is true (not zero), loop statements are executed until the ENDW statement is encountered. Floating point math then returns to the WHILE statement and checks expression. If expression is still true, the process is repeated. If the expression is not true, execution resumes with the statement following the ENDW statement.
Math Package for W INTERPRET (T7833) Logical Operators Logical operators perform logical, or boolean, operations on numeric values. Just as the relational operators are usually used to make decisions regarding program flow, logical operators are used to connect two or more relations and return a true or false value to be used in a decision. A logical operator takes a combination of true/false values and returns a true or false result.
Math Package for W INTERPRET (T7833) Integer Constants Integer constants are constants entered as whole numbers that do not contain decimal points or commas. Entering an integer constant greater than 7 numerals long is allowed but the precision of the actual number stored and used in the Regent is limited to 7 significant digits. For example, the integer constants 12345678 and 12345679 may result in an equal values when converted and stored in the Regent.
Math Package for W INTERPRET (T7833) application program in the Regent. This will prevent the program from being loaded into the Regent. For more information about Regent variable types, see Regent Variable Types and Memory, in Section 4, Working with Projects, in the Regent User’s Guide. Floating point math function blocks recognize the following variable types: Logical Variables Logical variables are used for digital output, shared control relays, and local control relays.
Math Package for W INTERPRET (T7833) Table 5. Conversion Rules. Logical to analog False to 0, true to 1. Logical to integer False to 0, true to 1. Logical to floating point False to 0.0, true to 1.0 Analog to logical 0 to false, otherwise true. Analog to integer Valid for all analog values. Analog to floating point Valid for all analog values. Integer to logical 0 to false, otherwise true. Integer to analog Valid for all integers between 0 and 4095 (-16384 to +16384 for T/C and RTD inputs).
Math Package for W INTERPRET (T7833) A = SQRT (B) During execution in the Regent, the value of B may change from one scan cycle to the next. Table 6 illustrates the values of B the result stored in A for a series of scan cycles to illustrate the effects of a math error (square root of a negative number). Table 6. Example of Math Error and Result Values. Scan B SQRT(B) Result, A 1 25 5 5 2 16 4 4 3 2 1.414213 1.414213 4 -7 1.
Math Package for W INTERPRET (T7833) Table 7. Error Codes. Error Code Description Example 1 Underflow C = A / B; |A/B| < 1.175494E-38 2 Overflow C = A * B; A * B > 3.402823E38 C = A/B; B = 0 3 Not a number C = SQRT A; A < 0 4 Conversion AO = 3000 + 2000 (where AO is an analog output) In most floating point equations, the results do not approach the error limits of floating point math.
Math Package for W INTERPRET (T7833) Table 9 shows a general example of how the error variables can be used in a floating point function block to check for error conditions and conditionally execute alternate equations that calculate a more appropriate result than leaving the value at its last valid value.
Math Package for W INTERPRET (T7833) The Regent does not reset the values of the line number and error code variables when no more math errors are present. When the error condition ceases, these variables contain the values for the last error. You should include equations to reset the error variables (as shown in lines 1 and 2 in Table 9. Otherwise, once an equation generates an error, the test for error will remain true for that equation until a different line number generates a math error.
Math Package for W INTERPRET (T7833) The floating point math editor allows you to create up to 6500 lines in a single function block. The size of each compiled function block is limited to 64 kbytes of code which provides up to 1300 lines which contain floating point math statements (a simple statement like A = 1 occupies approximately 50 bytes). Statement Lines Each line of the function block may contain up to 72 characters that form a floating point math statement.
Math Package for W INTERPRET (T7833) Figure 2. Example of the Floating Point Math Editor Window. File Menu The File Menu gives you access to the standard function block file commands which include: Save Function Block, Revert to Last Saved, Compile, View Error Messages, Edit Function Block Description, Edit Function Block Details, Print Function Block, Print Setup, Log Off and Exit.
Math Package for W INTERPRET (T7833) Click and drag the mouse to select the desired text to cut. Choose Cut from the Edit Menu to remove the selected text. Copy The Copy command can be used to copy the currently selected text to the Windows clipboard. Copied text can later be inserted into the function block using the Paste command. Click and drag the mouse to select the desired text to copy. Choose Copy from the Edit Menu to copy the selected text to the clipboard.
Math Package for W INTERPRET (T7833) Figure 3. Floating Point Math Error Variables. Line number variable Enter the tag name for the line number variable. The variable is used to report line numbers that generate math errors if they occur during execution in the Regent. Error code variable Enter the tag name for the error code variable. The variable is used to report the error code for math errors if they occur during execution in the Regent.
Math Package for W INTERPRET (T7833) Go Choose Go to move to the line number that you entered in the Line Number text box. First Go to the first line in the function block. Last Go to the last line in the function block. Find The Find command lets you quickly locate text strings in the floating point math function block. For example, you can search for a tag name and have the editor locate the line of the function block where the tag name is used.
Math Package for W INTERPRET (T7833) Window Menu The Window menu commands are standard throughout all WINTERPRET windows. For more information on using the Window menu commands see Commands Common to all WINTERPRET Windows in Section 3, Installing the WINTERPRET Application of the Regent User’s Guide. Help Menu The Help menu commands are standard throughout all WINTERPRET windows.
Math Package for W INTERPRET (T7833) Normally you will use the Floating Point Math Monitor Window to observe results of the floating point math calculations. You can also select a single line and display the values of all the variables used in the selected line. File Menu The File Menu provides access to several commands common to all function block monitors. These include View Function Block Details, View Function Block Description, Log Off and Exit.
Math Package for W INTERPRET (T7833) Figure 7. Floating Point Math: Line Details Dialog. Search Menu The Search Menu provides commands to locate information in floating point math function block. You can choose Go to Line (to move to a particular line number), Find (to search for test strings) or Find Next (to repeat the last Find selection). More details about each of these commands are described on Page 18. Window Menu The Window menu commands are standard throughout all WINTERPRET windows.
Math Package for W INTERPRET (T7833) Typical Equation Sizes and Execution Speeds The following information may be used for estimating the size and increasing the efficiency of floating point equations. This is only a guideline. Execution speeds and memory size requirements will vary for each equation according to the general rules shown below.
Math Package for W INTERPRET (T7833) Local and Floating point 1.0 Constant 1.2 Shared register 1.5 Analog 1.8 Bit-type 2.5 The maximum and minimum code sizes for each operation listed in Table 10 are approximate and will vary according to use in an equation. Code sizes are shown in bytes. These numbers should be used only to estimate the size of a function block.
Math Package for W INTERPRET (T7833) function block, and will vary according to type of data used and the complexity of the equation. Table 11. Execution Speeds. Format Minimum Speed (msec.) Add + 63 Subtract - 87 Multiply * 56 Divide / 56 LOG(x) 45 Natural Log LN(x) 62 Square root SQRT(x) 45 X^Y 90 EXP(x) 1845 = 15 Operation Logarithm Exponentiation e raised to the X Equality There are two general rules for creating the most efficient floating point equations: 1.
Math Package for W INTERPRET (T7833) 26 Industrial Control Services