Siemens SIMATIC S7-200 System Manual page 115

Programmable controller
Hide thumbs Also See for SIMATIC S7-200:
Table of Contents

Advertisement

Operation of the Round and Truncate Instructions
The Round instruction (ROUND) converts the real-number
value IN to a double integer value and places the result into
the variable specified by OUT. If the fraction portion is 0.5 or
greater, the number is rounded up.
The Truncate instruction (TRUNC) converts a real-number
value IN into a double integer and places the result into the
variable specified by OUT. Only the whole number portion of
the real number is converted, and the fraction is discarded.
If the value that you are converting is not a valid real number or is too large to be represented in
the output, then the overflow bit is set and the output is not affected.
Example: Standard Conversion Instructions
Double Word Integer to Real and Round
C10
101
VD0
101.0
VD4
2.54
VD8
256.54
VD12
257
Network 1
LD
ITD
DTR
MOVR
*R
ROUND VD8, VD12
Network 2
LD
BCDI
Count = 101 inches
Count (as a real number)
2.54 constant (inches to centimeters)
256.54 centimeters as real number
257 centimeters as double integer
S7-200 Instruction Set
Error conditions that set ENO = 0
H SM1.1 (overflow)
H 0006 (indirect address)
SM bits affected:
H SM1.1 (overflow)
//Convert inches to centimeters:
//1. Load a counter value (inches) into AC1.
//2. Convert the value to a real number.
//3. Multiply by 2.54 (convert to centimeters).
//4. Convert the value back to an integer.
I0.0
C10, AC1
AC1, VD0
VD0, VD8
VD4, VD8
//Convert a BCD value to an integer
I0.3
AC0
Chapter 6
BCD to Integer
AC0
1234
BCDI
AC0
04D2
101

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents