FC vs FB, DB

i'll have to some search Peter, i'm not really sure as i'm a beginner myself but i combined my programming background to what i have understand from along the thread and wrote it in the sum up, so the people can check an amend or complete what is not ... that's it ...

anyway please guys don't forget my questions:

that means the FB & FC once they were called & their outputs status have changed. they will always keep their current state except if they were called again and the state have been changed from within the same FB or FC.

YES/NO ????

+ how to change the DB (variable within) after creation & linking ??? :(
 
Are you talking about "rebuilding" datablock after you make changes to the FB structure?

Two Choices:
1. Delete DB in Manager and create new ones.

2. Check block consistency (Right-Click on blocks folder and then fix Highlighted problems)

Nick
 
to delete the DB's and re-create them is okay...

but amending the FB calls all of them. well i deleted them one by one and recreated them - is there is any other easier way ... :)

Michael
 
LOL, i saw it - but i didn't understand it ...

what u have said "was that english" excuse my ignorence ...
please clearify a little

sorryyyyyyyyyyy
 
'Can you pass a variable number of parameters? I don't think so.'


In the context of what was written before, yes. One of the differences between a FC and a FB is that you do not have to pass the parameter, it can be left blank. Its feasible for someone to do as per example, use the same DB for 2 successive FB calls, if, as stated, on the second call, only one number is entered, the second number will remain as per the first call.
 
I know it's an old thread

I am digging around looking for clarification and details on S7 programming as I have a small "slow down" right now.

When I read this thread I see several things.

First S7 generates the level of confusion that prevents a new user from even knowing what question to ask.

Second, the veteran users of S7 understand it so well they have trouble explaining it to someone who has never seen it.

Several key issues are completely lost and so much detail is given in terms that can't be understood.

Even now that I can use FCs and FBs and multi instance DBs and I understand how and why the DB exists............I still have trouble following this thread.

All kinds of what you could do , just like Hans.

Not enough WHY would you do it that way.

And HOW do you do it that way.


So to turn my post into somethng useful for the next guy we tell to "search the forum":

A FC is a function. Similar to a math function. Where all you need is inputs and an answer. No need to know what happened in between.

((2+3)-4)*6=6

here 2,3,4 and 6 could be inputs or inouts , or just one of these could be a variable input. The last 6 is the output.

In this case because S7 can't use more than 2 numbers at once, (correct me if I am wrong here) We would first have to do 2+3 , put 5 in a temp.

Then 5-4 and put 1 in a temp
Then 1*6 and put the answer in the output.

