STL - Step7

naserals

Member
Join Date
Dec 2003
Posts
61
I'm .NET Framework senior programmer but I really failed to understand the whole story of programming in STL. I want to understand the technology very fast. I purchased Automation with Step7 in STL and SCL. I know that the code is event-oriented but how OB, FB and FC communicate with each other.

Let me tell you what I understand and correct me if I'm wrong.

The PLC's operating system keeps looping through OB1. OB1 contains all events that should be maintained and how PLC would handle these events. In order to make our program well organized we divide it into Function Blocks. Also, we have DB or Data Blocks which represent Functions parameters. Global Verialbles are defined in VAT which can be used by the whole program.

I'd better post an example so that you guys can tell me if I'm doing fine or not.

Let's assume that we have two inputs (e.g. level sensors) and two outputs (e.g. green light and engine). The system can be in automatic mode or manual mode. engine will be switched on if both level sensors are on and only if the automatic mode is on.

So in VAT we would write the following:

//OB1
I 0.1 "Sensor1" BOOL
I 0.2 "Sensor2" BOOL
Q 4.0 "Green_Light" BOOL
//OB1
I 0.3 "Automatic_On" BOOL
I 0.4 "Manual_On" BOOL
//FB1
I 1.0 "Switch_Engine_On" BOOL
I 1.1 "Switch_Engine_Off" BOOL
Q 5.0 "Engine_On"

in DB1 ("EngData") which is going to be used by FB1, we would write the following:

0.0 in Switch_Engine_On BOOL
0.1 in Switch_Engine_Off BOOL
5.0 out Engine_On

in FB1 ("Engine") , we would write the following:
A "Switch_Engine_On"
A "Automatic_On"
S "Engine_On"
O "Switch_Engine_Off"
O "Manual_On"
R "Engine_On"

in OB1, we would write

A "Sensor1"
A "Sensor2"
= "Green_Light"

Call "Engine", "EngData"
Switch_Engine_On := "Switch_Engine_On"
Switch_Engine_Off := "Switch_Engine_Off"
Engine_On := "Engine_On"

--------------------------

Please also let me know how operating system would communication with OB2, 3, etc.

Thanks for your help
 
Hi naserals,

engine will be switched on if both level sensors are on and only if the automatic mode is on.

In the program you switch the engine on if automatic mode is on and the start switch is in start position. Where are the two level sensors that should be also on??

You have probably thought that the call for FB1 wont be executed because you have put the "Green Light" output before that. Thats where youre wrong. Include level sensor inputs before setting "Engine on"

Also when resetting "Engine On" you should start with A "Switch Engine Off" instead of O "Switch Engine Off"

Thats what I found out with a quick look before going to sleep.
 
Helo Naserals;

The PLC's operating system keeps looping through OB1. OB1 contains all events that should be maintained and how PLC would handle these events. In order to make our program well organized we divide it into Function Blocks. Also, we have DB or Data Blocks which represent Functions parameters. Global Verialbles are defined in VAT which can be used by the whole program.

You pointed out that you are a .NET programmer, and you use C-programming terms. Please note that PLC programming is not event-based, but logic based. You do not wait or expect events to control the program flow. You scan a program cyclicly and establish logical connections of different inputs (and internal logic) in order to control selected outputs.

Now, Siemens Step 7 programming blocs are divided into these types:

-FCs (and FBs, which are the same as FCs but have a specific DB attached to contain static variables of the function) are use to program modular blocs of logic, repeatable and re-addressable (through parameters) to distinct outputs; they are equivalent to procedures or subroutines.
-DBs are memory blocks that are adapted to the requirements of the programmer; they are the equivalent of a STRUCT in C, and are used in a similar fashion. You do not know the exact memory location that the operating system will use when the DB is calle; all you have is a pointer to the start of the STRUCT (its symbolic name or its DB number) and the offset and length of the required variable. All variables created in a DB are available as global variables. Local variables are defined in the declaration tables of the FCs (or FBs) as TEMP variables.
-VATs are only display structures to allow you to validate the state and values of the variables in Runtime; they are not used for programming, but for debugging.
-OBs are programmable, but never called by the user, only by the operating system as required. OB1 is the equivalent of the main() procedure in C, but it is called cyclically so the programm is processed continuously. All other OBs act like what we called "interrupt vectors" in assembly language: small blocks of programs preassembled and located at specific memory areas, and called by the operating system to respond to certain events (logic or harware error, time interrupts, addressing errors, first scan...) occur. Each CPU has a specific number of OBs available; in the Step 7 world, there are no OB2, OB3, for example. You will find all available OBs for your CPU in the properties of the CPU, either in online or offline mode.


