Detailed explanation of the difference and usage of FC and FB

Many newbies will ask, what is the difference between FC and FB? How to use it? In fact, it is very simple, you can understand it by carefully reading the following!
FC block explanation First, we can distinguish between the two names, which can be represented by a formula called FB=FC+DB. FB is a special FC with DB background block, which means that FB has FC function and has A DB block. The full name of FC is the Function function. Note: The DB block is called the DataBlock data storage area, which is similar to the relational table structure in the database. What function is it first?

function

The function f(x) is like a machine or black box, giving the input value x a unique output value f (x). x is an independent variable and f(x) is a dependent variable. To give us a common formula, find the area of ​​the circle, s = π * r * r. Enter the r value to get the area s of the circle. This is the simplest function, r is the independent variable, and s is the dependent variable.

Detailed explanation of the difference and usage of FC and FB

Figure 1 variable declaration

Detailed explanation of the difference and usage of FC and FB

Figure 2 FC function content Input: Input type parameter, providing an external input interface. Similar to x in the function f(x), is an independent variable. The Input type parameter is a copy of the external variable, modifying its value, and the external variable has no change. Suppose you modify the value of R in the program. From the compilation information in Figure 2, it is found that the actual parameters are not passed, so there is no change in modifying the external interface variables. Output: Output parameter, providing an external output interface. This type parameter can modify its value by directly referring to the external variable address. InOut: Input and output parameters, both input and output. As with the Output type, you can modify the value of an external interface variable. In the appropriate place, using the InOut type variable can reduce the variable declaration space that occupies the plc. Temp: Local variable, used inside the function, does not provide an external interface. We often use temp variables for intermediate values ​​of data conversion, or for loop variables, such as for For or While loops. Since Temp is a local variable, its value is random, and the use must be initialized and assigned. Constant: Constant, used inside a function, meaning a constant variable that can only be modified at the declaration.

For example, our pi circumference is fixed, there may be dozens of places to call, if the program directly refers to 3.1415, later modification, you need to modify each place, it is very troublesome. Modify the π value at the declaration, and the π variable in all functions will be modified. Suppose we modify the π constant in the program. From the compilation information in Figure 2, we can see that the constant cannot be modified in the program. Return: The function returns a value and stores the result of the calculation. The default is no return value, so it is declared as void. In our mathematical knowledge, the function should have a return value, but in TIA PORTAL there can be no return value, we call this function without return type, called procedure. We set this to the Real type and return the area of ​​the circle. Some readers may have doubts, both the return variable and the Output type can be used to store the result of the calculation. What is the difference between the two? One of the significant differences is that the Output type output parameter can declare several, but the return type of the return type, Only one can be declared, and the variable name cannot be modified. Other differences, when you explain SCL, then answer. Drag the FC1 function in the main[OB1] block to get the following result:

Detailed explanation of the difference and usage of FC and FB

Figure 3 program running results

Figure 4 DB block value monitoring program interpretation: Since the PLC program is executed from left to right, the left side of the "Func" function block is the input interface, and the right side is the output interface. Observe the internal variable name of the function block and find a one-to-one correspondence with the declaration in the function, except for the variable. Ret_Val is an alias for the Return interface variable. Since each function has a different name, it is uniformly used as the name of the function return value variable. The first procedure is to convert the analog value. The lower resolution limit of the sample is 0, the upper limit is 27648, and the sampled digital value is 15000. The converted value is placed in the variable <"Data" by calling the specified function. Voltage value>, The converted value is 0.5425347. The variable <"Data". Voltage value > is placed in the Inout interface of the FC function. Using the scan cycle of the PLC, the final value of 5.425347 can be seen through the DB block. If you do not put Inout, put it on the Input interface, we must declare a variable in the OutPut interface to store the final conversion value. This declaration saves the memory space of the PLC, and also makes the program look more concise. The code content of the FC function block is relatively simple, please read and understand it yourself. If there is any problem, you can leave a message.

FB block explanation To understand the difference between FB and FC, let us analyze the variable declaration structure of these two modules:

Detailed explanation of the difference and usage of FC and FB

Figure 5 FB block variable declaration

Detailed explanation of the difference and usage of FC and FB

Figure 6 FB occupies DB background block internal variables Through FB and FC variable declarations, we can see three obvious differences: 1. FB block adds Static static area declaration 2. FB adds retentivity and accessibility selects above The two differences just illustrate the establishment of the FB=FC+DB formula, because these two features are unique features of the DB block. The variables we declare in the normal DB block are declared in the Static area. If you don't believe it, you can open it and see it. We can access the value of the variable in the FB by accessing the background block owned by the FB. When the FC call ends, the variable values ​​declared in the various interfaces cannot be saved. After the FB call ends, the value of the variable can still be retained. You can access it through the background DB block of the FB. Each call of FB will automatically generate a DB block. Think about what kind of operation in our programming will have similar behavior? In fact, we use very frequent timer operations, each time the drag timer will automatically create a DB block. Look at the DB block owned by the timer through <System Resources> and see if it is similar to Figure 6.

Figure 7 Timer DB background block structure Since the timer has a background block, when we stop timing, the PLC can read the value of the stop timing no matter how many scan cycles it passes. This is the benefit of having a DB background block, FB block. Similar to this. 3. The FB block does not have a Return interface. Since the return value can be stored through the Output interface, there is no significant effect on the Return interface.

Figure 8 FB program additions Because the program is similar, the FB program only lists the additions. We can see the program, each time the maximum voltage value is placed in the variable, and variables are added to record the time to change the voltage. In the hmi program, we can easily read these two variables to get the current maximum voltage value and modification time in real time. Is it convenient? Readers may have questions. If I write an FC function myself and then add a DB block externally, can this be done the same? It seems to be very reasonable, but the idea is wrong. This method can be used if you only call the FB block once in the PLC program. If you are in the PLC program, you must compare the voltage, but also compare the current, temperature and humidity, etc. If you use the same FC how to achieve it? Using FB can solve this problem very well, if you don't understand it, you should think about it!

VOZOL D5 Vape

VOZOL D5 Vape are so convenient, portable, and small volume, you just need to take them
out of your pocket and take a puff, feel the cloud of smoke, and the fragrance of fruit surrounding you. It's so great.
We are China leading manufacturer and supplier of Disposable Vapes puff bars, vozol d5 disposable vape,vozol d5 vape kit,
vozol d5 vape pen, and e-cigarette kit, and we specialize in disposable vapes, e-cigarette vape pens, e-cigarette kits, etc.

vozol d5 disposable vape,vozol d5 vape kit,vozol d5 vape pen,vozol d5 vape 1000 puffs,vozol d5 e-cigarette 1000 puffs

Ningbo Autrends International Trade Co.,Ltd. , https://www.vapee-cigarettes.com