Step7 - Global variable + FirstTimeScan

Dariusch

Member
Join Date
Sep 2003
Posts
284
Hi!

I am new to Siemens Step7 and are hoping for some little starthelp, Thanks.

I have made some FB, but would like to know if it is possible to use a variable defined in "Symbol Table" in any FB I have created??

Also do I have to make my own "First time scan" flag or is there some sort of system bit, that I can use?

Thank you

Dariusch

Edit//
By using the variable in FB I would like to know if it is possible to use ex. M100.0=Motor in a FB without using the "IN" for the FB.
Just by writing "M100.0" or "Motor" in my code in the FB.

But I also think if it is possible, that it would be hard debugging program if one dont know where the variable is used.

Thank you again

Dariusch
 
Last edited:
You can use (global) symbolic names in an FB example motor = M100.0You can enter 'motor' and you will see that global symbolic names become represented by STEP7 as "motor".

FB-parameters have also names but they get '#' before their name.
 
So if I write "Motor" in many diffrent FB they all act to the "Motor" from the OB1 for example?

How if I write to a global variable in many diffrent FB's. Will the var. be taken the status ("1" or "0") from the logic in the last FB then?

Dariusch
 
Yes; all FB's act on the same global variable "motor"

Yes; as a result of this only the last result of "motor" will be used for further logic.
 
If you want to know where every bit, timer, counter, ect. is used you can do this by opening the Block-folder in the Simatic Manager and choose;

Options / Reference data / generate

and then

Options / Reference data /display

In the subprogram 'Ref' you can switch between different reference data if you choose 'view' and change to a different subject that you want to see
 
1 more question.

Do I have to use a "global var." for exchange signal between different FB's or can I use the internal var. in FB1 and use it in FB2 with the same name?

ex. If I declare #Test_FB1 in FB1 as an output, could I use the exact name in FB2 as an Indput??

Thank you

Dariusch
 
Hello dariusch;

Any variable you create inside a FB (or FC) and use with a # is a local variable; it only exists inside this FB or FC. You cannot use it to exchange data between FBs. You should use global variables (as per the definition you were given earlier).

One exception: Static variables could be accessed through the instance DB generated with a FB; but that is a little beyond the scope of your original question.
Hope this helps,
Daniel Chartier
 
Hi Daniel Chartier

The accesing to the DB and use it in an other FB would I like to here a little more of.
If you ar kind enough to tell me how I can exchange an INT from FB1 to FB2 for ex.

I am doing a program controlling some band conveyor.
Currently I have made 10 FB
1. FB1 Alarm handling
2. FB2 Motor control
3. FB3 Start metode 1 for conveyor
4. FB4 Start metode 2 for conveyor
5. FB5 Start metode 3 for conveyor
6. FB6 Start metode 4 for conveyor
7. FB7 Start metode 5 for conveyor
8. FB8 Calling of a tablet
9. FB9 Weight
10. FB10 Check-in

I have to get info from the different FB's so if you have a good idea of exchanging data I am lisen

Thank you

Dariusch

Edit//
Is it also possible to use the FB6(Also with the DB6) in the FB8, when I have used the FB6 in the OB1.?
 
Last edited:
Hello Dariusch;

You could try this (easiest method, especially for debugging):

-Create a stand-alone DB, one that is not an instance of any of your FBs;
-Configure it with all the data you need to exchange between FBs;
-Read and write from this DB when you want to exchange data between your FBs.

For example; say in your FB4 ("start method 2 for conveyor") you set alarm conditions for your motor. If you have create DB20 ("Data exchange") with a BOOl value dbx2.2 == "Alarm conv_2 Fail_to_start" (for example), simply activate this bit DB20.dbx2.2 in FB4, and use it in FB1 ("Alarm handling") as input logic in your program.

You can call FB6 from any function or OB in your program. However, unless you are completely sure that both calls are not overlapping in time, I would suggest you use DB16 (for example) as an instance DB for the second call. You can have FB6,DB6 and FB6,DB16 running in parallel. If you use the same instance DB you have a chance that the values in the DB are overwritten by those of different concurrent calls.

hope this helps,
Daniel Chartier
 
Thank you Daniel,

That it a good idea, using a standalone DB for all the communication between FB's. I will go for that.

But I still not quite sure about the FB6 call.
How can the same FB be executet at the exact same time???

I think if I call the FB6 in the 6.Netwerk and again call the the FB6 after I have called the FB8 in netwerk 10. and the call of FB6 in the FB8 is made in the end of the FB.
So they would not be called at the same time.

Dariusch

Edit//

Btw if I should use a standalone DB for comm. between FB's. Then I could use the "Global variable" as well.
What is the argument for using the DB instead of the "Global".

Dariusch
 
Last edited:
If you want to use global flags for remembering results, then your number of flags is 'very' limited. DB's have more 'space' for remembering results.
 
Ok. Thank you

I stille like to know if this is good programming practice or is ther a better way of doing it?
If you use a DB for communication between diffrent FB, it could be diffecult to know where the flag came from!?
Or how about naming the flag with the DB ex.
"DB100_AlarmMotor1Trip" then you know it is from the DB100, but then again you dont know where the flag is used.
 
Let say you have FB1 with output Out1 and FB2 with input In1 then it's possible to:
1)
Code:
CALL FB1
Out1:=FB2.In1

or

Code:
CALL FB2
In1:=FB1.Out1
 

Similar Topics

Hopefully someone can validate my thoughts on the following: I'm looking at a proposed program design for a line which will be with us early next...
Replies
13
Views
7,062
Hi Experts, I'm trying to connected 2 PLCs through Ethernet and define Global Data between them. Is it possible? Why the "Define Global Data" item...
Replies
7
Views
4,022
This is the first time I am working with Simatic Manager Step7 as I started my siemens journey with TIA which is pretty easy and do a lot of stuff...
Replies
3
Views
143
When you download a DB, the values get overwritten by what is in the "actual" column in offline DB. Does this happen at the start of the PLC...
Replies
6
Views
142
Hello Inside a FB, I´m trying to transfer a string from a DB to a IN_OUT var that was define as a UDT. The problem is that i can´t determine the...
Replies
4
Views
128
Back
Top Bottom