Application of PLC in Flow Display and Accumulation Measurement Author: Constant built in Shenzhen Co., Ltd. Xia Bing Control At present, PLC (Programmable Logic Controller) has been widely used in steel, petroleum, chemical, electric power, building materials, machinery manufacturing, automotive, textile, transportation, environmental protection and cultural and entertainment industries. It has high reliability and resistance. With the characteristics of strong interference, powerful, flexible, easy to learn and use, small size, light weight, and low price, it also has a wide range of applications in flow measurement, and it is unique in programming for the accumulation of traffic. Perform detailed analysis and discussion, including examples of programming on the Siemens S7-200 CPU. The output signal of the flowmeter is generally a pulse signal or a 4-20mA current signal. Both of these signals output instantaneous flow (there is also a relay output cumulant signal. The principle is the same, and will not be described in detail). Our purpose is to use the PLC. Calculate and display the instantaneous flow value and calculate the cumulative value. When the input signal is a pulse signal, when calculating the instantaneous flow rate, it must be calculated according to a strict time interval to ensure the accuracy of the instantaneous flow rate. Therefore, when calculating the instantaneous flow rate, Must use timed interruption to carry on, moreover, can only run this one and cut off the program in PLC system, can't allow to produce other cut off again (even the low priority cut off does not allow to run), in order to prevent to interfere with time interval of cut off interval Accuracy, the calculation of instantaneous flow is to convert the cumulative number of pulses in this time period into a cumulative flow, and divided by the time is the instantaneous flow rate, for the 4-20mA input only in accordance with the corresponding range conversion can be directly obtained by the instantaneous flow, Accumulated traffic is the cumulative flow of each time period is cumulative flow We must pay attention to the following questions in the course of the actual use of PLC programming: 1. The input pulse frequency range is beyond the PLC receiving range; 2. How to ensure the correct calculation when the PLC high speed counter reaches the maximum count value; 3. How to ensure that scheduled interruptions are not disturbed; 4. How to avoid calculating the cumulative error; 5. The maximum cumulative number of cumulative amounts; 6. How to reset the cumulative amount; The following is a detailed description of the most critical issues of 2,4,6. Taking the Siemens S7-200 CPU224 as an example, the CPU224 of the S7-200 has six single-phase high-speed counters with a maximum of 30 kHz, but the PLC does not provide corresponding algorithms internally. Calculate the frequency, therefore, need to calculate by oneself, this needs to guarantee the correctness of the calculation when the PLC high-speed counter reaches the maximum count value, in the actual programming, after making the high-speed counter initialize, make it count continuously, no longer carry on counting. For any intervention, the high-speed counter initialization procedure is as follows: Note: This segment program should be executed in the program executed by the PLC in the first scan cycle. When the high-speed counter reaches the maximum count value, it needs to be judged that the high-speed counter of the S7-200CPU can be accumulated continuously, the highest bit is the sign bit, and the minimum value is 7FFFFFFF. Since the counter is always added, it is impossible to read this time. The fetched count value is less than the previous count value. Therefore, judging whether the current value of the counter is smaller than the previous count value, it is possible to judge whether the count value reaches the inflection point (7FFFFFFF) of the maximum value. If it reaches, special calculation is performed to eliminate the calculation. Error, as shown in the following program, when the current count value is greater than or equal to the last count value, the difference between the two count values ​​is obtained, the count difference in the program scanning interval is obtained, and the current count value is assigned to the last time. Count value; When the current count value is less than the previous count value, calculate the difference between the last count value and 7FFFFFFF (in subtraction), and the difference between the current count value and 7FFFFFFF (in addition), then Adding the two results is the difference in the counts in the two scanning intervals of the program, so that the cumulative count value can be reached Correct calculation of points. Note: This program should be placed in the timer interrupt subroutine. In fact, in the on-the-spot application, the timer interrupt subroutine is executed with a 250ms interrupt. When using SMB34 to control, it should be noted that the system must only guarantee that this interrupt is the only one that exists and will not be affected by other interrupts. Otherwise, the periodic interrupt may not be punctual due to the influence of other interrupts, which affects the accuracy. Through the above calculations, the number of pulses sent by the flowmeter within 250ms is obtained. This value is multiplied by the pulse equivalent that is the flow value within 250ms. Dividing the time by the instantaneous flow is also calculated. In addition, the accumulation procedure can be performed within 250ms. To accumulate flow, it is necessary to avoid the calculation error of the accumulation process during the calculation of the cumulative flow. We know that the flow accumulation amount is a value that has accumulated continuously and generally accumulates to 8 digits, and the effective number of floating-point numbers within the PLC It is 6 bits. When the cumulant value is very large, it will cause a large number and a decimal number to add. This will inevitably result in the loss of the effective number of decimals, resulting in a large cumulative error. Therefore, to avoid the addition of large numbers and decimal numbers. The situation arises, the solution is to use multiple flow accumulators, only allow the same amount of values ​​to add, thus avoiding the loss of the number of significant digits, the actual programming used in the five accumulator, according to the common traffic situation, in the cycle of interruption The flow through the interval (250ms) is multiplied by 15 as the upper limit of the first accumulator, after reaching the upper limit of this accumulator Accumulate the accumulator's value into the second accumulator and clear the first accumulator. Also treat the third accumulator. The fourth accumulator is used to store the fractional part of the cumulant. The five accumulators are used to store the integral part value of the cumulant so that only the integer part and the small tree part can be displayed when displaying the total cumulant, and the whole process fully avoids the addition of large numbers and decimal numbers during the accumulation process. In an actual project, the number of accumulators used must be determined based on the size of the traffic and the period of periodic interruption. The integer part of the accumulator is represented by double integers. The range of double integers is -2,147,483,648 to +2,147,483,647. Therefore, The number of integer bits in the accumulator can be set to 9 bits so that when displaying the accumulated amount, the cumulative amount of 9-bit integers and the 6-bit fractional accumulation amount can be displayed at most. A total of 15 bits eliminates the multiplier multiplier and makes reading easier. The accumulator needs to be reset under certain conditions and accumulated to the maximum value or manually reset. In the interrupt program, it is determined whether the accumulated amount exceeds the maximum number of digits. When the maximum value is exceeded, the accumulators are cleared to zero, and the cleared trigger is also cleared. The signal can also be manually triggered. 3.2V Battery Cells,Prismatic Phosphate Lithium Batteries,3.2V 202Ah,3.2v lifepo4 battery,3.2V LifePO4 Lithium Battery Pack Jiangsu Zhitai New Energy Technology Co.,Ltd , https://www.ztbatteries.com