arithmétique step7

Upload: plcrg

Post on 02-Jun-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 arithmtique step7

    1/10

    AAPPPPLLIICCAATTIIOONNOOFFPPLLCCIINNIINNDDUUSSTTRRIIAALLAAUUTTOOMMAATTIIOONN

    Chapter VIIMath and conversion functions

    In math functions only variables with data type numeric and/or numbers (constants) are used.

    The numbers can be integer and real numbers. Integer numbers are whole binary numbers

    with a preceding sign (- or +). There are two types of integer numbers: integer INT and

    double integer DINT. Real numbers are floating-point numbers with a preceding sign (- or +).

    Real number variables are declared as data type REAL. InTable 0.1 the numerical data types,

    their range, bit number (how much memory it takes) and constant samples (how the numbers

    are written in a user program) are shown.

    Table 0.1. Integer and real numbers

    Data type INT DINT REAL

    Allowed range -32 768 to 32 768 -214 783 648 to

    +214 783 647

    1.75495e-38

    to

    3.402823e+38

    Memory range 16 bits = 1 word 32 bits = 2 words 32 bits = 2 words

    Constant samples 234-15 674

    L#25 000L#-345 764

    1.578-2345.0

    1.2e3 (1200)3.5e-2 (0.035)

    Ar ithmetic funct ions

    IEC 61131 offers the following arithmetic functions: addition (ADD), subtraction (SUB),multiplication (MUL), division (DIV), division with remainder (MOD) and exponentiation

    (EXPT).

    STEP 7 has four arithmetic functions for standard arithmetic calculations with integer (INT),

    double integer (DINT) and real (REAL) numbers and variables/operands, which are declared

    as data types INT, DINT or REAL. These are addition, subtraction, multiplication and

    division. The division with integers (DIV_I) and double integer (DIV_DI) numbers provides a

    quotient result only. However, double integer division can give out also the division

    remainder (fraction) as a result if the function MOD_DI is used for division. The integer,

    double integer and real arithmetic functions in STEP 7 are shown inTable 0.2.The arithmeticfunctions are performed only with the same data types (numbers, variables and operands) -

    input operands and output operands have to be of the same data type.

    Table 0.2. Integer and real number arithmetic functions in STEP 7

    Operation Arithmetic functions using data type

    INT DINT REALSTL FBD/ LAD STL FBD/ LAD STL FBD/ LAD

    Addition +I ADD_I +D ADD_DI +R ADD_R

    Subtraction -I SUB_I -D SUB_DI -R SUB_R

    Multiplication *I MUL_I *D MUL_DI *R MUL_R

    Division /I DIV_I /D DIV_DI /R DIV_RDivision with remainder - - MOD MOD_DI - -

  • 8/10/2019 arithmtique step7

    2/10

    AAPPPPLLIICCAATTIIOONNOOFFPPLLCCIINNIINNDDUUSSTTRRIIAALLAAUUTTOOMMAATTIIOONN

    STEP 7 uses CPU accumulators ACCU 1 and ACCU 2 for arithmetic operations. Read more

    about it in modules 4.6 and 5.1.

    Some examples of the STEP 7 arithmetic functions are shown in Fig. 0.1. An addition

    function with integer variables is shown in STL, a multiplication function with real variablesis shown in FBD and a division MOD function with double integer variables is shown in

    LAD.

    Fig. 0.1. Some samples of arithmetic functions in STL, FBD and LAD languages

    Numeric functions

    The numeric functions have only one input operand. The result is the functional value [6].

    IEC 61131 defines the following functions as numeric functions: absolute value (ABS),

    square root (SQRT), natural logarithm (LN), logarithm (LOG), exponential value (EXP), sine

    (SIN), cosine (COS), tangent (TAN), arc sine (ASIN), arc cosine (ARCOS), and arc tangent(ARTAN). IEC 61131 requires that numeric functions must have the same operand types inthe function input and output. In most numeric functions only the data type REAL can be

    used. Only exception is the absolute value function, which can use also work with data typesINT and DINT. STEP 7 has most numeric functions defined in IEC 61131 - only the

    logarithm function is missing.

    InTable 0.3 STEP 7 numeric functions in STL and FBD languages are shown. In STEP 7 all

    numerical functions use real numbers in inputs (IN) and outputs (OUT). By numeric functions

    only accumulator ACCU 1 is used. Read more about it in modules 4.6 and 5.1.

    Table 0.3. STEP 7 numeric functions

    Name STL FBD/LAD

    LN (natural logarithm)

    EXP (exponential value)

    SIN (Sine)

  • 8/10/2019 arithmtique step7

    3/10

    AAPPPPLLIICCAATTIIOONNOOFFPPLLCCIINNIINNDDUUSSTTRRIIAALLAAUUTTOOMMAATTIIOONN

    Name STL FBD/LAD

    COS (Cosine)

    TAN (Tangent)

    ASIN (Arc Sine)

    ACOS (Arc Cosine)

    ATAN (Arc Tangent)

    ABS (Absolute value)

    SQR (Square)

    SQRT (Square root)

    Function LN calculates the natural logarithm (logarithm to base e = 2.718282) of a real

    number (IN). The following equation can be used to calculate logarithm to any other base

    (Logba) if natural logarithm is used.

    .

    The logarithm to base 10 can be calculated with the following equation:

    .

    Function EXP calculates the exponential value (exponential value for base e) of a real

    number. The following equation can be used to calculate exponential to any other base (ba).

    Functions SIN, COS or TAN calculate the sine, cosine or tangent of an angle, which is givenin radian. The angle value has to be from 0 to 2 ( = 3.14). If the angle radian value is

  • 8/10/2019 arithmtique step7

    4/10

    AAPPPPLLIICCAATTIIOONNOOFFPPLLCCIINNIINNDDUUSSTTRRIIAALLAAUUTTOOMMAATTIIOONN

    greater than 2, then 2 has to be subtracted from it as long as the value becomes less than or

    equal to 2.

    Functions ASIN, ACOS or ATAN calculate the arc sine, arc cosine or arc tangent of a real

    number. The result is an angle specified in a radian measure. In the case of functions ASIN

    and ACOS, the input operand IN value must be greater than or equal to -1 and less than or

    equal to +1. InFig. 0.2 the possible values of functions ASIN, ACOS and ATAN in radian areshown.

    Function ASIN output value range:

    Function ACOS output value range:

    Function ATAN output value range:

    Fig. 0.2 Range of possible values of functions ASIN, ACOS and ATAN in radians

    Function ABS produces the absolute value of a real number, function SQR calculates the

    square of a real number and function SQRT calculates the square root of a real number. The

    function SQRT result is positive if the input operand value is greater than or equal to zero.

    Conversion functions

    Conversion functions are used to convert data from one type to another [6]. For example, an

    operand in the BCD format has to be used in arithmetic functions. Firstly, the operand data

    has to be converted into an integer or real format. After that the converted data can be used inarithmetic calculations. If the arithmetic result is needed in the BCD format, then the result

    has to be converted back to the BCD format.

    InTable 0.4 some IEC 61131 conversion functions are shown.

    Table 0.4. IEC 61131 conversion functions

    Name CommentBCD_TO_INT The BCD format value in function input is converted to the data type integer

    value.

    INT_TO_BCD The integer format value in function input is converted to the data type BCD

    value.INT_TO_REAL The integer format value in function input is converted to the real format

    value.

    REAL_TO_INT The real format value in function input is converted to the integer formatvalue. When converting the number is rounded to the nearest integer number.

    TRUNC The real format value in function input is converted to the integer formatvalue. The result is the integer component of the real number. The realnumber decimal point is deleted.

    STEP 7 conversion functions in STL, FBD and LAD languages are listed inTable 0.5.STEP7 uses only accumulator ACCU 1 for conversion functions. Read more about it in modules 4.6

    and 5.1.

  • 8/10/2019 arithmtique step7

    5/10

    AAPPPPLLIICCAATTIIOONNOOFFPPLLCCIINNIINNDDUUSSTTRRIIAALLAAUUTTOOMMAATTIIOONN

    Table 0.5. STEP 7 conversion functions

    Name STL FBD/LAD CommentBCD_TO_INT BTI BCD_I BCD value is converted to 16 bit integer

    value.

    BCD_TO_DINT BTD BCD_DI BCD value is converted to 32 bit (double)integer value.

    INT_TO_BCD ITB I_BCD 16 bit integer value is converted to the BCDvalue.

    INT_TO_DINT ITD I_DI 16 bit integer value is converted to 32 bit(double) integer value.

    DINT_TO_BCD DTB DI_BCD 32 bit (double) integer value is converted tothe BCD value.

    DINT_TO_REAL DTR DI_R 32 bit (double) integer value is converted to a

    real value.REAL_TO_INT RND ROUND Real value is rounded to 32 bit (double)

    integer value.

    RND+ CEIL Real value is rounded to 32 bit (double)integer value, which is greater than or equalto the specified real number.

    RND- FLOOR Real value is rounded to 32 bit (double)

    integer value, which is less than or equal tothe specified real number.

    TRUNC TRUNC Real value is truncate to 32 bit (double)

    integer value. The result is the integercomponent of the real number.

    INVI INVI INV_I Ones Complement integer (16 bit).INVD INVD INV_DI Ones Complement double integer (32 bit).

    NEGI NEGI NEG_I Twos Complement integer (16 bit).

    NEGD NEGD NEG_DI Twos Complement double integer (32 bit).

    NEGR NEGR NEG_R Real value is negated.

    Conversion of BCD values

    BCD values are converted to integer or to double integer values by using BCD_TO_INT or

    BCD_TO_DINT functions (Table 0.5). Only BCD values with 3 (integer) or 7 (doubleinteger) decades are converted (Fig. 0.3). The BCD value preceding sign is stored in bit 15 or

    in 31 (0 for positive, 1 for negative). An error can occur in the BCD conversion if in one

    of the BCD decade has a number from 10 to 15. With this error the PLC can go to the STOP

    mode.

    0000 0000 0010 0011

    31 16 15 0

    320+

    BCD_TO_DINT

    0000

    +235721

    0000 0000 0011

    0101 1000 0010

    1001 1000 1100 1001

    0001

    275 1BCD

    INT

    Bit

    MD 24 (ACCU 1)

    MD 28 (ACCU 1)

    Fig. 0.3. BCD value conversion to double integer

  • 8/10/2019 arithmtique step7

    6/10

    AAPPPPLLIICCAATTIIOONNOOFFPPLLCCIINNIINNDDUUSSTTRRIIAALLAAUUTTOOMMAATTIIOONN

    Some samples of the STEP 7 BCD value conversion functions are shown inFig. 0.4.In STL

    and FBD language BCD_TO_INT function and in LAD a BCD_TO_DINT function is shown.

    Fig. 0.4 Some samples of BCD value conversion in STL, FBD and LAD languages

    Conversion of integer and double integer values

    Integer and double integer values can be converted to integer, double integer, real and BCDvalues by using INT_TO_BCD, INT_TO_DINT, DINT_TO_BCD, DINT_TO_INT and

    DINT_TO_REAL functions (Table 0.5).

    Functions INT_TO_BCD and DINT_TO_BCD are used to convert integer and double integervalues into BCD values (Fig. 0.5). The (double) integer value preceding sign is stored from

    bit 12 to 15 (by double integer the bits are 28 to 31) (0 = positive, 1 = negative). If the

    integer value is greater than 999 or less than -999, then the integer value conversion to BCD

    value is not carried out. The same thing happens with double integer value, which is greater

    than 9999999 or less than -9999999.

    By INT_TO_DINT function integer value is converted to the double integer value. The first

    15 bits of integer are transferred straight to the first 15 bits of double integer (Fig. 0.6). The

    last bit (15) of integer value is also transferred to double integer, from bit 15 upwards up to bit31. For converting the double integer value to the integer value transfer functions (MOVE)

    have to be used in STEP 7. If the double integer value exceeds the integer value limits, then a

    random number is given as an integer value.

    1111 1110 1111 0111

    15 8 7 0

    562-

    INT_TO_BCD

    1111

    -265INT

    BCD

    Bit

    MW 32 (ACCU 1)

    MW 34 (ACCU 1) 0010 0110 0101

    Fig. 0.5. Integer value conversion to BCD

  • 8/10/2019 arithmtique step7

    7/10

    AAPPPPLLIICCAATTIIOONNOOFFPPLLCCIINNIINNDDUUSSTTRRIIAALLAAUUTTOOMMAATTIIOONN

    In the DINT_TO_REAL function the double integer value is converted to a real value with

    the data type REAL (Fig. 0.6).

    Some samples of the STEP 7 integer and double integer value conversion functions are shownin Fig. 0.7. An INT_TO_BCD function is shown in STL, an INT_TO_DINT function is

    shown in FBD and a DINT_TO_REAL function shown in LAD.

    Fig. 0.7. Some samples of integer and double integer value conversion in STL, FBD and LAD languages

    Conversion of real valuesSTEP 7 offers 4 functions to convert real values to double integer. These 4 conversion

    functions differ in the execution of rounding.

    The ROUNDfunction (RND) rounds the result to the nearest whole number. If the fractional

    part of the converted number is midway between an even and an odd result, then the function

    chooses the even result (Fig. 0.8)[6].

    31 16 15 0

    -16533

    INT_TO_DINT

    1111

    -16533

    1111 1111 1111

    1011 1111 0110

    1011 1111 0110 1011

    1011

    INT

    DINT

    BitMW 44 (ACCU 1)

    MD 46 (ACCU 1)

    15 0

    Bit

    0000 0000 0000 0000

    31 16 15 0

    0.953125135+

    DINT_TO_REAL

    500

    0011 1010

    0000 0001 1111

    0000 0000 0000 0000

    0100

    DINT

    REAL

    Bit

    MD 50 (ACCU 1)

    MD 54 (ACCU 1) 1000 1111

    31 22 1615 0Bit

    500.0

    E = 27 + 22 + 21 + 20 = 135

    M = 2-

    +2-

    +2-

    +2-

    +2-

    == 0.953125

    REAL = +1.953125 * 2135-127

    =

    =500.0

    Fig. 0.6. Integer conversion to double integer and double integer conversion to real

  • 8/10/2019 arithmtique step7

    8/10

  • 8/10/2019 arithmtique step7

    9/10

    AAPPPPLLIICCAATTIIOONNOOFFPPLLCCIINNIINNDDUUSSTTRRIIAALLAAUUTTOOMMAATTIIOONN

    function NOT. The formation of Twos Complements is done with a multiplication with -1

    [6]. These functions are not included in IEC 61131. Both complementations exist in STEP 7

    STL, FBD and LAD languages as inversion and negation functions.

    Ones Complement (INVI, INVD) function inverts the (double) integer value bit by bit, that is,0 is replaced by 1 and 1 is replaced by 0 (Fig. 0.10). In the INVI function only the

    first 16 bits of ACCU 1 are inverted.

    The Twos Complement function (NEGI, NEGD) of (double) integer value is performed in

    two steps. In the first step the integer value bits are inverted (Ones Complement is created). In

    the second step +1 is added to the inverted value (Fig. 0.11). In NEG_INT functions only the

    first 16 bits of ACCU 1 are used by the Twos Complement creation.

    The real Twos Complement creation (NEGR) negates the real value. Only the bit 31(sign ofthe mantissa) is inverted with this function.

    Some samples of the STEP 7 Ones and Twos Complement functions are shown inFig. 0.12.

    An Ones Complement function with integer variables is shown in STL, a Twos Complement

    function with double integer values is shown in FBD and a Twos Complement function with

    real variables is shown in LAD.

    Fig. 0.12. Some samples of Ones and Twos Complement conversion in STL, FBD and LAD languages

    0000 0000 0000 0011

    31 16 15 0

    INVD

    1111

    -235722

    1111 1111 1100

    1001 1000 1100

    0110 0111 0011 0110

    1001

    1DINT

    DINT

    Bit

    MD 86 (ACCU 1)

    MD 90 (ACCU 1)

    +235721

    1111 1111 1110 1010

    31 16 15 0

    NEGD

    0000

    +1407009

    0000 0001 0101

    1000 0111 1101

    0111 1000 0010 0001

    1111

    1DINT

    DINT

    Bit

    MD 98 (ACCU 1)

    MD 102 (ACCU 1)

    -1407009

    Fig. 0.10. Ones Complement creation of double integer value

    Fig. 0.11. Twos Complement creation of double integer value

  • 8/10/2019 arithmtique step7

    10/10

    AAPPPPLLIICCAATTIIOONNOOFFPPLLCCIINNIINNDDUUSSTTRRIIAALLAAUUTTOOMMAATTIIOONN

    Conversion of BYTE, WORD and DWORD

    STEP 7 transfer functions (MOVE) can be used for conversion of data types BYTE, WORDand DWORD into other data types like BYTE, WORD, INTE, DWORD, DINT etc. in STL,

    FBD and LAD languages. Sometimes, when the input value exceeds the output value limits, itcan happen that a random number is given as the output in the transfer function.

    Self check

    1.

    Which is the allowed range of data type DINT (double integer)?

    a. -32 768 to 32 768

    b. -214 783 648 to +214 783 647

    c. 1.75495e-38 to 3.402823e+38

    2.

    Which of the following functions cannot be performed with integer numbers(multiple answers)?

    a. Additionb. Multiplication

    c. Division with remainderd. Sine

    e. Squaref.

    Absolute value

    3. Which of these numeric functions is not possible in STEP 7 (multiple answers)?

    a. Tangent

    b. Cotangent

    c.

    Arc Tangentd. Arc Cotangent

    4. How is the output of function ACOS given?

    a. In degreesb.

    In radians

    c. As a real number

    5.

    Which of the following functions can be used in STEP 7 to convert a double integer

    value to an integer value?

    a.

    DINT_TO_INT

    b. INT_TO_DINT

    c.

    BCD_TO_INTd. MOVE

    6. The result of the TRUNC function is

    a. the integer number part of the real number.

    b. the largest whole number, which is smaller than or equal to the real number.c. the nearest whole number.

    d. the smallest whole number, which is greater than or equal to the real number.

    7. Once Complementation allows one to

    a. convert floating point numbers to the BCD code.

    b. invert integer numbers.

    c. negate integer numbers.

    d.

    invert real numbers.