Escolar Documentos
Profissional Documentos
Cultura Documentos
April 2005
Topic: Product Information / Automation System / Simatic Industrial Automation System / PLC
/ SIMATIC S7 / S7-200
Subject/Title: How to implement a scale conversion of an analogical signal in a S7-200?
Validity for Product/Version: MicroWin 4.0
Date: 10/08/2007
Motivation/Benefit:
The technical formation of the automation professionals in the third world is not the best. This effect
is particularly noted in simplest automation systems, like Logo or S7-200. We, from the technical
support in Brazil, become frequently question about how to implement a scale conversion of an
analogical signal in the S7-200. Thinking in to make this ground question lighter to us customer, I
wrote this FAQ, with explanations about the theme, and principally, a library that does the task for
the customer.
I hope that you appreciate it.
FAQ Text
How to implement a scale conversion of an analogical signal in a S7-200?
Frequently, in the automation tasks, an analogical signal (e.g. 0 to 10 V or 4 to 20 mA) must be
represented (in HMI or in the controller itself) in different scales to represents physical units. This
FAQ explain how to implement unit conversion and provides a library to implement it.
A S7-200 can operate with analogical signals through specific inputs of some CPU or due analog
modules. The type of measurement depends of the module, but a grate spectrum is covered in total:
Voltage:
0 to 50 mV
0 to 80 mV
0 to 100 mV
0 to 500mV
0 to 1 V
0 to 5 V
0 to 10 V
-25 mV to +25 mV
-50 mV to +50 mV
-100 mV to +100 mV
-250 mV to +250 mV
-500 mV to +500 mV
-1 V to +1 V
-2.5 V to +2.5 V
-5 V to +5 V
-10 V to +10 V
Current:
0 to 20 m A
April 2005
To make easy the work of the programmer, the scale of the voltage and current measurements are
fixed at S7-200 controller. So, independent of the range of the measurement adopted, the point 100%
of the measurement is represented by 32 000 in the S7-200. The start of the scale is represented by 0
for unipolar scales (i.e. the scale begins at 0) or by -32 000 for bipolar scales (in this case the range
goes from -100% to 100% of the signal).
A special case is the measurement of 4 to 20 m A, where 4 m A is represented by 6 400 and 20 m A
is represented by 32 000.
So, in function of the measured type of the range (0 to 32 000, -32 000 to + 32 000 or + 6 400 to 32
000) and the desired conversion range (here designed as from LO_LIM to HI_LIM) three formulas can
be developed:
Case 1: original range from 0 to 32 000:
HI_LIM
OUT
LO_LIM
IN MIN
IN
IN MAX
April 2005
HI_LIM
OUT
LO_LIM
IN MIN
IN
IN MAX
Case 1: IN MIN = -32 000; IN MAX = +32 000 (for example, -10V to +10V)
OUT = [IN (-32000)] * (HI_LIM - LO_LIM) + LO_LIM
32 000 - (-32 000)
OUT = (IN + 32000) * (HI_LIM - LO_LIM) + LO_LIM
64 000
HI_LIM
OUT
LO_LIM
IN MIN
IN
IN MAX
At the same way for conversion of a process signal to be output in a analog module can be related by
the formulas:
Case 1: original range from 0 to 32 000:
April 2005
HI_LIM
IN
LO_LIM
OUT MIN
OUT
OUT MAX
Case 1: OUT MIN = 0; OUT MAX = +32 000 (for example, 0 to +10V)
OUT = (IN LO_LIM) * [32 000 - (0)] + 0
(HI_LIM - LO_LIM)
OUT = (IN LO_LIM) * 32 000
(HI_LIM - LO_LIM)
HI_LIM
IN
LO_LIM
OUT MAX
Case 1: OUT MIN = -32 000; OUT MAX = +32 000 (for example, -10V to
OUT = (IN LO_LIM) * [32 000 - (-32 000)] + (-32 000)
(HI_LIM - LO_LIM)
OUT = (IN LO_LIM) * 64 000 32 000
(HI_LIM - LO_LIM)
April 2005
HI_LIM
IN
LO_LIM
OUT MAX
Case 1: OUT MIN = -6 400; OUT MAX = +32 000 (for example, 4 mA to 20
OUT = (IN LO_LIM) * [32 000 (6 400)] + (6 400)
(HI_LIM - LO_LIM)
OUT = (IN LO_LIM) * 25 600 + 6 400
(HI_LIM - LO_LIM)
TIP: despite a unit conversion with integer number are possible, its recommended first convert the
integer to a float point signal.
Sample Program
[Scale.zip]
The up archive have a library and a project that bring six subroutines that implemented these
calculations:
SCALE_X_to_X: Subroutine to convert analogical inputs in bipolar format (e.g. -10V to +10V) to a
float point in a configurable scale.
SCALE_0_to_X: Subroutine to convert analogical inputs in unipolar format (e.g. 0V to +10V) to a float
point in a configurable scale.
SCALE_4_to_20mA:: Subroutine to convert analogical inputs in 4 mA to 20 mA format to a float point
in a configurable scale.
UNSCALE_X_to_X: Subroutine to convert a float point variable, with a configurable scale, to an
analogical output in bipolar format (e.g. -10V to +10V).
UNSCALE_0_to_X: Subroutine to convert a float point variable, with a configurable scale, to an
analogical output in unipolar format (e.g. 0V to +10V).
April 2005
Declaration
Input
Data type
BOOL
Memory area
I,Q,M,V,L
IN
Input
INT
I,Q,M,V,L,P,
Constant
HI_LIM
Input
REAL
LO_LIM
Input
REAL
OUT
Output
REAL
I,Q,M,V,L,P,
Constant
I,Q,M,V,L,P,
Constant
I,Q,M,V,L,P
Description
Enable input with signal state of 1
activates the box.
The input value to be scaled to a real
value in engineering units.
Upper limit in engineering units.
Lower limit in engineering units.
Result of the scale conversion.
Declaration
Input
Data type
BOOL
Memory area
I,Q,M,V,L
IN
Input
REAL
HI_LIM
Input
REAL
LO_LIM
Input
REAL
OUT
Output
INT
I,Q,M,V,L,P,
Constant
I,Q,M,V,L,P,
Constant
I,Q,M,V,L,P,
Constant
I,Q,M,V,L,P
Description
Enable input with signal state of 1
activates the box.
input value to be unscaled to an integer
value.
Upper limit in engineering units.
Lower limit in engineering units.
Result of the unscale conversion
Note: To avoid zero division, the UNSCALE subroutines dont uses the formula to convert a signal if
HI_LIM is equal to LO_LIM. In this case, the LO_LIM is followed to OUT. However these subroutines
do not any other type of limitation of values or the plausibility check.
Each subroutine was used in a different network to show how then can be used:
April 2005
April 2005
Important:
The sample program is freeware. Any user can use copy and forward this program FREE OF
CHARGE. The authors and owners of this program take no responsibility whatsoever for the
functionality and compatibility of this software. Use of the software is entirely at the user's own risk.
Since this software is free of charge, there is no warranty, nor claim for error correction and hotline
support.