Hope this helps,
Daniel Chartier
 
Dear Daniel,

Thank you very much indeed, that exactly what I wanted to know.

Let's assume that I have a PLC which is already configured to do specific tasks. If I decide to add a new third party device, let's say continues measuring sensor. When we conntect this device to the PROFIBUS-DP:

For testing purpose, we would like to make sure that the device is working fine, do we for example create VAT or use existing VAT to add the address of this device and monitor the readings? How would I know which address to assign to this device?

After doing this test and making sure that data is readable. We go ahead and create DB that includes the address of the above device. If we want to do a logic about it, then we create FB or FC and we call this FB/FC from the existing OB1.

I'd like to emphasize on one point here. Do I have to upload the current PLC configuration and do some changes in it or I can create a new program to do the new changes. Does creating DB or VAT affect current program?

I know I'm giving you a hard time here since I'm asking very basic questions. Please execuse my background, I'm not a guru like yourself.
 
Hello Naser;

I will give you answers as simple as possible, so that you can try them out easily. Please feel free to request more precise information as needed.

How would I know which address to assign to this device?

The I/O address is generated by the HW Config editor once you have inserted your device as a Profibus-DP slave on the graphical representation of the bus line (steps include importing the *.gsd file for your device, selecting the device in the hardware catalog [Profibus DP, Additionnal field devices (probably)], dragging the device to the bus line and selecting an adequate Profibuas address).
Clicking on the slave will open the I/O address window for your device, where you will be shown the I (input, reading from slave to master) and Q (output: writing from master to slave) addresses selected for you.

Say the HW Config editor has selecte I addresses 512...515 (no Q addresses). That gives you 2 words of analog data that you can read in your program as PIW512 and PIW514. Note that unfortunately Siemens does not allow you to use the peripherical addresses PIWxxx and PQWxxx directly in a VAT Table; to monitor the values, use an FC to transfer (MOVE) the data from PIW512 to either an MWxx address or a DB word type variable that you can create at will, and monitor these addresses.

Once you have validated the Profibus-DP data transfers, you can use the PIWxxx addresses directly in your program, for Compare or Math operations.

Using a VAT table has no effect on your program; it is never downloaded to the PLC, and only exists on the programming computer for debugging purposes. refresh rates will depend on your type of physical connection to the CPU (PC-adapter, CP5511, CP5613...).

Using a DB will of course impact on your program, as you use it to store data; you will have to address the required variables either in absolute form (db12.dbw22) or symbolic form ("Archive_DB".LoadCell_1).
This of course implies that you have created a DB12, that there is av 2-byte (Word or INT) variable starting at offset 22.0 named Loadcell_1, and that the symbol table has matched DB12 to Archive_DB.You must also make sure that the DB has been downloaded to the CPU.

Yiou will need to have an available Harware configuration to be able to insert new devices to the Profibus-DP. Thic<s can be uploaded from the CPU, but you will have no symbolic information for the devices (unless the CPU has the project saved on a Flash-Eprom on the CPU); it would be easier if you open the project on your computer to do the changes, then dowload it to the CPU.

Hope this helps,
Daniel Chartier
 
Thanks again Daniel. Well presented procedure.

So, each third party device comes with *.gsd file. Does it belong to the load cell or the JBox?


Note that unfortunately Siemens does not allow you to use the peripherical addresses PIWxxx and PQWxxx directly in a VAT Table; to monitor the values, use an FC to transfer (MOVE) the data from PIW512 to either an MWxx address or a DB word type variable that you can create at will, and monitor these addresses.

Would you please furnish me with an example?

The I/O address is generated by the HW Config editor once you have inserted your device as a Profibus-DP slave on the graphical representation of the bus

The I/O address will be generated automatically once added to the bus. So, why do I need an expert to help me out in doing that?

Thanks again for your support.
 
Hello, Naser;

The *.gsd file will come with the element that contains the Profibus communication chip (ASIC); in your case, I would assume it is the JBox.

In STL, a MOVE instruction is split into a Load and a Transfer instruction:

L PIW512
T MW124

or

L PIW512
T DB12.DBW22

In LAD or FDB there is a MOVE instruction Box (look in the instructions catalog)


