SIEMENS SIMATIC S7-300 PLC Programming Course, Chapter 2
In Chapter 2, we are going to deal with the PLC's hardware configuration in STEP7, online diagnostics, updating the hardware catalogue, the structure of the program in a project in SIMATIC Manager and, finally, STEP7's diagnostic function for the S7-300 PLC.
This SIEMENS SIMATIC S7-300 PLC Setup & Programming Course is being developed in collaboration with the company FOXON s.r.o. The number of course parts/chapters offered will depend on the interest of the public as well as the amount of information to be provided. A detailed description of all the features and all the programming operations lies outside the scope of this course.
The main focus is on the practical aspects of PLC setup and the most useful programming tasks for beginner and casual users, who need to grasp the basics of Simatic PLCs. The course is also designed for those who come into contact with a range of PLCs from various manufacturers, but lack the time and resources to receive comprehensive training in all of them. With this audience in mind, we encourage you to share your idea of the topics to be explored so that we can customise the course parts for you.
If you do not have access to a PLC that you could use to try the steps described, for most of the tasks the SIEMENS PLC simulator will suffice (i.e. you will only need a computer and this software).
FOXON s.r.o. & Jaroslav Blažek, blaja.cz
SIMATIC S7-300 Hardware Configuration, STEP7 Project Structure, and Diagnostics
In this and the next chapter/s, when I talk of opening a station's hardware configuration editor or the STL editor, what is meant by that is I always open it in the SIMATIC Manager. There are also other ways to open these editors but doing so via the SIMATIC Manager is the best option for us now.
As with any other PLC programming software, in STEP7 you first need to create your PLC's hardware configuration. This means that in the hardware configuration editor, selecting from a comprehensive hardware catalogue that contains PLCs, modules and SIMATIC PLC parts, you create exactly the same SIMATIC PLC configuration as the one that will be physically deployed on the factory floor.
Important: If you are experiencing difficulty with any of the settings, feel free to use the Help function (available under the Help button or the F1 key on your keyboard). You will get context-sensitive help for the selected menu command.
Here you can see our CPU – the SIMATIC S7-313C. It features integrated analogue and digital inputs/outputs, which is ideal for the purposes of this course.
Known under the code 6ES7313-5BE00-0AB0, it has these specifications:
Compact CPU with MPI port, 24 DI/16 DO, 4 AI, 2 AO, 1 Pt100, 3 high-speed counters (30 kHz), integrated power supply 24 V DC, work memory 32 KB, Micro Memory Card required.
In the SIMATIC Manager, create a new project and specify the directory to which the project will be saved. In the project, insert the SIMATIC 300 Station.
In the project's structure on the left, under SIMATIC 300(1) you can find the inserted station. By clicking the station's hardware, open the hardware configuration editor.
Note: Any of the names can easily be changed to suit your needs. For example, our demo project is called 313_kurz (i.e. 313_course).
The hardware configuration editor's dialog consists of three panes. The main pane is the top left pane, which is now empty. In the bottom left pane, you are provided with details about added components. And in the right-hand pane, you can find the hardware catalogue that you select components from.
All SIMATIC parts are installed on a special rail. So first you need to select this rail from the catalogue and by dragging and dropping it add it to the top left pane.
Note: The hardware catalogue is updated with every STEP7 upgrade. It can also be updated via the Internet or the update can be copied to your computer from another computer. I am going to show you later.
When you have added the rail, from the catalogue you can now select our CPU – CPU 313C – and add it to the configuration. Feel free to experiment with the editor. You can try adding or deleting whatever you want or change the order of the parts. If any of the combinations that you would like to try is not possible, the editor will prevent you from performing the operation.
Note: The fact that the editor will prevent you from performing certain operations is the reason why it is often used for checking that your PLC's hardware configuration is feasible.
By clicking on the CPU, you will get a very important dialog with the PLC's properties. Feel free to explore the individual tabs. One of the most important ones is the tab Cycle/Clock Memory, which enables you to set the memory byte (e.g. to number 1). Each of the memory byte's bits is assigned a frequency (0,1–10 Hz). While the PLC is in operation, the individual bits occur periodically at their assigned frequencies. In the Scan cycle monitoring time (ms) box, leave the default value of 150 ms. This function means that when the cycle time in the box has been exceeded, the PLC will report an error.
Note: For new CPUs, 150 ms is a long enough time. However, with older CPUs you often had to enter a higher number because if you did not you would get PLC errors. It is thus important that you check if the cycle time of your PLC agrees with the Scan cycle monitoring time value in this tab.
Another important tab is the one called Cyclic Interrupts. It specifies how often certain organisation blocks will be started. For example, the organisation block OB35 in the PLC program will be triggered every 100 ms. You can adjust the time as well as the priority.
When you have checked CPU parameters, you need to set the addresses and parameters of individual inputs and outputs, analogue signals and the counter. If your hardware configuration contains more parts than those on the right, setting the parameters and addresses of the entire PIW/PQW area will take more time. I recommend that you carefully consider the choice of these parameters and addresses so that your addressing is not chaotic. To set the counter, I encourage you to use the Help function. It describes the settings very well.
Note: Addresses can be changed at any time in the future. But remember to change them in the PLC program as well.
You can now download your PLC's hardware configuration to your PLC. Before you do that, the configuration needs to be compiled. What this means is that it needs to be converted into the format that the PLC understands. To compile your hardware configuration, click the Save and Compile button. If the compiler reports an error (usually an incomplete configuration), you have to correct it and compile your configuration again.
Note: Compilation errors are often caused by inconsistent configurations or missing modules in the configuration. You can try simulating this by inserting any module into the wrong slot and starting the compilation.
When you have compiled your hardware configuration, the last step is downloading it to your PLC. The topic of connecting to a PLC is covered in Chapter 1, so this should not be a problem. If you are using the PLC Simulator, you have to download your hardware configuration to it in the same way as you would to a normal PLC.
In the hardware configuration settings, there are many more functions to explore. In this subchapter, I have dealt with only the settings that you need to be familiar with.
Using STEP7 and its hardware configuration editor, you can directly connect to the CPU to detect potential hardware problems. To do that, you only need to be connected to the CPU that is to be tested.
If everything is OK, in the online view next to the CPU you can see a blue symbol. If there is an error, this symbol is red.
In the case of a simple hardware configuration, like the one here, there are rarely any problems. However, when you have a large configuration including PROFIBUS nodes, being able to see the status in the online view is a great help when finding faults.
By clicking on the row with the CPU, you open a dialog called Module Information, which is a very important functionality. Nevertheless, as you usually access it via the Simatic Manager, it is going to be dealt with later. If there are any problems, the Module Information dialog is the only place where you will find the information that you need. The individual tabs contain all the essential information. For example, let us see what the actual cycle time of our CPU is.
Note: On the time axis of the cycle time, you can see a maximum value of 150 ms, which is the value that we checked in the CPU properties dialog in the Cycle/Clock Memory tab under Scan cycle monitoring time.
The following is a common scenario. You try to open a project from another author, created in an unknown version of STEP7. You get a warning which says that there is a missing part in the configuration. However, you cannot make any changes to the configuration because you are in read-only mode. If you want to avoid having to update your STEP7 all the time, you can simply update the hardware catalogue via the Internet or via the folder on your PC that the hardware updates are already saved to.
Note: To add some modules to the hardware catalogue, for example Siwarex weighing modules, you first need to install the required software application.
Start the hardware catalogue update by going to Options. The catalogue does not get updated directly but through a software tool that you run when you click on Install HW Updates…
Note: On successful installation, click Update Catalog.
The Install Hardware Updates dialog is a software tool for obtaining the latest data for the hardware catalogue and installing it in STEP7. First, you need to set this tool, especially the directory to which the downloaded updates will be saved and the path to it. Simply create a new directory, for example HWUpdates.
Note: On downloading the latest updates, you can copy the directory onto a computer that does not have Internet access and update the catalogue on that computer as well. In such a case, you will copy the data from disk.
When you have completed the settings, download the updates. The whole process may take a while, depending on your connection speed. Note: Right now we are downloading data to a pre-defined directory, not to STEP7.
Check the boxes next to the hardware updates that you want to install. Choose carefully because the installation cannot be undone.
Before installing the selected components in the catalogue, all STEP7 applications need to be closed. The installation tool will do that for you.
On successful installation, you will get this message.
As regards the hardware catalogue, this is it for beginner users. Let us now go back to the Simatic Manager and explore the updated catalogue.
Our entire STEP7 project (i.e. our entire program for the Simatic PLC) is graphically displayed and organised in a structure of individual project directories. Each part of the program has its own place. Object code can be found in one place, while symbols are located elsewhere. Let us now look at what the project structure contains and other related matters.
Important: Again, if you are not sure about a particular block's number or its function, feel free to use the perfect help function by pressing the F1 key.
In the CPU 313C folder, which was already added to the project folder before (on successful completion of the hardware configuration), you can see the S7 Program (1) directory. In it you will find an important file called Symbols, which is a table that contains symbolic names of variables and addresses. The table is empty now. We are going to complete it later.
Note: The Symbols file can be copied into other projects by simply dragging and dropping it. You then do not need to create it from scratch if you need exactly the same symbols in another project.
The folder Blocks is the most important folder of the entire project. It contains all the program components that you create or copy. You can see that it now contains only a single program block – OB1. This block represents the highest programming level and organises the other blocks in the S7 program. It is a Cycle Execution block that other blocks are called from.
The program that the PLC executes consists of various program blocks – OB, FB, FC, DB and others. To insert these blocks into a folder, simply right-click and under Insert New Object select the requested block. I am going to explain their functions later but for now you should remember the following:
- OBs = control cyclic and interrupt-driven program execution, startup behaviour of the PLC and error handling
Note: A detailed description of the function of each OB block can be found in Help.
- FBs = blocks with a "memory" which you can program yourself
- FCs = contain program routines for frequently used functions
- DBs = data areas for storing user data
- UDTs = user-defined data types
- VATs = variable tables into which you can enter any of the program's variables and monitor their status
Let us not forget about system functions and system blocks. I am going to show them to you in a slightly unusual way. By clicking the icon in the red box, switch to online mode (this also works when using the simulator). After some time, you will see all system functions and system blocks contained in the PLC. Each of them is designed to execute a function or a mathematical calculation. The PLC contains a large number of these blocks. They cannot be deleted. It is up to you if you want to use them or not. You enter them into the program from libraries that are part of STEP7 (in offline mode).
Note: By clicking a system block and pressing the F1 key, you will get a detailed description of the block including its parameters. Try that!
Before we start creating a program and explore all the various functions of the Simatic PLC, it is essential to learn more about STEP7's diagnostic function called Module Information. I already mentioned it when talking about online diagnostics in the hardware configuration editor. It is a very useful troubleshooting functionality – if the CPU goes into STOP mode or you have a different problem, Module Information is exactly the function to use.
You can access this function by right-clicking and selecting PLC --> Module Information or by pressing Ctrl+D.
Note: To use this function, you need to be in online mode. It is available in the simulator as well.
Let us now explore the essential information in the Module Information tabs.
In this tab, you will find some general information about the CPU and other connected modules, such as order numbers and firmware versions.
This is probably the most useful tab. It shows CPU status by time. If there is an error, this is where it will say what the problem is. You can also take advantage of the Help on Event function, which will give you more information about the error that you are dealing with.
If you are experiencing problems with downloading your program to the PLC, one of the causes might be occupied memory. The memory does not necessarily have to be full. What sometimes happens is that after deleting and reloading blocks, gaps can occur in the user memory. These gaps can reduce the usable memory area. In such a case, you can use the Compress button, which rearranges the existing blocks in the user memory, removes the gaps and creates a continuous free memory. You can imagine it as a quick defragmentation of your disk and a delete of temporary files.
Here you will find a list of all system blocks and functions including their short descriptions. On the left you can see OB blocks, while on the right there are SF blocks. Below the blocks you will find the address area with all the address types and their sizes. For example, you can see that this CPU features 256 counters and 256 timers and that the highest Bit Memory address is M255.7.
Note: If you choose an address outside the address area, you will not be able to download the program to the PLC. This is a common problem that programmers face.
In this chapter, we have explored such topics as the PLC's hardware configuration, the structure of the STEP7 project and diagnostics via Module Information. In Chapter 3, I am going to explain to you how the CPU processes a program. In addition, I am going to show you the first steps of S7-300 PLC programming.
Author: Jaroslav Blažek, blaja.cz