creating function blocks siemans s7

darren.s

Member
Join Date
Apr 2005
Posts
46
hi,
just a beginner with s7 having problems understanding how create and use your own function blocks for a sub routine.
i know its simple stuff for most people and the answer may be to long in the tooth to explain but if anyone can give me some tips or hints id be appreciated.

regards darren
 
Darren, you're asking a very general question that would take a book to do justice to. What have you tried so far? Also, have you done a search on this site? Several of us have done some pretty detailed descriptions of FC and FB applications, along with code examples.

Just to get you started, a general rule of thumb is that OB1 is used as the "root" of your program, from where your "canned routines" (i.e. FCs and FBs) are called. But FCs and FBs can also be called from other FBs and FCs as well. Tell us what you are trying to do, and we'll be glad to help.
 
problem with fc

hello s7 guy.
thanks for the reply you gave.
i understand some basic principles with s7 but there are still one or two simple things i cant get my head round wondered if you could help?

if i come across a piece of code in an (fc) as below

A DB92.DBX 0.0
A DB92.DBX 0.3
A I 1.7
= #TEMP4


A #TEMP4
AN DB92.DBX 1.2
= #TEMP3

with a declaration table as below

address declaration Name TYPE
0.0 temp TEMP0 BOOL
0.1 temp TEMP1 BOOL
O.2 temp TEMP2 BOOL
0.3 temp TEMP3 BOOL
0.4 temp TEMP4 BOOL

with reference to the code i understand that #temp3 is refering to the info in the declaration table. and it can be used anywhere in the (fc) but what i dont understand is somewhere it must have an absolute address.
when =#temp 3 is true what bit is turned on.
if i can get to grips with this everything else will fall into place.
hope that makes sense. if im totally going in the wrong direction could you point me the right way.
ive looked all through different bits of code and still got nowhere

thanks in advance
darren
 
As far as I understand it...

Create an FB. Then go to the top of the block (when editting it) until your mouse pointer turns to two parallel lines. Click and drag down and voila! there's your Variable Declaration Table.

Fill in what variables you want to pass into the function block. Ins / Outs/ Ins and Outs/ Temps and Stats. Temps are temporary variables only used within the FB. Stats are static variables that won't change (minutes_In_An_Hour = 60 etc)

Then write your code as normal but use a # in front of all the variable names. ie. #minutes_In_An_Hour etc

Variable names must be unique and are case sensitive.

Once you've written your code, go to OB1 or wherever you want to call it from. From your program elements on the right, open the FB folder and select your FB.

This will then allow you to add what addresses you want each of your inputs and outputs to be. It will also ask for a DB name. Just type in DBx (replace the x with the DB number). If that DB doesn't exist it will create it for you. The Data Block will then be an 'instance' of the Function Block...

Hope that clears some things up.. as I said at the start I may be slightly wrong with parts of that, but thats how I understand it.

JT
 
Just read your other post... I'm not sure where you will find the value of #TEMP3 but I don't think it matters as #TEMP3 only exists within that FC so you can just address by typing its variable name. OR, you could "move" it into another location that is global and can be accessed from other parts of your code.
 
when =#temp 3 is true what bit is turned on.

In this case, it would be L 0.3. But usually when we work with local data, we don't really care because it is good practice to use local data symbolically. There are cases where you can use local data absolutely, but I would not recommend it for a beginner. Trust me, it will bite you sooner or later.

Variable names must be unique and are case sensitive.

That was the case in very early versions of S7 (pre 1998 or so), but no longer. You don't have to worry about the case anymore.
 
Originally posted by darren.s:

what i dont understand is somewhere it must have an absolute address.
when =#temp 3 is true what bit is turned on.

I'm not a big S7 user so others may correct me on this.
#temp3 has an absolute address ONLY IN THE CONTEXT OF A SPECIFIC CALL INSTANCE. It is temporary memory assigned by the processor firmware when the function call is made. The memory is released when the function is complete. So #temp3 may occupy one physical memory address on one call and a different physical memory address on the next call. You cannot count on a TEMP variable having a consistent value from call to call. So make sure to equate your TEMP variables to something before using them in a given function.

Keith
 

Similar Topics

The idea here is to provide for a brief rapid influx of message codes while preventing sequentially repeating the same message. i.e. if two...
Replies
23
Views
661
In function block programming I am wanting to be able to select from 4 different flow meter tags to point to an equation depending on the mix tank...
Replies
1
Views
2,811
Hello everyone, In a factory where we installed Citect 7.20 the computer began to show the first signs of end of life. They never considered...
Replies
0
Views
70
Hi everyone, I'm a last year student at the university in Ghent, and for my thesis i need to write a TwinCAT program that writes data to a .daq...
Replies
0
Views
135
When I go to create a new module in Studio 5000 I can't enter any information for the IP Address or change any other fields. Is there any fix to...
Replies
1
Views
249
Back
Top Bottom