In my previous articles I've covered installing and licensing the TIA Portal software, setting up and configuring the CPU and I/O modules, as well as compiling and downloading a program, and then going online with the S7-1200 CPU.
With those necessary first steps out of the way, I'm able to get down to doing some programming, which is the fun stuff.
As with any control system that is new to me, learning the terminology and ways of accomplishing what you would like to, takes both time and effort.
Reading through the manuals, browsing TIA Portal, reading help and searching online for examples and questions are all means of learning a system.
To get started, I needed to come up with some sort of project that would make sense to fellow controls engineers and readers of the blog, while being as simple as a first program should be.
I also wanted something that could be built upon in future articles.
What I decided to do is program the S7-1200 to run a home lawn sprinkler system. This would allow me to utilize the Function Block feature, and once created re-use it over and over for each sprinkler/zone in the “lawn” of the project.
Step 1 – Creating a Function Block
By clicking “Add New Block”, you have multiple options for different types of blocks that can be created. In my first creation, I decided to create a Function Block that would execute the logic for running each sprinkler zone.
I named the Function Block “Sprinkler_Zone” and it is shown in the below screenshot:
- This Function block will monitor parameters that ensure that the sequence is active, and the current step is active. It will then start a timer that will operate the sprinkler until it is completed. When the timer completes, it will provide an output to continue to the next step.
Step 2 – Creating Data Blocks
In the same way that I created the Function Block, I am creating two “Data Blocks”. These data blocks will contain arrays.
One data block is called ZONE_PRESETS and this array will hold all the Timer Presets for how long each sprinkler zone will run.
The other data block is called ZONE_ELAPSED and will contain the placeholders for the elapsed time that can be monitored while each zone is running.
Step 3 – The OB1 Main Routine
In my main routine, I am creating a simple sequence. This will be started with a memory bit or an input from a key switch and will be reset either manually with a memory bit or will reset at the end of the sequence.
I also created a counter that will keep up with the step of the sequence and correspond to the zone of each sprinkler. ( Example: Step 1 = Zone 1, Step 2 = Zone 2…etc.. )
Step 4 – Inserting the Function Block
- This is where I can now use my Function Block in the Sequence. When I insert the function block, I can connect all the different variables that are different for each zone.
Local Inputs to the Function Block:
- The FB must monitor that the SEQ_ACTIVE is “TRUE”
- The FB must monitor that the current step is active
- I bring in the ZONE_PRESET Array value for this step so that this Zone will run the needed amount of time. (Allows the user to run each zone for different amounts of time)
Local Outputs from the Function Block:
- The ZONE_ELAPSED timer value is returned to the array and can be monitored
- The Actual Physical Output (Q) is written to the assigned output for each Zone.
- The Pulse to go to the next step becomes active when the Zone finishes running.
I have six of these “Sprinkler_Zone” instances (Function Blocks) inserted into my networks with their respective data blocks.
This allows me to have six instances of the Function Block Running instead of the eighteen networks it would take to accomplish the same logic.
Finally, I have a network that increments my step counter as each zone finishes.
I have tested the logic and it steps through and runs my sequence. The next step is to begin my HMI project and have ability to better monitor and interact with the system. More will be added to this system later, but this is a starting point.
Written by Brandon Cooper
Senior Controls Engineer and Freelance Writer
- PanelView 800 – Datalogging and Trending - August 10, 2021
- PanelView 800 – Using the Recipe Feature - August 3, 2021
- SIMATIC HMI Basic Panel – Using the Recipe Feature - July 27, 2021