In STL ( I don't use STL) this looks easier ,load and transfer, but in LAD it would take several temp variables.

Once the program completes the FC all that is left is the output in a memory location.

If you use all defined external memory locations, you can do a lot of things with just FCs.

One issue with FCs is the temp area. It is local and temporary, as in not protected / retained. So once the FC is not active, the temp area is released. The tricky bit is that the temps do not get zeroed out they are just released.

Another tricky bit is when I look at an FC online I frequently get data from a previous FC in the online view. Somewhere I read that the inside of an FC can't be viewed online. I don't see why, but this is the case with so much.

S7 does this sort of thing a lot. Usualy when online, I have to click around the screen to find a spot that allows the data to be visible regardless of whether I am looking at a FB or FC or just a plain ladder.

If an FC is edited after being used in several places, you will need to go to each place and update the block call.

Save program FC and go to OB1 and save , you get an error and any changed blocks will be in red, you may have to go to the S7 manager main window and go to the edit menu then down to "check block consistancey" to see which blocks are changed.

Go to each changed block and right click and select "update block call"

I have also had to open a block and save and download the block individualy.

This is also true if a FB is edited while it is in use in the program.

Now for the FB. Function Block

The simple difference is the stat area as everyone has said.

Why /when do you need an FB?

Anytime you want to keep information locally, and use it the next time the block is called.

In our previous example,

((2+3)-4)*6=6

We could have all these variables come in as inputs or in/outs.

If we use a FB we can keep the result of each operation in addition to the last answer in the output.

2+3=5 stat or inout
5-4=1 stat or inout
1*6=6 output.

Now the 5 stat , 1 stat are in a DB assigned to the FB and can be used in other places in the program.

The down side to this is if you have to edit the FB and you have used the Stat locations elsewhere in your program , the stats will shift and be in different locations so everywhere in your program where you referenced these stats , you have to edit.

This is what I ran into.

Made an FB , stored data in stat area for use in other FBs.

Later had to edit the first FB.

This edit inserted new stats and ins which shifted the original variable around.

So originally I had DB30.DBW16 as a location for a certain variable.

After the edit , this same data was relocated down to DB30.DBW20

The other FBs were still looking in location, DB30.DBW16.

So I began using an external DB and moved these outside the FB so the location for other parts of the program would not have to be changed when the FBs were edited.

So then I moved DB30.DBW16 which is a stat in FB30, out to DB98.

Now the other FBs look to DB98.DBW1.0

There is a lot more detail here on the subject, and after the new user comes to grips with the simple stuff then the details will have a place to stick.

On the STL thing, I just finished a fairly complex program and did it all in LAD.

I did not find at any point that I could not do what needed to be done in LAD.

So my interest in STL is curiosity only at this point. I assume once I understand it better, I will either realize I don't need it, or see how I can use it to make better blocks. By the time I figure out basic STL usage it will be obsolete anyway LOL. Probably get better use from learning C+.

It looks like I will have to use STL to pass a DB address as a parameter, so that is the reason I am looking at it now.

This will be very usefull.
 
Once the program completes the FC all that is left is the output in a memory location.

true, but part of the IO defined could be pointers where info is stored for later.

Another tricky bit is when I look at an FC online I frequently get data from a previous FC in the online view. Somewhere I read that the inside of an FC can't be viewed online. I don't see why, but this is the case with so much.

You may not see where the logic is jumped over (not scanned) or if the FC is called more than once you may not know which call you are seeing the data of.

You can map the path to the call that you are monitoring which means you can isolate the particular call, but you would need the calls to be made from separate locations to view your code (in FB's you can map it to an IDB).

If an FC is edited after being used in several places, you will need to go to each place and update the block call.

Only of you have changed to interface.

The down side to this is if you have to edit the FB and you have used the Stat locations elsewhere in your program , the stats will shift and be in different locations so everywhere in your program where you referenced these stats , you have to edit.

The STATs are symbolic so you should not need to do this.

This is what I ran into.

Made an FB , stored data in stat area for use in other FBs.

Later had to edit the first FB.

This edit inserted new stats and ins which shifted the original variable around.

So originally I had DB30.DBW16 as a location for a certain variable.

After the edit , this same data was relocated down to DB30.DBW20

Did you select to program symbolically?

On the STL thing, I just finished a fairly complex program and did it all in LAD.

I did not find at any point that I could not do what needed to be done in LAD.

True enough, you would only need STL really for indirect addressing using ANY pointers etc.

So my interest in STL is curiosity only at this point. I assume once I understand it better, I will either realize I don't need it, or see how I can use it to make better blocks.

It depends if you want a fast program, STL is lower level code and makes the code more efficient.
 
Just in case Peter hasn't worded his answer forcefully enough, if you get into the habit of programming with Symbolic Priority enabled (in Simatic Manager, "Edit -> Object Properties -> Address Priority (rider)" then set Symbol has priority "For all accesses (I,Q,M,T,C and DB)", the problem with adding STATs just disappears along with a whole load of other problems.

Have a look at this Thread, in particular S7Guy's sample program in post #23, to see how much easier life is when you resolutely use Symbolic Priority.
 
My first: Once the program completes the FC all that is left is the output in a memory location.

Peter: true, but part of the IO defined could be pointers where info is stored for later.

These 2 statements mean the same thing to me. "IO defined" or 'outputs", "in a memory location" or "pointers to where info is stored". Same.




My first:Another tricky bit is when I look at an FC online I frequently get data from a previous FC in the online view. Somewhere I read that the inside of an FC can't be viewed online. I don't see why, but this is the case with so much.

Peter: You may not see where the logic is jumped over (not scanned) or if the FC is called more than once you may not know which call you are seeing the data of.

You can map the path to the call that you are monitoring which means you can isolate the particular call, but you would need the calls to be made from separate locations to view your code (in FB's you can map it to an IDB).


This makes no sense at all. If I open a block and select online , how is it possible that S7 is somehow confused about which data I want to see? How can it be skipped over if it is being executed? Why do we need to re-write something just to stop S7 from putting the wrong data in the online view? I am trying hard to like S7....

"You can map the path to the call that you are monitoring..." So in order to see what is happening in a FC online, I have to put each one in an isolating FB and then use an IDB for each one?????????? Why not just use FBs to begin with?
I accept that this is the case, I just stopped expecting to see anything usfull in FCs online and switched to using FBs for all but the simple things.



My first: The down side to this is if you have to edit the FB and you have used the Stat locations elsewhere in your program , the stats will shift and be in different locations so everywhere in your program where you referenced these stats , you have to edit.

Peter: The STATs are symbolic so you should not need to do this. (But not priority over absolute as we discover later.)


I keep hearing things like this. Symbolic is on by default, even when I turn it off to change an address, it comes back on after I close the block. So it is always on when I open a block and when I make a new block. However when I have to make a change, the symbol is not available in the DB drop down list to select as it does not display everything in the DB in the list.

I still have not figured out the pattern to this. All the stats have symbols , but not all show up. The DB is named, if its not named the whole DB doesn't show up in the list. So many times I have to use the actual address by turning symbolic off. Of course right after I enter the address it displays the symbol which is quite irritating. I would prefer S7 not do so much automatic switching. It is as if it suddenly realizes the address has a symbol after I use the complete numerical address. The only reason I do it this way is because I have to.



Peter: It depends if you want a fast program, STL is lower level code and makes the code more efficient. I would be interested to see some data on this. I imagine the difference is around 10% but that's just a WAG based on looking at STL and the STL generated by LAD.

I would hope the ladder is compiled into a similar code as STL when downloaded into the PLC processor. I guess you can make more direct comparisons and leave out some steps in STL that are needed in LAD.




RMA: Just in case Peter hasn't worded his answer forcefully enough, if you get into the habit of programming with Symbolic Priority enabled (in Simatic Manager, "Edit -> Object Properties -> Address Priority (rider)" then set Symbol has priority "For all accesses (I,Q,M,T,C and DB)", the problem with adding STATs just disappears along with a whole load of other problems.


See that is specific and very usefull advice right there. Mine was set to use the symbols but the Absolute had priority. (upper left selection)

Without your specific advice I would have thought I was using symbolic addressing, and I was, it just wasn't set to take priority over the Absolute.


Have a look at this Thread, in particular S7Guy's sample program in post #23, to see how much easier life is when you resolutely use Symbolic Priority.


This will make several things easier,

Thanks Peter and RMA,
 
You have to forgive me if I'm not specific, I don't have access to S7 anymore, on this side of the pond I'm stuck with ControlLogix (trying hard to like it).

With regard to the path to the FC, it can be done, someone else may have to point to the correct drop down and selection.

There are two methods to isolate your multiple called blocks, one is to state which DB you want, this can be your IDB and makes FB's easier to monitor.

The other is to specify a path (map), like OB1-FC3-FC5, then you will see only the blocks that are called from that path, this is where FC's can be isolated, but if the FC is called more than once from that exact path, then its not a great help.

By logic jumped over, I meant jumped over within the FC, not an FC that is not called.
 
Which side of the pond?

You have to forgive me if I'm not specific, I don't have access to S7 anymore, on this side of the pond I'm stuck with ControlLogix (trying hard to like it).

I did not mean to imply that your advice was not valuable, (it is very much so) ,just that frequently veteran users make reference to methods which seem like a small pile of words. And while they are decidedly correct in grammer and usage, seem to be completely foreign.

With regard to the path to the FC, it can be done, someone else may have to point to the correct drop down and selection.

There are two methods to isolate your multiple called blocks, one is to state which DB you want, this can be your IDB and makes FB's easier to monitor.

I see no place to specify which DB I want. I call an FC and it has no DB to specify. I am using the FC inside a FB so if any DB is to used I would think it would be the DB of the FB.

In the case of the IDB, I thought it was the default DB for the associated FB?

I suspect your advice is tailored for STL and may not be the same when using LAD.


The other is to specify a path (map), like OB1-FC3-FC5, then you will see only the blocks that are called from that path, this is where FC's can be isolated, but if the FC is called more than once from that exact path, then its not a great help.

I suspect this is useful in STL but may not apply to LAD.

I am opening OB1 then FB1 then FC1 but I don't see any other way to get there.





In my program , I have a FB.

FB1 lets call it. FB1 is called in OB1.

I have a FC. Lets use FC1. FC1 counts time and gives a pulse when the time is counted and incriments a counter.

Inside FB1, FC1 is called 5 times , each time using a different timer and counter and a different time value. Each counter is reset as needed.

When looking inside the third FC1 , I see data that is from the previous FCs.

This is all in LAD.

This is just one example of this , I have seen it over and over through out the program.

I have stopped trying to see what is happening in FCs even though it looks as if it should work.(and would be nice if it did.)

I just looked in the DB for FB1. Only a couple of STATs are there and these numbers are the current count of the counters.

Is it true then that all else is being done in an undefined temp area?

I am having so many AH HA moments lately I can't keep up.

So , if this is true then what we see on the screen are ghosts of data past?

As long as it works and I understand that it wont display the correct values, I wont get hung up on "why".

I managed electron theory OK , I use the same perspective with S7.

Sometimes the level of detail required to understand the "why" of S7 is just so involved I lose track of what the question was.


The point of this last post is just to understand FCs a little better and the online viewing of variables.

Thanks again Peter.
 
Without Step 7 in front of me I cannot explain too well.

I believe the option maybe in debug or test menu, can't recall which, also it can make the scan time longer whilst monitoring in this way.

from your example above then it would not help, 5 FC's called from the same block would not be able to be isolated.

Say you had only 1 instance of FC1 in FB5, another in FB3 and another in FC6 and each of these were called from OB1.

You could set the path to OB1, FB5, FC1 and you would only see the data in FC1 when it had followed that one path, that one instance, no ghosts.

Then you could do the same and set a path for OB1, FC6, FC1 and again you would only see the one.

It doesn't work where it is called multiple times.

What I have done in the past, where I could not lay a path, is to copy and paste the FC as a new FC and change the one call to see what is happening at that point, and revert afterwards.

For an FB you can alternatively, from the same menu, stipulate an IDB, therefore if the same FB is called multple times from the same block (providing they don't share an IDB) you can isolate that 1 FB. Yes the TEMP's don't make sense but the STAT's do.
 
Without selecting the path S7 displays the FIRST instance of a FC. Thus if you use FC10, 50 times the first one is display when you monitor inside the block.

You can use the editor to select the call path. My trick is to use a dummy block at the top of Step 7 and monitor it. Ie run the block you want to monitor twice...if possible.
 
Back
Top Bottom