How to monitor #TEMPS of a FC on Siemens S7?

rachid29

Member
Join Date
Sep 2012
Location
Belgium
Posts
17
Hello everyone,

I want to understand how to use a FC with IO VARIABLE and MOVE instruction.
I have make this example but my marker MW 20 doesn't change:

BLOCK: OB1
A I 2.0
= L 20.0
A I 2.1
= L 20.1

CALL FC 2
IN1 :=L20.0
IN2 :=L20.1
OUT1:=Q2.0
IO1 :=MW20


IN 0.0
IN1 Bool 0.0
IN2 Bool 0.1
OUT 0.0
OUT1 Bool 2.0
IN_OUT 0.0
IO1 Word 4.0
TEMP 0.0
TEMP1 Bool 0.0
RETURN 0.0
RET_VAL 0.0

Block: FC2
Network: 1
L MW 20
T #IO1
Network: 2
A #IN1
A #IN2
= #TEMP1
Network: 3
A #TEMP1
= #OUT1
Network: 4
L #IO1
T MW 20

Can you explain to me why MW 20 doesn't change?
 
Look at it from the perspective of assuming nothing changes unless there is a reason for it e to change. What could cause the value to change?
 
Thank you for your reply.

The MW20 has to change when the I2.0 and I2.1 are HIGH, but my MW20 stays at 0.
 
