How can you scale analog values with S7-200 in conjunction with CPU224XP and expansion modules EM 231, EM 232 and EM 235?
Analog input and output values of the expansion modules EM 231, EM 232 and EM 235, as well as of CPU 224XP are displayed digitally in the INTEGER data word format. It is necessary to make conversions to ensure correct interpretation and processing. These conversions are explained using the download attached. The download contains both the "Scale" library with conversion functions and the sample program "Tip038" for better understanding.
The following diagrams show how the input and output values are scaled.
The terms "unipolar", "bipolar" and "20% offset" are explained here. These are important for, among others, the STEP 7 Micro/Win - Instruction Wizard PID (Tools > Instruction Wizard > PID Controller).
Unipolar scaling is done only in the positive or negative value range (Fig. 01 shows an example for an analog input value of between 0 and 32000).
In the case of unipolar scaling with a 20% offset, the lower limit of the value range is 20% of the upper limit (Fig. 02 shows an example for an analog input value of between 6400 and 32000).
Bipolar scaling is done in the positive and negative value range (Fig. 03 shows an example for an analog input value of between -32000 and 32000).
The following table explains the abbreviations used:
|Ov||Scaled output value (Output value)|
|Iv||Analog input value (Input value)|
|Osh||Upper scale limit for the scaled output value (Output scale high)|
|Osl||Lower scale limit for the scaled output value (Output scale low)|
|Ish||Upper scale limit for the scaled input value (Input scale high)|
|Isl||Lower scale limit for the scaled input value (Input scale low)|
The following formula is derived from the diagram for calculating the scaled value:
Ov = (Osh - Osl) / (Ish - Isl) * (Iv - Isl) + Osl
3.1 Description of the "Scale" library
The "scale.mwl" library contains the function blocks for converting the scaling from data type INTEGER to REAL (S_ITR), from REAL to REAL (S_RTR) and from REAL to INTEGER (S_RTI).
3.2 Scaling the analog input in the output data format REAL (S_ITR)
The S_ITR function permits you to convert the analog input signal into a normalized value between 0.0 and 1.0 (type REAL).
3.3 Scaling change to the data type format REAL (S_RTR)
The S_RTR function permits you to convert value ranges within the REAL format (e.g., convert the input value between 0.0 and 1.0 to the output range in percent).
3.4 Converting to the analog output scaling format INTEGER (S_RTI)
The S_RTI function converts a REAL number to the analog output data type INTEGER.
4. Sample program
4.1 Description of the sample program "Tip038"
There is a liquid in a closed container.
The differential pressure measuring transducer provides a current (4 - 20 mA) at the input of the analog input module. The current is proportional to the fill level in the container.
The analog module EM 235 must be calibrated so that the analog value of 20 mA is converted into the digital value of 32000 at a fill level of 10 m. At a fill level of 0 m the analog value of 4 mA is converted into the value 6400. The program scales the converted digital values as height in meters.
The voltage for the fill level indicator must be produced via the analog output module. This voltage is generated by writing the corresponding digital value to the analog output word (AQW).
The analog output module transfers the fill level height (between 0 m and 10 m) to a measuring instrument in the form of a voltage of between 0 V and 10 V. The analog display of the measuring instrument reacts to the voltage with needle deflection proportional to the fill level.
The formula scales every value between a maximum and minimum scaling value. This program receives the analog input value (AIW) and scales it for the analog output module. First the program reads the AIW, a value between 4 mA and 20 mA (6400 and 32000), and scales the value to a normalized value between 0.0 and 1.0 (see Fig. 05). This value is then scaled for the ranges of 0.0 to 100.0 (see Fig. 06) and 0 to 32000 (see Fig. 07).
4.2 The STEP 7 Micro/WIN library as zip file
Copy the "scale.zip" file to a separate directory and extract the file. You can then integrate the "scale.mwl" library and the sample program "Tip038_D.mwp", which can be used in version 126.96.36.199 and higher of STEP 7 Micro/WIN, into your S7-200 project. The "scale.zip" file contains the library "scale.mwl" and the sample program in German ("Tip038_D.mwp") and in English ("Tip038_E.mwp").
- This program is also part of the SIMATIC S7-200 Programming Tips 08/03 ("Tip038")
Entry ID: 1232912
- Information on inserting libraries in STEP 7 Micro/WIN is available in
Entry ID: 16689345
scale.zip ( 20 KB )