Nêu chi tiết sự khác nhau giữa FC và FB trong tia portal?
Trong TIA Portal của Siemens, FC (Function) và FB (Function Block) đều là các khối hàm dùng để viết các đoạn mã chương trình phục vụ cho điều khiển và tính toán. Tuy nhiên, chúng có một số khác biệt chính như sau:
Mục đích: FC được sử dụng để thực hiện các thao tác hoặc tính toán đơn giản không cần lưu trữ trạng thái hoặc dữ liệu qua nhiều lần gọi.
Không lưu trữ trạng thái (Stateless): Các FC không có bộ nhớ riêng để lưu trữ dữ liệu của chúng. Khi FC được gọi, các biến cục bộ chỉ tồn tại trong thời gian thực thi và không được lưu lại sau khi FC hoàn thành. Điều này có nghĩa là mỗi lần bạn gọi FC, nó bắt đầu với cùng một giá trị khởi tạo.
Truyền tham số: FC chỉ có thể nhận và trả về dữ liệu thông qua các tham số đầu vào (Input) và đầu ra (Output).
Không cần DB (Data Block): FC không cần một Data Block riêng biệt để lưu trữ dữ liệu của nó.
Mục đích: FB được sử dụng khi cần lưu trữ trạng thái hoặc dữ liệu qua nhiều lần gọi, chẳng hạn như các thao tác điều khiển phức tạp, điều khiển PID, hoặc quản lý trạng thái của hệ thống.
Lưu trữ trạng thái (Stateful): FB có khả năng lưu trữ dữ liệu và trạng thái của mình trong một Data Block (Instance Data Block - IDB). Điều này có nghĩa là FB có thể duy trì trạng thái của các biến nội bộ giữa các lần gọi, giúp quản lý trạng thái của hệ thống hoặc quy trình.
Sử dụng Instance Data Block (IDB): Mỗi khi một FB được gọi, nó cần một IDB riêng để lưu trữ dữ liệu của nó. IDB này sẽ giữ tất cả các biến của FB và cho phép chúng duy trì giá trị của mình trong suốt chu kỳ hoạt động của chương trình.
Khả năng sử dụng lại (Reusability): FB có thể được gọi nhiều lần với các IDB khác nhau để duy trì các bộ trạng thái riêng biệt cho từng trường hợp cụ thể.
FC: Không lưu trữ trạng thái, không cần Data Block, dùng cho các thao tác đơn giản.
FB: Lưu trữ trạng thái qua IDB, dùng cho các quy trình phức tạp cần theo dõi trạng thái.
Function (FC) and Function Block (FB) both are just like a subroutine. Users can create a part of the logic in this block and then call it each time when required to execute that logic.
This logic must be such as,
Control Valve Operation
Mathematical Operation, etc.
Function (FC) and Function Block (FB) both are used to optimize user programming. The main use of FC and FB is to divide and organize the user program into smaller parts that can be easily understood. It helps in maintenance and troubleshooting.
FC and FB can be created by the user and used as a user library. So, users have to just write it once, and can be used as many times as required. This also reduces and rationalizes the resources of the CPU, such as memory occupation.
A Function(FC) is a logic block without memory. This block can be created by the user and called as many times as required. We can assign different parameters in the function such as In, Out, In-Out, Temp.
Temp variables defined in the FC are stored in the local data stack, which will be lost after the execution of FC.
The above image shows the FC blocks for the motor starter. All the parameters such In, Out, In-Out have to fill with the address.
A Function Block(FB) is a logic block with memory. This block can also be created by the user and called as many times as required. The difference is whenever we called a Function Block(FB), it creates a DB as its memory. This DB is called an instance data block.
We can also assign different parameters in the function block as In, Out, In-Out, Temp, and Stat, which is an additional parameter in the FB. Data saved in the instance data block is not lost after the execution of the FB. Static variables are stored in the instance data block. However, Temp data is stored in the local data stack which is lost after the execution of FB.
The above image shows the Function Block(FB) for the control valve operation. You need not enter all the parameters with the address. FB will generate an instance data block with each call.
⇒ The main difference is FC has no instance memory, while FB has an instance Data Block(DB). This instance data block saves all the parameters of In, Out, In-Out, and Stat. They can be accessible even after the execution of FB.
⇒ We can program FC or FB with FBD, LAD, STL, and SCL. The FB has additional capabilities to program in Graph.
⇒ Whenever we called for FB, it generated an instance Data Block(DB) with it. There is no such necessity for FC.
⇒ In FC, we can not leave any parameters such In, Out, In-Out blank. Since all the formal parameters in FC do not save in any memory and as a result there is no initial value assigned to them. In FB, we can leave any of the parameters such as In, Out, In-Out with no address.
Basically, memory.
An FB is a function that "remembers", or "keeps score" of its last operations.
Both FCs and FBs can hold parameters (IN, OUT, IN-OUT and TEMP), it allows the re-use of the blocks with different calling environments. But FBs have an extra type of parameter: STATIC not available in FCs.
When you call an FB, you are required to generate an instance DB (IDB) that accompanies this particular call of an FB; this DB contains all the STATIC parameters of the FB, and these are available at any time by any other block in your program. You could do this with an FC, a general DB and MOVE instructions that would write results of the FC program in that DB. With an FB it is automatic.
If you want an example, look at the contents of the System Function Blocks library in Step 7, and look at the grouping of the SFCs and the SFBs. SFCs include SET RTC; this transfers a DT value to the real-time clock of the CPU. Once executed, there is no reason for the function to look back at what it had done. Same thing for SFC20, BLKMOV; once the data has been transfered, no need to remember. But look at the first SFBs: CTU, CTD, TON, TP... Once you have started counting or timing, you might need to look at the value of your accumulated value, or modify the preset. The IDB makes it always available, memorized and accessible, even if the block is not being processed at this exact moment by the CPU.
As an exercise call SFB4, TON, in a Lad network; you will be promped for a DB number; put any DBx not presently used to create the IDB. Once the calling block saved, open the blocks folder and see that are the elements of this DB; try modifying them.. The structure od the IDB is linked exclusively to the structure of the FB and is not accessible to you.
Now go back to the program, and use any instruction to use the IDB varables in your program. You should be able to use them as any other data in the CPU.
FB and FC are two types of subroutines that make STEP 7 a very flexible and powerful tool.As subroutines, FC and FB can be used to optimize the programming. Main uses for FC and FB:
Divide and organize the user program. Divided in small parts the units can be easily understood. This helps specially maintenances and alterations of the program.
Rationalize and optimize the programming. FC and FB can be created and used as users’ library. So, an algorithms is programming just one time, and can be used many times in one our more projects.
Reduce and rationalize resources of the CPU (e.g. memory occupation).
Both FB and FC has an important feature that is the possibility to have input/output parameters. This permits that a same algorithm could be used many times, each with different set of variables.While a FC uses the address of the given parameter to read and write directly in then, a FB copy this parameters to/from a associated DB, and work internally just with the DB variables. The uses of an associated DB for each call (so called Instance DB), open the possibility to store variables internally. The follow table shows the difference between FC and FB
Note:The FB copy the input parameters to the instance DB at start call and, at end, copy back from the instance DB to the outputs. This could take a little bit more memory and processing time as a FC. In other hand, internally it works just with instances DB variables; this means that the internal processing of a FB could be a little faster as FC. However, these differences will depends of many factors like ratio parameters / codes, type of parameters, etc
Great explanation from Daniel Chartier and beautiful table from Pegaia.
Really good work.
I can't add something but I would like tohighlight one of the differences (I consider it a big one).
If you can use an FC with shared DB with Load and transfer, it's true that this would be very equal to the use of FB and instance DB.
BUT still you can't ignore the story of parameters.
In FB like Pegaia had said the actual parameters (INs and Outs) are transferred into and from the instance data block. (This increases your data block space) while if you use FC with shared data block you don't have to add a place for your parameters in the shared data block because the FC deals with the addresses of parameters.
I think this might increase execution time in FB because FB have to copy Input actual parameters to formal parameters(inside instance data block) and also have to copy Output formal parameters (inside instance data block) to the actual parameters.
However, this gives a really beautiful feature for FBs.
Since the FB reserve space in the instance data block for parameters, You can ignore some parameters when you call this FB.
I mean if you create FB with 10 inputs and 20 outputs, You can call this FB and ignore any parameter you don't need because the FB will take the initial value of this parameter in the instance data block.
So you can select only the parameters you need and let the FB takes the initial of the other parameters.
The best example for this story of parameters is the FB41 (PID controller).
you don't have to assign actual parameters to the formal parameters of the FB41 and this is a good thing because you assign just what you need.
Now we come to the FC, you can't ignore any parameters and you MUST assign actual parameters to all formal parameters you have in this FC.
The attached file explains the FC,FB and the difference between them in better words that what I said.
Siemens là một trong những công ty hàng đầu trong lĩnh vực tự động hóa công nghiệp và cung cấp nhiều chuẩn truyền thông để đáp ứng các nhu cầu khác nhau của ngành công nghiệp. Dưới đây là các chuẩn truyền thông công nghiệp phổ biến mà Siemens sử dụng:
PROFIBUS:
PROFIBUS DP (Decentralized Peripherals): Được sử dụng rộng rãi trong tự động hóa nhà máy để kết nối các thiết bị hiện trường với hệ thống điều khiển.
PROFIBUS PA (Process Automation): Dành cho các ứng dụng tự động hóa quá trình, đặc biệt là trong các ngành công nghiệp hóa chất và dầu khí.
PROFINET:
Là phiên bản Ethernet của PROFIBUS, PROFINET cung cấp khả năng truyền thông real-time và tốc độ cao, phù hợp cho các ứng dụng điều khiển chuyển động và điều khiển tự động hóa.
AS-Interface (AS-i):
Sử dụng để kết nối các cảm biến và thiết bị chấp hành trong các hệ thống tự động hóa cấp thấp. Siemens sử dụng AS-i cho việc kết nối đơn giản, hiệu quả chi phí giữa các thiết bị hiện trường.
Industrial Ethernet:
Siemens hỗ trợ Industrial Ethernet cho các ứng dụng đòi hỏi truyền thông Ethernet tốc độ cao và đáng tin cậy, từ cấp điều khiển đến cấp doanh nghiệp.
Modbus TCP/IP:
Siemens hỗ trợ Modbus TCP/IP cho các ứng dụng yêu cầu kết nối với các thiết bị hoặc hệ thống khác không sử dụng chuẩn Siemens.
OPC UA:
Siemens tích hợp OPC UA trong các hệ thống như S7-1500 và WinCC để cung cấp khả năng kết nối mở, an toàn và linh hoạt giữa các thiết bị và hệ thống khác nhau.
EtherCAT:
Mặc dù không phải là giao thức do Siemens phát triển, Siemens cũng hỗ trợ EtherCAT trong một số thiết bị khi cần kết nối với các hệ thống sử dụng giao thức này.
IO-Link:
Siemens sử dụng IO-Link cho các kết nối điểm-điểm thông minh giữa các cảm biến/thiết bị chấp hành và hệ thống điều khiển.
BACnet:
Siemens sử dụng BACnet trong các ứng dụng tự động hóa tòa nhà để kết nối các hệ thống HVAC, chiếu sáng và các hệ thống quản lý tòa nhà khác.
KNX:
KNX là chuẩn truyền thông được Siemens sử dụng trong các hệ thống tự động hóa tòa nhà, đặc biệt là cho điều khiển chiếu sáng, HVAC, và các hệ thống quản lý năng lượng.
Các chuẩn truyền thông này cho phép Siemens cung cấp các giải pháp tự động hóa toàn diện, từ cấp hiện trường đến cấp quản lý và từ các hệ thống nhỏ đến các mạng lưới nhà máy lớn.
Kết nối PLC s7-1200/1500 với Modbus Poll/Slave
Kết nối PLC s7-1200/1500 với KepserverEX
Kết nối 2 PLC S7-1200/1500