Last edited:
There is no code which would change MW20. Inside FC20 you are reading MW20 to IO1 then on last network output (which isn't changed) IO1 is writed back to MW20. MW20 stays on same than before program call.

You also should avoid to use same memory address inside FC and outside of FC.
Use FB blocks or temp data of FC and then update outputs.If there is need to use marker memorys, then use totally diffrent area.
Ladder is also easerier to code than STL.
 
Your code doesnt seem right.

You have an IO variable on the FC call but then inside the FC are reading and writing the variable hard coded inside the FC. Just transferring the value to itself a few times

There is nothing in your code that would change the value of either the IO variable or MW20.
 
Like i mentioned above I want to understand how to work with FUNCTIONS.
Look at this threat:


An FB is a function that "remembers", or "keeps score" of its last operations.
Both FCs and FBs can hold parameters (IN, OUT, IN-OUT and TEMP), it allows the re-use of the blocks with different calling environments. But FBs have an extra type of parameter: STATIC not available in FCs.
When you call an FB, you are required to generate an instance DB (IDB) that accompanies this particular call of an FB; this DB contains all the STATIC parameters of the FB, and these are available at any time by any other block in your program. You could do this with an FC, a general DB and MOVE instructions that would write results of the FC program in that DB. With an FB it is automatic.

Instead a DB, I used a MW.

How to memorise the TEMPS of an FC?
 
Like i mentioned above I want to understand how to work with FUNCTIONS.
Look at this threat:


An FB is a function that "remembers", or "keeps score" of its last operations.
Both FCs and FBs can hold parameters (IN, OUT, IN-OUT and TEMP), it allows the re-use of the blocks with different calling environments. But FBs have an extra type of parameter: STATIC not available in FCs.
When you call an FB, you are required to generate an instance DB (IDB) that accompanies this particular call of an FB; this DB contains all the STATIC parameters of the FB, and these are available at any time by any other block in your program. You could do this with an FC, a general DB and MOVE instructions that would write results of the FC program in that DB. With an FB it is automatic.

Instead a DB, I used a MW.

How to memorise the TEMPS of an FC?

You could do that. But I feel you are missing the point of an FC. That block you originally posted has no moves to a DB. And you would need to pass input parameters for which/where/what DB or location you want to write to or the FC wont be reusable.
 
Temporary variables for FC can used only inside this FC. Once you finish executing FC all your temporary variables (TEMP's) are lost.

I would like to know:
How to memorise the TEMP's of an FC?
 
Temporary variables for FC can used only inside this FC. Once you finish executing FC all your temporary variables (TEMP's) are lost.

I would like to know:
How to memorise the TEMP's of an FC?

Simple. Use an FB.

Otherwise there are quite a few ways.

Create an interface global DB with a structure and then pass the DB number in and indirectly address your FC.

Use a MW or MD with a structure you write down as an Input/Output declaration then use the bits/bytes for your code in side as an I/O. This way you can declare a different MD/MW for each FC call.

Or, just use an FB.

What is the specific reason for needing to use an FC?
 
I have found the problem, instead to transfer my MW to LOCAL TEMP, I tranferred to the IO.
BLOCK: OB1
A I 2.0
= L 20.0
A I 2.1
= L 20.1

CALL FC 2
IN1 :=L20.0
IN2 :=L20.1
OUT1:=Q2.0
IO1 :=MW20


IN 0.0
IN1 Bool 0.0
IN2 Bool 0.1
OUT 0.0
OUT1 Bool 2.0
IN_OUT 0.0
IO1 Word 4.0
TEMP 0.0
TEMP1 Bool 0.0
RETURN 0.0
RET_VAL 0.0

Block: FC2
Network: 1
L MW 20
T LW 0
Network: 2
A #IN1
A #IN2
= #TEMP1
Network: 3
A #TEMP1
= #OUT1
Network: 4
L LW 0
T MW 20

Thank you for your replys.
 
I have found the problem, instead to transfer my MW to LOCAL TEMP, I tranferred to the IO.
BLOCK: OB1
A I 2.0
= L 20.0
A I 2.1
= L 20.1

CALL FC 2
IN1 :=L20.0
IN2 :=L20.1
OUT1:=Q2.0
IO1 :=MW20


IN 0.0
IN1 Bool 0.0
IN2 Bool 0.1
OUT 0.0
OUT1 Bool 2.0
IN_OUT 0.0
IO1 Word 4.0
TEMP 0.0
TEMP1 Bool 0.0
RETURN 0.0
RET_VAL 0.0

Block: FC2
Network: 1
L MW 20
T LW 0
Network: 2
A #IN1
A #IN2
= #TEMP1
Network: 3
A #TEMP1
= #OUT1
Network: 4
L LW 0
T MW 20

Thank you for your replys.

This is still really bizarre code. Why have the IO variable then directly reference in the FC? And why not just remove TEMP1 and have OUT1 wired directly to your logic?

Maybe my STL is rusty but this code doesnt make much sense to me.
 
How to memorise the TEMP's of an FC?


Use a DB instead of TEMP variables... and one way to do that is, as others mentioned, by using an FB. The other way would be to move the UDT as an InOut parameter.



Also, that code looks strange, buffering makes sense on a global scale, not buffer to a temp and call the function in the line below.
 
@bmw_apprentice:
You have right, I have just used TEMP1 in my code to see how it works.
And the second fault I maked is to use the MB20 (instead of #IO) inside the FC. It should be: (If you copy this code to your STL editor and then use the FBD/LAD editor it will be much clear to understand)

BLOCK: OB1
Network: 1
A I 2.0
= L 20.0
BLD 103
A I 2.1
= L 20.1
BLD 103
CALL FC 2
IN1 :=L20.0
IN2 :=L20.1
OUT1:=Q2.0
IO1 :=MW20
NOP 0

IN 0.0
IN1 Bool 0.0
IN2 Bool 0.1
OUT 0.0
OUT1 Bool 2.0
IN_OUT 0.0
IO1 Word 4.0
TEMP 0.0
TEMP1 Bool 0.0
RETURN 0.0
RET_VAL 0.0

Block: FC2
Network: 1
L #IO1
T LW 0
NOP 0
Network: 2
A #IN1
A #IN2
= #TEMP1
Network: 3
A #TEMP1
= #OUT1
Network: 4
L LW 0
T #IO1
NOP 0
 

Similar Topics

We have a quad monitor setup with FT SE and we are utilizing a header screen at the top of every display. when we open a new page we abort the...
Replies
0
Views
88
Our plant manger/my boss wants each line to display the takt time above the line. I am trying to research the cheapest way to do this. Our plant...
Replies
3
Views
184
Hi Folks, Looking for support and ideas. We are trying to go online to monitor/fault find on an S7-300 programmed with TIA Portal V15. I can...
Replies
9
Views
343
We finally replaced our Cognex Checker with an IV-3 and I'm wondering if can replace the s/w in the monitor with anything else. I haven't been...
Replies
0
Views
97
Im very new to programmin,but i was wanting to try and set up a program that could monitor the speed of a roller. Would it be possible to use the...
Replies
4
Views
151
Back
Top Bottom