At the end of the article, there are 55 practical case materials.
Introduction: In engineering projects, there are situations where it is necessary to calculate accumulated flow and acceleration. In programming, we can use integration and differentiation formulas to obtain these data values.
The motivation for the development of integration comes from the needs in practical applications. In actual operations, sometimes we can estimate some unknown quantities in a rough manner, but with the advancement of technology, it is often necessary to know precise values. For simple geometric shapes, the area or volume can be calculated using known formulas. For example, the volume of a rectangular swimming pool can be calculated using length × width × height. However, if the swimming pool is oval, parabolic, or has a more irregular shape, integration is needed to determine the volume. In physics, it is often necessary to know the cumulative effect of one physical quantity (such as displacement) on another physical quantity (such as force), which also requires integration.
In this case, we can use an approximate “integration” formula to write the program.
1. Control Requirements
① Read the instantaneous flow every 100ms and calculate the accumulated flow.
② Read the speed value every 100ms and calculate the real-time acceleration.
According to the diagram, draw a straight line between t1 and t0, which is the average of f(t0) and f(t1), and multiply by the time interval t1-t0 to obtain the area, as shown in the following formula:


1.Create a new FB block and define the interface variables.

2.Call the FB program block in the cyclic interrupt program, with a cycle time of 100ms, so the parameter for the pin is 0.1. FB10028 is an automatic LGF library instruction used for simulation testing.

Differentiation is the linear main part of the change of a variable during a certain change process. If the function y=f(x) has a derivative f'(x) at the point x, then the change in y caused by the change in x by △x is △y=f(x+△x) – f(x)=f'(x)·△x+o(△x), where o(△x) approaches 0 as △x approaches 0. Therefore, the main part of the linear form of △y is dy=f'(x)△x, which is the differential of y.
According to the formula in the diagram, differentiation is actually finding the slope, so knowing the values of F (t2) and F (t1) and subtracting them, then dividing by the time difference gives the slope value.

1.Create a new FB block and define the interface variables.

2. Call the FB program block in the cyclic interrupt program, with a cycle time of 100ms, so the parameter for the pin is 0.1. FB10028 is an automatic LGF library instruction used for simulation testing.


Finally: Recently, many friends have mentioned wanting case books, saying that reading articles on mobile phones is not very convenient. I will take some time to organize all 55 practical cases, which are quite typical, including cylinder control programs, alarm programs, program frameworks, motion control program encapsulation, analog control of frequency converters, communication, and other practical cases.If you need them, you can add me on WeChat: biao467524527



Previous Recommendations
Why do I strongly recommend everyone to master one PLC programming language first? Two cases will tell you the answer!
Using two methods to implement Modbus communication polling, which one would you choose?
Should PLC programming focus on mastering one brand or learning multiple brands? Let’s compare through cases!
Which is more convenient and intuitive for writing process control programs: ladder diagrams or SCL language?
Learn PLC data IO mapping through three examples!
Which is simpler for controlling servo functions: Siemens PLC or Inovance PLC?
PLC programming framework for automatic control program writing.
How to achieve multi-language switching on touch screens.
Universal PLC program framework for manual control programs.
Universal PLC program framework for automatic switching programs.
Double your efficiency! Practical application of array data types in PLC.
What “pits” have you encountered in FC program blocks?
Can’t adjust PID? This guide will help you solve it all! Limited time only!!!
How to implement encryption functions on Siemens touch screens?
Using PLC ladder diagrams to write state machine cases.