When we develop programs in any application, it’s important for the project to be as efficient, as consistent, and as accurate as possible.
Something that Siemens has incorporated into their PLC’s to help with efficiently is the ability to create Function Blocks.
I have shown this one time prior in my first programming article for the S7 1200. Now I want to take another look at the function block and maybe get a little further into the details of it.
In this example, I want to create a function block for a pump that will be a non-reversing starter application.
It will only have one output for a run command, with no direction changes, speed controls etc… and will only have a couple of alarms built into the function block.
Creating a Function Block
By Clicking “Add new block”, I will select “Function block” and give it the name “Pump_Standard”.
Function Block Logic
I’m going to display the logic that I added for this simple pump for display of what can be accomplished that I would need to incorporate into every pump that I would want to program, but this isn’t intended for real- world use and a little disclaimer: I don’t guarantee it for use in production. An instance in production would probably contain much more than this.
Inserting the Function Block Instance into my organizational block
Here, I insert my “Pump_Standard” into my “OB1” organizational block.
This is where I connect the attributes within my block (Local Inputs/Outputs) with real world inputs and connections that will be different for each Pump/Motor that I would need to program.
This Pump will be Data Block “Well_Pump_1” and I will also create a “Well_Pump_2” data block instance.
From now on, when I need to add a new Pump/Motor to my system, it will be done with one network (Although, it is likely I would add a second network-as shown below- for motor interlocks as interlocks can be complex).
This is a look at my function block when online. I can give each pump/motor a different “Feedback Time” if needed.
The Aux Feedback would normally be a real world digital input, but here I am doing simulation, so it is a memory tag. I have three HMI buttons for start/stop/reset that I will be adding to my HMI Project as will follow.
Function Block Tags
Any tags that I would connect outside the function block would be local inputs/outputs and any tags that would stay inside the function block would be static tags.
HMI – Adding the Pumps
Of course, I need to add my two pumps to an HMI display.
Well Pump 1 is running in this Live HMI display. Well Pump 2 is not running and has an alarm that would need to be reset before restarting.
Coding with function blocks creates efficient, consistent, and accurate templates that make life easier when maintaining and troubleshooting the system in the future.
They make code simpler by having one block perform the exact same function instead of having to create the same lines of code over and over. This certainly goes beyond a single starter application.
Think in terms of a VFD. If you have many of the same drives that bring in the same data, you can create a function block of that VFD that brings in all the available parameters, alarms and data exchange with that VFD. You could potentially save thousands of networks of code if programming many VFDs.
Written by Brandon Cooper
Senior Controls Engineer and Freelance Writer
Sponsor and Advertise: Get your product or service in front of our 75K followers while also supporting independent automation journalism by sponsoring or advertising with us! Learn more in our Media Guide here, or contact us using this form.
- Rockwell Patch Rollup – How To Download and Install (2022) - August 4, 2022
- Studio 5000 – Resolve .Net Framework 3.5 Installation Error 0x80D05001 - July 26, 2022
- Studio 5000 – v34: What’s New - May 9, 2022