FB and FC difference in Siemens PLC - Database & Sql Blog Articles
FB--function block with instance data block
FC--function, equivalent to function
The main difference between them is that FC uses shared data blocks and FB uses background data blocks.
For example, if you want to control three motors with the same parameters, you only need to use FB programming plus 3 instance data blocks. However, if you use FC, you need to constantly modify the shared data block. Otherwise it will result in data loss. The FB ensures that the parameters of the three motors do not interfere with each other.
FB and FC are essentially the same, they act like subroutines, which can be called by other programs (they can also call other subroutines). The biggest difference is that FB works with DB, and the data stored by FB is kept in DB even after the FB exits. FC does not have a permanent data block; it only allocates temporary memory during runtime. In actual programming, whether to use FB or FC depends on the specific needs. The benefits of using FB are significant.
FB and FC are not very different, but FB has a background data block while FC does not. This allows FBs with different data blocks to carry different parameter values, enabling multiple objects to use the same FB with separate instance data blocks.
In C language, FC and FB are similar to functions, except that FB can generate static variables. These variables retain their values between function calls, while FC variables are only valid during the call and are replaced in subsequent calls. Every time you call the I/O area of FC, you must manually input the values each time, whereas FB handles this automatically, saving a lot of trouble. If you input the DB control address directly in the host computer control, it becomes much easier.
For example, if there are 50 motors that need to be controlled, and they all follow the same control logic but with different parameters, using FC would require allocating separate DB blocks for each motor and specifying the parameter addresses one by one. This can be very tedious and error-prone. Using FB instead allows you to write the control process once and reuse it for all motors by assigning different instance data blocks.
Imagine how much time and effort this could save. If the function needs to be modified, you just need to update the FB, and all instances will automatically reflect the changes. Other examples include PID control, traffic accumulation, and more.
Think of FC as an assembly line—once the processing is done, there's no record left. But FB with DB not only processes the data but also keeps a record. When dealing with multiple devices, writing an FB and calling it multiple times automatically generates the corresponding DB blocks, making the process much simpler.
The variable declaration table of an FB contains static variables, allowing for multi-level parameter transfer. Therefore, a background data block must be generated when calling an FB. FC does not support this feature. While FBs can replace FCs, the reverse is not true.
Multi-instance calling refers to the ability to call an FB multiple times with different DBs, passing parameters at each level. For example, parameters from FB1 can be used in FB2, and only one instance data block is finally generated.
Zane: FB doesn’t actually consume too many resources because these variables exist regardless of being global or local.
I use a lot of FBs now. FC is mainly used for simple logic or short subroutines that don’t require complex data handling.
FBs help modularize the program, increasing its portability. It’s similar to using standard libraries provided by Siemens.
The fundamental difference between FB and FC lies in the support for static variables. Static variables retain their values across function calls, while FC variables are temporary and reset each time.
If you store data in temporary variables in FC, it may lead to unpredictable results when you read it again. But with static variables, the last written value remains.
Wanquanhe: In our control programs, FBs are rarely used. It’s rare to say that replacing FC with FB is practical. Who used to rely solely on FC? I think the system might not handle that well.
Among the standard libraries, there are many FBs available. If your function doesn’t require static variables, there’s no need to use FB. High-level languages often have static variables, but they aren't commonly used.
Knight: I agree with Zane. In my work, I compile the same function into an FB and then call it from FC. It makes modifications easier. For example, if you have 10 motors, you usually need to handle start, stop, alarm, and reset logic. By compiling this into an FB and assigning a background block to each motor, you can easily call them from FC.
When you call these motors in FC, you just need to add the corresponding I/O points to the FB pins and let the logic inside handle everything. If you use FC, you’d have to write the same logic 10 times, which increases the chance of errors and makes maintenance harder.
Therefore, combining FB and FC is the most efficient approach. I recommend trying FB. Once you understand it, you’ll be surprised by how powerful it is.
Zane: Regarding the use of FB and FC, I learned through real-world applications. It’s my personal experience and view, not a strict rule. You can try different approaches. However, one thing is certain: before starting the development, you should have a clear plan for the entire project.
Programs from foreign sources are often written directly in FC, while domestic projects tend to use FBs and then call them from FC. What are the pros and cons of each method?
If FC can achieve the task, there’s no need to use FB. FC and FB are essentially the same. Calling an FB is similar to using OPNDI in FC and indexing variables with AR2.
The advantage of FB is that you can refer to variables in the data block by name, making it more intuitive. Execution efficiency is the same as FC.
Supplement: In fact, FC is more flexible. In FC, you can call OPNDI multiple times to access multiple background blocks. AR2 can also be used for various purposes.
In principle, AR2 cannot be used in FB. Calling FB also specifies the data block, which can be inconvenient.
Supplement 2: FB is like a trick in the programming environment. The PLC instructions themselves don’t differ between FB and FC.
Calling FB or FC ultimately involves a call instruction converted to UC or CC. To observe this in the programming environment, just write a program with a parameter (FB or FC), call it from another block, download it, change the subroutine interface, and download again.
At this point, the calling instruction of the calling block becomes invalid. Then upload the calling block.
1. Generally, use FB to write common control programs, such as valve or pump control. In the interface, you can define some preset values for valve opening degrees (not through input, but directly controllable via HMI). Fault signals can also be written into the static variables and sent directly to the HMI.
2. FC typically calls these FBs and provides some inputs and outputs.
3. All inputs and outputs of FC must be assigned, while FB only needs to provide the background data block.
4. Of course, if you don’t need to track the process values, FC is sufficient and simpler.
If you have a basic understanding of computer programming, you can think of it this way:
1. FC is like a "program" within a larger program, directly called for process execution.
2. FB is like a "class," with interfaces, properties, and methods for programming "control objects." The FB DB is like a concrete "object" instance.
Speakers are one of the most common output devices used with computer systems. Some speakers are designed to work specifically with computers, while others can be hooked up to any type of sound system. Regardless of their design, the purpose of speakers is to produce audio output that can be heard by the listener.
Speakers are transducers that convert electromagnetic waves into sound waves. The speakers receive audio input from a device such as a computer or an audio receiver. This input may be either in analog or digital form. Analog speakers simply amplify the analog electromagnetic waves into sound waves. Since sound waves are produced in analog form, digital speakers must first convert the digital input to an analog signal, then generate the sound waves.
The sound produced by speakers is defined by frequency and amplitude. The frequency determines how high or low the pitch of the sound is. For example, a soprano singer's voice produces high frequency sound waves, while a bass guitar or kick drum generates sounds in the low frequency range. A speaker system's ability to accurately reproduce sound frequencies is a good indicator of how clear the audio will be. Many speakers include multiple speaker cones for different frequency ranges, which helps produce more accurate sounds for each range. Two-way speakers typically have a tweeter and a mid-range speaker, while three-way speakers have a tweeter, mid-range speaker, and subwoofer.
Speaker System,Magnet Speaker Acoustic,Moving Coil Loudspeaker,Metal Frame Mylar Speaker
Jiangsu Huawha Electronices Co.,Ltd , https://www.hnbuzzer.com