1. Understanding FC and FB from the Perspective of “Cooking”: What is the Essential Difference?
Let’s set aside the code and use a life example:

•FC (Function) is like avegetable cutter in the kitchen. You throw a potato in, and it consistently outputs shredded potatoes without remembering whether the last item was a radish or cucumber. Each time it is called, it works according to a fixed process without any “memory.”
•FB (Function Block) is more like anintelligent rice cooker . When you press the cook button, it remembers the amount of rice and water, and even adjusts the heat based on your previous taste preferences. It has its own “little ledger,” which can record and reuse data.
In programming terms:
•FC has no static variables; each call starts “from scratch,” making it suitable for calculations, conversions, and other pure logic tasks . For example, converting a temperature value from℃ to℉, inputting 37℃, will always output 98.6℉.
•FB has an independent background data block (DB), which can store intermediate results and states. It is suitable for scenarios that require “memory” such as motor start-stop control, where it remembers whether the last state was on or off to avoid misoperation.

2. Unveiling the Underlying Logic: Why Choose FC/FB?
1. FC: A Lightweight “Tool”
•Advantages:
◦No data storage: Fast execution speed, low memory usage, suitable for simple tasks with high-frequency calls.
◦Strong independence: Does not rely on external data; modifying one piece of code does not affect other program segments, making maintenance super convenient.
•Applicable Scenarios:
◦Data conversion (e.g., analog filtering)
◦Mathematical operations (addition, subtraction, multiplication, division, trigonometric functions)
◦Conditional judgments (e.g., alarm threshold detection)
2. FB: An Intelligent Module with Built-in “Memory”
•Core Features:
◦Background data block DB: Each FB instance has its own DB, which stores input/output parameters and static variables. For example, controlling the extension and retraction of a cylinder, DB can remember the current position and speed of the cylinder.
◦High reusability: Once a FB is well-written, it can be reused in different projects with slight modifications. For example, an elevator door control FB can be reused in both office and residential building projects.
•Typical Applications:
◦Device control (motors, valves, conveyors)
◦Complex logic (sequential control, state machines)
◦Multi-instance tasks (simultaneously controlling multiple identical devices)
3. Practical Cases: How to Use FC and FB?
Case 1: Temperature Monitoring Alarm (FC is More Suitable)
Scenario: Trigger an alarm when the temperature exceeds80℃.

Here, FC1 acts like a “temperature referee,” immediately outputting judgment results based on the input temperature value without recording historical data, making it concise and efficient.
Case 2: Servo Motor Control (FB is the King)
Scenario: Control the forward and reverse rotation of the servo motor, adjust acceleration and deceleration, and record the operating status.

FB2 remembers the motor’s position, speed, and other parameters through the background DB, allowing for a “seamless connection” during the next call, ensuring control accuracy.
These Pitfalls Must Be Avoided!
1.Abuse of FB Leading to Memory Explosion: While FB is powerful, each instance occupies DB space. For controlling dozens of small lights while still using FB, the PLC may directly “crash.”
2.Misuse of FC Leading to Data Confusion: Using global variables to store intermediate values in FC can lead to data being overwritten when different program segments are called simultaneously, causing strange faults.
3.Ignoring the Importance of Background DB :: After modifying FB parameters, forgetting to update the corresponding DB can cause the device to directly “go crazy” during runtime.
Summary: FC is suitable for simple tasks that are “ready to use,” while FB excels at handling complex control logic with memory. Mastering the differences between the two can improve programming efficiency by at least 50%!
If you encounter any FC/FB related issues in your projects, feel free to leave a message in the comments, and I will help you “debug”! If you find this useful, please like + share to help more engineers avoid detours~