How is numerical integration programmed in S7-SCL and STEP 7?
The integral is the mathematical calculation of the area under a given function curve. However, there is often no mathematical correlation in practice, but rather an analog value which varies over time. The integral calculation involving totaling the trapezoidal areas, spread between the last two function values and the time. This trapezoidal area is identical to the product of the average of the two process values and the time interval.
Fig. 01 illustrates the calculation of the integral of a trapezoidal area:
- Calculation: 0.5*(F(t1)+F(t0))*(t1-t0) + 0.5*(F(t2)+F(t1))*(t2-t1) + ...
The table below contains some sample programs for calculating integrals. Copy the EXE files into a separate folder and then start the files with a double-click. The STEP 7 projects are then extracted automatically with all the associated subfolders. You can then use the SIMATIC Manager to open and process the extracted projects.
|No.||Sample programs / Downloads|
|1||Integral calculation with STEP 7|
The "I_STEP7.exe" download contains an FB1 function block with the STEP 7 program for calculating the integral. OB1's current cycle time is applied here. In the case of slower processes, you simply need to supply the time input with a timer or to call the FB in another OB. The slow changing output from a heating system represents a slow process here. In this case, the integral is the energy consumption in J (joules) or KWh.
FB1 is started with the input "start" and is reset to the value zero. If the last value has to continue to be available after recording, the "EN" input in the FB1 must be disabled in OB1. The data is retained in the instance data block.
I_STEP7.exe ( 97 KB )
|2||Integral calculation with S7-SCL|
The "I_SCL.exe" download contains the S7-SCL "Integral_SCL" source with the (FB1) program for calculating the integral. There are two examples programmed in the STEP 7 project.
I_SCL.exe ( 123 KB )
In example 1 (Fig. 02) an analog input value (EW0 on the "IN" parameter) is converted to a floating-point value with the SCALE function and is transferred to MD4 via the "OUT" parameter. The transfer of the floating-point value to the integrator takes place when the MD4 is parameterized on the "IN" parameter of the FB1. The calculation of the integral is started with the flag M0.1 on FB1's "Enable" parameter.
Fig. 03 illustrates the example of a cascade. The flags M0.0 and M0.1 at the inputs of the "Integral" function block serve to start and stop the calculation of the integral for the input value in MD0 on FB1's "IN" parameter. The calculated integral value is saved in its instance DB under the address DB1.DBD6 (DB1.OUT). The values between DB1.OUT and a specified constant from MD8 (Constant) are compared in the "CMP>R" floating-point number comparator. If the value from DB1.OUT is greater than the value of the constant, the value from DB1.DBD6 is added to MD4 (Output).
|3||S7-SCL source: "Integral_SCL_B"|
The "I_SCL_B.exe" download also contains the FB1 block described above, whereby this S7 program only contains the "Integral_SCL_B" source, the compiled FB1 function block and the associated "TIME_TCK" system function. After dearchiving, the S7 program is saved in the STEP 7 library.
I_SCL_B.exe ( 95 KB )
Runnability and test environment:
The examples can be used on all the CPU types of SIMATIC S7-300 and S7-400. The following table lists the components that have been used to create this entry and verify the functions described:
|PC platform||Intel(R) Pentium(R) 4 CPU, 2.40 GHz|
|PC operating system||Windows XP SP2|
|STEP 7||V5.3 SP3|
Consumption measurement, Flow-rate measurement