In the realm of industrial automation, Siemens PLCs (Programmable Logic Controllers) stand as a cornerstone, offering robust and flexible solutions for a wide range of applications. Function blocks are a fundamental aspect of programming Siemens PLCs, enabling efficient and modular programming. As a Siemens PLC supplier, I am well - versed in the process of creating and using function blocks, and I am excited to share this knowledge with you.
Understanding Function Blocks in Siemens PLCs
Function blocks in Siemens PLCs are reusable program units that encapsulate a specific set of functions. They are similar to sub - routines in traditional programming, but with more advanced features. Function blocks can have input and output parameters, as well as internal variables. This modular approach simplifies the programming process, enhances code readability, and promotes code reuse.
There are two main types of function blocks in Siemens PLCs: FB (Function Block) and FC (Function). A Function Block (FB) has its own memory, known as the Instance Data Block (DB). This means that each call of an FB can have its own set of internal variables, making it suitable for situations where multiple instances of the same function need to operate independently. On the other hand, a Function (FC) does not have its own memory. It relies on the input parameters passed to it and returns a result. FCs are typically used for simple, stateless operations.
Creating Function Blocks
Step 1: Open the Programming Environment
First, you need to open the programming environment for your Siemens PLC. For example, if you are working with Siemens PLC S7 1500, you would use TIA Portal (Totally Integrated Automation Portal). This software provides a comprehensive platform for programming, configuration, and diagnostics of Siemens automation systems.
Step 2: Define the Function Block
In the programming environment, navigate to the block library and create a new function block. You can choose between an FB or an FC depending on your requirements. When creating the block, you need to define its name, which should be descriptive of the function it performs.
Step 3: Define Input and Output Parameters
Next, you need to define the input and output parameters of the function block. Input parameters are the values that the function block will receive from the calling program, while output parameters are the values that the function block will return. In the parameter definition section, you specify the name, data type, and description of each parameter. For example, if you are creating a function block to calculate the sum of two numbers, you might define two input parameters of type "INT" (integer) and one output parameter of type "INT" to hold the result.
// Example of parameter definition for a sum function block
// Inputs
IN1 : INT;
IN2 : INT;
// Output
OUT : INT;
Step 4: Define Internal Variables (for FBs)
If you are creating an FB, you also need to define the internal variables. These variables are used to store the state of the function block during its execution. For example, if you are creating an FB to control a motor, you might have internal variables to store the motor's current speed, direction, and status.
// Example of internal variable definition for a motor control FB
MOTOR_SPEED : REAL;
MOTOR_DIRECTION : BOOL;
MOTOR_STATUS : INT;
Step 5: Write the Function Block Logic
Once you have defined the parameters and internal variables, you can start writing the logic of the function block. This is where you use the programming language supported by the Siemens PLC, such as Ladder Logic (LAD), Structured Text (ST), or Function Block Diagram (FBD). For the sum function block example, the logic in Structured Text would be:
OUT := IN1 + IN2;
Using Function Blocks
Step 1: Call the Function Block
In your main program or another function block, you can call the function block you have created. To call an FB, you need to create an instance of it by associating it with an Instance Data Block (DB). For an FC, you simply call it by its name and pass the required input parameters.
// Example of calling a sum FC
RESULT := SUM_FC(IN1 := 5, IN2 := 3);
// Example of calling a motor control FB
MOTOR_INSTANCE(IN1 := TRUE, IN2 := 100);
Step 2: Pass Input Parameters
When calling the function block, you need to pass the appropriate input parameters. These parameters can be constants, variables from the calling program, or the results of other function block calls. Make sure that the data types of the input parameters match the ones defined in the function block.
Step 3: Retrieve Output Parameters
After the function block has executed, you can retrieve the output parameters. These values can be used in further calculations or to control other parts of the program.
Advantages of Using Function Blocks in Siemens PLCs
Code Reusability
One of the main advantages of using function blocks is code reusability. Once you have created a function block, you can use it in multiple programs or in different parts of the same program. This saves development time and reduces the chances of errors.


Modularity
Function blocks promote modular programming. Each function block can be developed, tested, and maintained independently. This makes the overall program easier to understand, modify, and debug.
Readability
Function blocks make the program more readable. By encapsulating a specific set of functions in a block with a descriptive name, it is easier for other programmers to understand the purpose of each part of the program.
Considerations for Different Siemens PLC Models
Siemens PLC S7 200
The S7 200 series is a compact and cost - effective PLC solution. When creating and using function blocks in S7 200, you need to consider its limited memory and processing power. You may need to optimize your function block logic to ensure efficient use of resources.
Siemens PLC S7 1200
The S7 1200 series offers a good balance between performance and cost. It supports a wide range of programming languages and has a user - friendly programming environment. When working with function blocks in S7 1200, you can take advantage of its advanced features such as data logging and communication capabilities.
Siemens PLC S7 1500
The S7 1500 series is a high - performance PLC solution with advanced features such as multi - core processors and high - speed communication. When creating and using function blocks in S7 1500, you can implement complex algorithms and take advantage of its high - speed processing capabilities.
Conclusion
Function blocks are a powerful tool in Siemens PLC programming. By following the steps outlined above, you can create and use function blocks effectively, improving the efficiency, modularity, and readability of your programs. Whether you are working with Siemens PLC S7 200, Siemens PLC S7 1200, or Siemens PLC S7 1500, understanding function blocks is essential for successful industrial automation projects.
If you are interested in purchasing Siemens PLCs or need further assistance with function block programming, please feel free to contact us. We are here to provide you with the best solutions for your industrial automation needs.
References
- Siemens, "Programming Manual for SIMATIC S7-1200 and S7-1500", Siemens AG, 20XX.
- Industrial Automation Handbook, Various Authors, Publisher, 20XX.
