Case 2 of analog temperature measurement based on Siemens 1200PLC

 

03
Conversion of analog and digital quantities

In actual engineering projects, readers often collect signals such as temperature, pressure, flow, etc., so how to deal with these analog signals in the program? In other words, what is the purpose of writing an analog program? The purpose of writing an analog program is to convert the analog quantity into a corresponding digital quantity, and finally convert the digital quantity into an engineering quantity (physical quantity).

There are two types of conversion of analog quantity to engineering quantity: unipolar and bipolar . The bipolar -27648 corresponds to the minimum value of the engineering quantity, and 27648 corresponds to the maximum value of the engineering quantity.

There are two types of unipolar analog, namely 4-20mA and 0-10V , 0-20mA .

( 1 ) The first type is 4-20mA, with offset.

Because 4mA is 20% of the total , and 20mA is converted to a digital quantity of 27648 , so the digital quantity corresponding to 4mA is 5530 . The conversion of analog quantity to digital quantity is completed by S7-1200PLC , and the reader needs to convert these values ​​into engineering quantities in the program.

( 2 ) The second type has no offset

The ones without offset are analog quantities such as 0-10V , 0-20mA, etc., 27648 corresponds to the maximum engineering quantity, and 0 corresponds to the minimum value of the engineering quantity.

( 3 ) The analog signal ( 0-10V , 0-5V or 0-20mA ) is represented by the value of 0-27648 inside the S7-1200PLC CPU ( 4-20mA corresponds to 5530-27648 ), there is a certain difference between the two Mathematical relationship, as shown in Figure 3-5-5

Figure 3-5-5 Analog signal and digital curve

04Standardized
instructions and scaling instructions

(1) Standardization instruction (NORM_X)

NORM_X instruction: Using the "NORM_X" instruction, the value of the variable in the input VALUE can be mapped to a linear scale to standardize it. Use the parameters MIN and MAX to define the limits of the input VALUE value range:

LAD

parameter

type of data

illustrate

IN

BOOL

allow input

ENO

BOOL

allow output

MIN

Integer, floating point

The lower limit of the value range

VALUE

Integer, floating point

the value to normalize

MAX

Integer, floating point

The upper limit of the value range

OUT

floating point number

standardized results

Note: You can select the data type of the instruction from the drop-down list of the instruction box "<???>".

The calculation formula of standardized instructions is: OUT= (VALUE - MIN) / (MAX - MIN), where (0.0 <= OUT <= 1.0), the calculation principle is shown in Figure 3-5-6

Figure 3-5-6 Schematic diagram of calculation corresponding to standardized instruction formula

Use an example to illustrate the use of standardized instructions (NORM_X), the ladder diagram is shown in Figure 3-5-7:

When I0.0 is closed to activate the standardization command, the VALUE to be standardized is stored in MW10, the range of VALUE is 0-27648, and the output range of normalized VALUE is 0.0-1.0. Assuming MW10 is 13824, then the normalized result in MD12 is 0.5.

Figure 3-5-7 Example of standardized instructions

(2) Scale instruction (SCALE_X)

SCALE_X instruction: Using the "SCALE_X" instruction, the value of the input VALUE can be mapped to the specified value range to scale it. When the scaling command is executed, the floating-point value of the input VALUE is scaled to the range of values ​​defined by the parameters MIN and MAX. The scaling result is an integer, stored in the OUT output. Refer to the table below for scaling command parameters:

LAD

parameter

type of data

illustrate

IN

BOOL

allow input

ENO

BOOL

allow output

MIN

Integer, floating point

The lower limit of the value range

VALUE

Integer, floating point

the value to normalize

MAX

Integer, floating point

The upper limit of the value range

OUT

floating point number

standardized results

Note: You can select the data type of the instruction from the drop-down list of the instruction box "<???>".

The calculation formula of scaling command is: OUT= VALUE (MAX - MIN) + MIN, where (0.0 <= VALUE <= 1.0), the calculation principle is shown in Figure 3-5-8;

Use an example to illustrate the use of the standardized instruction (NORM_X), the ladder diagram is shown in Figure 3-5-8, when I0.0 is closed to activate the standardized instruction, the VALUE to be standardized is stored in MD16, and the range of VALUE is 0-27648 , the normalized output range of VALUE is 0-27648. Assuming 0.5 in MD10, the normalized result in MW20 is 13824.

Figure 3-5-8 Zoom command example
4. Task implementation

The implementation steps of this task are mainly divided into PLC wiring, IO address allocation and program design ideas:

01
IO address allocation

enter address

illustrate

temperature display address

illustrate

IW64

analog input

MD24

temperature display

02
Program Design Ideas

1) Use the standardization command to standardize the collected analog value, and the standardized range value is between 0.0-1.0.

2) Then use the scaling command to scale the standardized value, and the scaled range value is within the range of the temperature sensor range (-50.0-200.0°C).

03
Program design


V. Experience and Summary

1. The conversion of analog quantities is mainly to understand the relationship between analog quantities and digital quantities.

2. In this task, standardization and scaling commands are mainly used for analog quantity acquisition and conversion. When converting, pay attention to filling in digital quantities and engineering quantities to avoid conversion errors.

3. In the above example, the range of the temperature sensor is -50°C-200°C, so it is necessary to fill in the correct value in the scaling command.

4. If there are multiple temperature sensors on site, it is more convenient to use the subroutine with parameters to write.

5. If the on-site sensor is a 4-20mA current output, then the value filled in the MIN pin in the standardized instruction should be 5530 instead of 0.

Guess you like

Origin blog.csdn.net/m0_73687141/article/details/127968270