Sie sind auf Seite 1von 7

Instructions with REAL Numbers

?
?

y=LN(x)

sin?
cos?
tan?
...?

SIMATIC S7
Siemens AG 2001. All rights reserved.

Date:
File:

09.01.2015
PRO2_03E.1

SITRAIN Training for


Automation and Drives

REAL Number Representation in SIMATIC S7

Representation format of a REAL number (IEEE FP 32 bit binary format):


31

30

29

28

27 26

25

24

23

22

21

20 19

18

17

16 15

14

13

12

11 10

0 1 0 0 0 0 1 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2-23

2-1
S

Exponent: e = 8 Bit

Representation of a normalized REAL number:


S x (1.f) x 2 (e-127)

Mantissa: f (23 Bits)

S = Sign bit, (0 corresponds to +, 1 corresponds to -)


f = 23 bit Mantissa with MSB = 2-1 and LSB =2-23
e = binary integer exponent (0 < e < 255)

Example:
S =0
e = 1000 0101 = 133
f = 1010 0000... = 0.5 + 0.125

R = +1.625 x 2 (133-127) = 1.625 x 64 = 104.0

Value range of normalized REAL numbers:


- 3.402 823 x 10+38 ... -1.175 494 x 10-38, 0, 1.175 494 x 10-38 ... 3.402 823 x 10+38

SIMATIC S7
Siemens AG 2001. All rights reserved.

Date:
File:

09.01.2015
PRO2_03E.2

SITRAIN Training for


Automation and Drives

Basic Instructions with REAL Numbers

REAL Addition:
L
L
+R
T

MD10
MD20
MD30

// Load 1st. REAL number


// Load 2nd. REAL number
// Subtraction of REAL numbers (MD10 - MD20)
// Transfer result into MD30

REAL Multiplication:
L
L
*R
T

MD30

// Load 1st. REAL number


// Load 2nd. REAL number
// Addition of REAL numbers (MD10 + MD20)
// Transfer result into MD30

REAL Subtraction:
L
L
-R
T

MD10
MD20

MD10
MD20
MD30

// Load 1st. REAL number


// Load 2nd. REAL number
// Multiplication of REAL numbers (MD10 * MD20)
// Transfer result into MD30

REAL Division:
L
L
/R
T

SIMATIC S7
Siemens AG 2001. All rights reserved.

MD10
MD20
MD30

// Load 1st. REAL number


// Load 2nd. REAL number
// Division of REAL numbers (MD10 / MD20)
// Transfer result into MD30

Date:
File:

09.01.2015
PRO2_03E.3

SITRAIN Training for


Automation and Drives

Extended Mathematical Functions

Mathematical Functions:
SQR
SQRT

Form the square


Calculate the square root

EXP
LN

Exponential function for Base e


Natural Logarithm
(e=2.718282)

Example:
L
SQR
T

MD10
MD30

EN
MD10

SIMATIC S7
Siemens AG 2001. All rights reserved.

IN

SQR

// Load REAL number


// Calculate the square
// Transfer result into MD30

ENO
OUT

(STL)

(LAD)
MD30

Date:
File:

09.01.2015
PRO2_03E.4

SITRAIN Training for


Automation and Drives

Trigonometric Functions and Their Inverse Functions

Trigonometric functions:
SIN
COS
TAN

Sine
Cosine
Tangent
Angle

Arc functions:
ASIN
ACOS
ATAN

Arc sine
Arc cosine
Arc tangent

Example:
L
SIN
T

MD10
MD30

EN
MD22

SIMATIC S7
Siemens AG 2001. All rights reserved.

IN

SIN

// Load REAL number


// Calculate the sine
// Transfer result into MD30

(STL)

ENO
OUT

(LAD)
MD30

Date:
File:

09.01.2015
PRO2_03E.5

SITRAIN Training for


Automation and Drives

Other Instructions with REAL Numbers

Conversion instructions from REAL to DINT:


RND+
RNDRND
TRUNC

Conversion instructions from DINT to REAL:


DTR

conversion with rounding off

Other instructions from REAL to REAL:


ABS
NEGR

with rounding off to the next larger DINT number


with rounding off to the next smaller DINT number
with rounding off to the next integer
integer component

forming the absolute amount


negation of a REAL number

Example:
L
RND+
T

MD10
MD30

EN
MD22

SIMATIC S7
Siemens AG 2001. All rights reserved.

IN

// Load REAL number


// Convert to next larger DINT number
// Transfer result into MD30

(STL)

RND+
ENO
OUT

(LAD)
MD30

Date:
File:

09.01.2015
PRO2_03E.6

SITRAIN Training for


Automation and Drives

Exercsie 3.1: Calculating the Distance


Example: Calculating the distance D between two points in
a right-angled coordinate system
Y
Y2

P2

Y1

P1

X1

Function: FC31 with D=

SIMATIC S7
Siemens AG 2001. All rights reserved.

X2
(X2 - X1)2 + (Y2 - Y1)2

Date:
File:

09.01.2015
PRO2_03E.7

SITRAIN Training for


Automation and Drives

Das könnte Ihnen auch gefallen