Siemens FB & FC

douyi

Member
Join Date
Aug 2005
Location
Toronto
Posts
123
I've been using Siemens for about one year now, and finished several different projects. Because I have more experience on AB, so I cannot get how and what benefit I have using FBs, actually, I can use DB instead of IDB, and feel no difference.

I know form some SFB I have to use that, on top of that, anybody familiar with FB can tell me why you'd like to use FBs?

Can you please tell me the difference as well?

Thanks a lot!
 
the main differece between fc and fb is that you can name the stat variables and use them as marks. If you use a FC with DB, you have to use bits of a DB as marks and they haven´t name.

i.e: FC1 with DB0:

opn #DBnr
***
u #in1
u(
u #in2
o dbx0.0
)
= dbx0.0
****

i.e: FB1 with DB1:

u #in1
u(
u #in2
o out1)
= out1

(out1 is a stat variable)
regards
 
Hi Douyi

This bit about FCs and FBs comes straight out of the IEC6-1131-3 standard. This is well-known and much discussed here and pretty much dismissed by the majority.

In pure IEC-speak, an FC should have only one Return Value, usually signified by Siemens as RET_VAL. Whatever you build it to do, the answer should be expressable as a single RET_VAL. The FC should be regarded as a RET_VAL generator whose answer is only dependent on the input parameters, not stored data. The result of the FC should be completely independent of whether this is the first or hundred-and-first time it has executed.

By contrast, an FB can have multiple output parameters and has its own associated instance data block for holding static variables. An FC has no concept of static variables as jmrcalin has indicated. If you have coded something like a moving average, the result of this does very much depend on how many times it has executed. The data carried forward between successive executions should justify this as being appropriate for an FB with its IDB.

That's 'pure' IEC-speak.

Of course, you can build an FC with twenty output parameters and store loads of data in fifty different data blocks. You can write all your code as FCs, or FBs, or a mixture in-between. So the question is really why didn't Siemens (or anyone else, for that matter) stick absolutely rigidly to the IEC-spec? Commercial suicide, I suspect. I don't know any manufacturer who has signed up for this and forbidden or prevented users to do what they want. We, the customers, demand the right to be wrong sometimes. Of course evry manufacturer has taken different bits of the IEC spec and enforced them more rigidly than others. How they decided which bits were important and which bits weren't we'll probably never know.

Regards

Ken
 
Thanks for replying.

As an example of jmrcalin, the purpose for stat variable is to be accessed outside of current subroutine, but when you access from outside, the format becomes DBx.DBXxxx.xxx again. If I use an external variable, I have more flexibilities.

So, I still can't have that - what's the benefit using FB? (Except using SFB)
 
douyi said:
So, I still can't have that - what's the benefit using FB? (Except using SFB)

Hi

Here is only couple of benefit using by FB's.
1) All the parameters and variables has a memory -> you don't have to transfer data between "memory" DB's and your function.
2) If you have more complicate function -> you don't have to fill all the "parametres" of the function. Look at e.g. PID-controller FB41.
3)You can read/write the FBs parametres directly all over the program.


-Pete- 🍺
 
douyi said:
Thanks for replying.

As an example of jmrcalin, the purpose for stat variable is to be accessed outside of current subroutine, but when you access from outside, the format becomes DBx.DBXxxx.xxx again. If I use an external variable, I have more flexibilities.

So, I still can't have that - what's the benefit using FB? (Except using SFB)

The instance data of the FB is ment to be manipulated only by the FB itself.
You can exchange data by its interface.
 

Similar Topics

HI everyone, i am new to Siemens plc programming and i am in need of some help. yesterday we had an S7-1200 CPU 1214C fail to turn on an output to...
Replies
7
Views
159
Hi PLC people, think about this scenario: The PLC is somehow connected to the same network with the facilities` network. Then someone connects to...
Replies
2
Views
84
Hello everyone, I've had this issue for the last 2 days where I try to assign the profisafe address to an IO block (6ES7 146-6FF00-0AB0) but when...
Replies
5
Views
152
Hello, good morning, I have been having two problems with the Tia Portal software. The first is that I have installed it on my computer and...
Replies
5
Views
184
Hello to all, I'm just starting with using CodeSys. Immediately, I have noticed that Codesys doesn't use data blocks like for example S7 does...
Replies
11
Views
182
Back
Top Bottom