Your last question leaves me a little edgy. Why indeed would you need an expert to help you out? I would like to point out that that is exactly what you are doing through this forum, consulting people with more experience in certain fields than you have. We do it gratiously, to help out programmers who need just a little pointer, a new idea or specific information. But we are not responsible for equipment or people at your plant; you are, ultimately. You can damage property and injure personnel if you are not careful with your machines and their control. An expert can help you shoulder responsabilities and accelerate development times. You are in no obligation to use their services. but please do not denigrate their skills or their usefulness to your project. Because by doing so you cast a shadow on our own expertise, mine and others on this forum. We have gained that experience through much work and time spent on machine controls. We have solved problems that you have not tackled yet; that is what an expert is useful for. If you think you are able to program your Profibus communications yourself, go ahead, and best of luck to you.
We will still be here to help out if (and when) you face a major problem.
Daniel Chartier
 
Just one correction:

You can monitor peripheral inputs with a VAT table. It's very useful when looking at things like the control bits and current count of a counter card, for example.

But it's true that PQs are off limits.
 
Dear Daniel,

I think you didn't get my last question. Someone has told me that I need an expert (in site) to help me doing device addresses assignment. That's why I was wondering why should I need an expert in site to do that while it's gonna be assigned automatically.

You've been of a great help. I really don't find the right word to thank you.
 
One thought on the addressing question is that whoever you were talking to was refering to the device Profibus address as opposed to the S7 peripheral word address. Most Profibus devices I have come across have a physical Profibus addressing method (rotary switches, DIP switches, etc). However, some of the more intelligent devices (scales, cameras, drives, etc) have their addresses adjusted by software. This is where someone may need to come in with the appropriate software to set an address.
As for your original question, you are correct. If you feel you have the ability to correctly write the general logic in the plc, I don't think you need any special knowledge to handle the peripheral word addresses, as this is done automatically.

Keith
 
Hi Daniel,

If I add a DP Slave to the PLC Hardware Configuration and the I Address 512..519 (4 Words) was assigned to the DP Slave. To read the data received by the DP Slave, do we have to read every word like
PIW 512
PIW 514
PIW 516
PIW 518
or we just read the first word PIW 512?

If we need to read every word, how do we end up with a meaningful data? How do we read inputs with say 32 words?
 
Another question Daniel.

You're almost the only one in here who knows what my project is all about. Do you recommend special training to me? What training do you recommend to me? where?

What do you think of the following:

1. S7 Programming I.
2. S7 Programming II.
3. S7 PROFIBUS.

Do I need something else to build PIC or maybe OPC Server/Client is good enough?
 
I haven't actually tried this on a plc but Step7 lets me do it.
Instead of using the PIW reference, use PID, which would indicate a peripheral input double word. You can then do what you need to with it. If that doesn't work you can do something like:
L PIW512
T MW50
L PIW514
T MW51
L MD50
T ??

This will let you use two consecutive words as a double.
Also be careful with byte and word order in your Profibus transfers. Depending on the slave device you may need to swap one or both of these to get meaningful data on the word and double word level.

Keith
 
Last edited:
Thanks Keith.

Sorry for this question but where do I do the MOVE procedure? in the OB1 itself?

sorry again for this question.
 
You can put the moves in OB1 or any function you are sure is running. Just to keep common code together I usually do stuff like this just before I use it. However, there is no technical reason it couldn't be done anywhere.

Keith
 
Last edited:

Similar Topics

Hi guys! I was wondering why I've seen some guys put a lot of NOP in their STL code. For example: CALL FC4 NOP 0 What is the purpose of this...
Replies
12
Views
3,640
I am checking codes for transferring a double word in an array based on an index. STL codes are mostly ended with DBD[AR1, P#0,0] or D[AR1...
Replies
1
Views
2,314
O m0.0 O m0.1 A m0.2 = m0.3 Is the m0.2 "and'd" only with the m0.1 or is it "and'd" with m0.1 and m0.2 (which are or'd)? -{}-----|--()...
Replies
3
Views
1,702
The process of converting LAD to STL is upon me. The Bit Logic Instruction: A( And with Nesting Open, saves the RLO and OR bits and a Function...
Replies
3
Views
2,685
Can you help me with "generating" pointers? I have INT variable and I want to create pointer based on variable's value. For example var=30 =>...
Replies
2
Views
1,692
Back
Top Bottom