You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old November 12th, 2018, 06:42 AM   #16
JesperMP
Lifetime Supporting Member + Moderator
Denmark

JesperMP is online now
 
JesperMP's Avatar
 
Join Date: Feb 2003
Location: Copenhagen.
Posts: 13,446
Not sure what you are trying to achieve, but you do realise that LW0 and the bool TEMP1 are overlapping ?

One should NEVER use the local "L" addresses such as L0.0 or LW0.
If you see an L address, it is a sign of bad programming habits, or that the block has become messed up.
__________________
Jesper
3 strikes and you're out
  Reply With Quote
Old November 12th, 2018, 07:32 AM   #17
Rob...
Supporting Member
United Kingdom

Rob... is offline
 
Join Date: Jul 2016
Location: Manchester
Posts: 145
Quote:
Originally Posted by JesperMP View Post
Not sure what you are trying to achieve, but you do realise that LW0 and the bool TEMP1 are overlapping ?

One should NEVER use the local "L" addresses such as L0.0 or LW0.
If you see an L address, it is a sign of bad programming habits, or that the block has become messed up.
Couldn't agree more!
  Reply With Quote
Old November 12th, 2018, 08:08 AM   #18
mk42
Member
United States

mk42 is offline
 
Join Date: Jun 2013
Location: MI
Posts: 1,965
rachid29,

Maybe this is a stupid question, but why are you trying to do this?

If you want to monitor the code, can't you just go online and monitor the logic directly?

If you want the internal memory of the FC to be remembered from scan to scan, why not just use an FB?

It feels like you're trying to solve a problem that doesn't exist.

Quote:
Originally Posted by JesperMP View Post
Not sure what you are trying to achieve, but you do realise that LW0 and the bool TEMP1 are overlapping ?

One should NEVER use the local "L" addresses such as L0.0 or LW0.
If you see an L address, it is a sign of bad programming habits, or that the block has become messed up.
I agree that normally this is something that wouldn't be done. However, I think OP is trying to do something crazy, and so is intentionally doing crazy things to make it happen.

Quote:
Originally Posted by rachid29 View Post
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.
I THINK he is intentionally trying to copy out the internal TEMP memory of the FC so that he can monitor it elsewhere in the program, or at least so it can get reused from scan to scan.
  Reply With Quote
Old November 14th, 2018, 06:08 AM   #19
rachid29
Member
Belgium

rachid29 is offline
 
Join Date: Sep 2012
Location: Belgium
Posts: 16
Quote:
Originally Posted by mk42 View Post
rachid29,

Maybe this is a stupid question, but why are you trying to do this?

I THINK he is intentionally trying to copy out the internal TEMP memory of the FC so that he can monitor it elsewhere in the program, or at least so it can get reused from scan to scan.
Thank you all for your replys,

Like I mentioned before, I want to understand how to work with FUNCTIONS.

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.
  Reply With Quote
Old November 14th, 2018, 06:58 AM   #20
JesperMP
Lifetime Supporting Member + Moderator
Denmark

JesperMP is online now
 
JesperMP's Avatar
 
Join Date: Feb 2003
Location: Copenhagen.
Posts: 13,446
Quote:
Originally Posted by rachid29 View Post
You could do this with an FC, a general DB and MOVE instructions that would write results of the FC program in that DB.
No. If you code a move inside an FC, and you use the FC several times, the move will use the same address. This is probably not what you want.

The proper way to have memory with an FC is to use IN_OUT pins, and be sure to place unique addresses on these pins for the different calls to the FC.

It is actually quite simple. Dont make it so complicated. Avoid the legacy variables such as Merkers inside FCs and FBs. If you need memory, in FCs use the IN_OUTs, in FBs use the STATs.
__________________
Jesper
3 strikes and you're out
  Reply With Quote
Old November 14th, 2018, 09:56 AM   #21
cardosocea
Member
United Kingdom

cardosocea is offline
 
Join Date: Nov 2016
Location: Fields of corn
Posts: 1,121
Quote:
Originally Posted by rachid29 View Post
Like I mentioned before, I want to understand how to work with FUNCTIONS.
Say you need to convert Celsius to Fahrenheit. Does it need to "keep score"? No, it doesn't... so you'll go with a function.

Say that you have a block that creates a runtime meter... it gets the running input, the running hours alarm limit and outputs the alarm and the number of running hours. This block will need a timer of sorts, and will need to "keep score" of the running hours. Additionally, this block will be called as many times as motors (for example) as you have in the plant... In this case, you'd use an FB.

A way of achieving a similar result with an FC, is to have IN_OUT parameters. In Out parameters are addresses to variables, so the FC will be touching the contents of a global DB.

Quote:
Originally Posted by rachid29 View Post
Instead a DB, I used a MW.
Never use M memory for writing to it, which means only the Memory bits selected in the Hardware config should be used.
  Reply With Quote
Old November 14th, 2018, 10:40 AM   #22
Jeebs
Member
Belgium

Jeebs is online now
 
Join Date: Feb 2007
Location: Leuven
Posts: 1,041
Quote:
Originally Posted by rachid29 View Post
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.

Seems to be lacking some information/understanding here.

What is a FB?

A FB is a block which can have a instance DB connected to it. When you create IN/OUT/IN_OUT/STAT variables, then that FB will require an instance DB to work. This instance DB will be generated automatically when you call the FB. Your editor will ask you whether it should create it or not in most cases.

NOTE: a FB without IN/OUT/IN_OUT/STAT variables does not need a DB and one will NOT be created for it.

The IN/OUT/IN_OUT data you supply to the FB will be copied to the instance DB. This is why you can leave these parameters empty. Because zero is a valid value.

In your case if you use MW10 as an IN_OUT parameter with a FB, the data from MW10 will be copied to the instance DB at the start of the block. And then copied from the instance DB to MW10 at the end of the block.

TEMP data, or L-data is NOT stored in the DB. This is a data block shared among all other blocks.


What is a FC?

A FC is a block that contains logic. It has no DB linked to it. When you call it no DB will be created.

So what about the IN/OUT/IN_OUT parameters? Well when you use these parameters with a FC, they are created as pointers. If you use MW10 as an IN_OUT then the FC will use #INOUT1 as a pointer directly to MW10 and will read/write directly to MW10 when #INOUT1 is referenced in the code. And this is the reason why FC's must have all their parameters filled in at all times. Because a null-pointer is not accepted.

Because there is no DB linked to a FC it doesn't have any STAT variables.


So how does one achieve FB functionality with a FC?

Manually. You have to manually create a DB with the correct data structure. You'll have to write the code to copy the data to/from the DB.

Code:
OPN DB[#IN1]   // This opens DBxx, where xx is the value of #IN1
L #IN2         // Loads the value of #IN2
T DBW0         // Transfers it to DBxx.DBW0 where xx is the value of #IN1

... some more code ...

OPN DB[#IN1]   // Opens DBxx again in case you've referenced another DB somewhere else in the code
L DBW2         // Loads value of DBxx.DBW2
T #OUT1        // Transfers it to #OUT1 parameter
The code calling this FC might look like:

Code:
CALL FC1
 IN1   := 20   // Opens DB20 within the FC
 IN2   := MW10 
 OUT1  := MW20
In this case MW10 = DB20.DBW0 and MW20 = DB20.DBW2

Achieving the same while using a FB would look like:

Code:
CALL FB1, DB20
 IN1   := MW10
 OUT1  := MW20
Done. No additional coding required within the FB.
  Reply With Quote
Old November 14th, 2018, 11:16 AM   #23
JesperMP
Lifetime Supporting Member + Moderator
Denmark

JesperMP is online now
 
JesperMP's Avatar
 
Join Date: Feb 2003
Location: Copenhagen.
Posts: 13,446
jeebs, you are confusing the guy with using STL code for opening of DBs and manipulating DB words in an FC to mimic an FB.
Stuff like that should be avoided. Keep it simple is my mantra.
__________________
Jesper
3 strikes and you're out
  Reply With Quote
Old November 15th, 2018, 02:58 AM   #24
Jeebs
Member
Belgium

Jeebs is online now
 
Join Date: Feb 2007
Location: Leuven
Posts: 1,041
Should not ignore/dismiss information just because you dislike it. What is shown is exactly what his source is referring to.
  Reply With Quote
Old November 15th, 2018, 04:10 AM   #25
JesperMP
Lifetime Supporting Member + Moderator
Denmark

JesperMP is online now
 
JesperMP's Avatar
 
Join Date: Feb 2003
Location: Copenhagen.
Posts: 13,446
Quote:
Originally Posted by Jeebs View Post
What is shown is exactly what his source is referring to.
I think your code is a correct reply to Rachids suggestion.
But I also think that your code is a bad style !
Essentially, opening DBs and accessing variables by byte offset only, means you have zero symbolics and no type checking. This is a big no-no in my book.

If one absolutely must try to make an FC have memory like an FB, then link to the desired variables via IN_OUT pins. If you have a big structure that would be too much to place on IN_OUT pins, then define the entire structure as a UDT and then make only 1 IN_OUT pin for the entire structure. You get all the structure symbolically. In fact, this is a simple and important method that everybody should learn.

If I posted a suggestion like your code, I would add an advice that even if it is possible to do it like that, one should avoid it.
__________________
Jesper
3 strikes and you're out
  Reply With Quote
Old November 15th, 2018, 06:25 AM   #26
Manglemender
Member
United Kingdom

Manglemender is offline
 
Join Date: Jul 2007
Location: Lancashire
Posts: 1,109
Passing integers as a DB number and then using a byte offset in S7 is often a translation of a block that was originally written in S5.
  Reply With Quote
Old November 15th, 2018, 09:28 AM   #27
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 5,583
If you want to monitor the temp data of an FC (or FB for that matter) copy the temp data to a DB and monitor the DB. Example attached. The size of the local data is available from the block properties.
Attached Files
File Type: zip LocalData.zip (128.4 KB, 3 views)
  Reply With Quote
Old November 17th, 2018, 06:29 AM   #28
Lare
Member
Finland

Lare is offline
 
Join Date: Jan 2006
Location: Finland
Posts: 1,048
Quote:
Originally Posted by JesperMP View Post
Not sure what you are trying to achieve, but you do realise that LW0 and the bool TEMP1 are overlapping ?

One should NEVER use the local "L" addresses such as L0.0 or LW0.
If you see an L address, it is a sign of bad programming habits, or that the block has become messed up.



I would say, use overlapping memory only if you really know what you are doing, regardless of PLC type.

From internet you can find top ten siemens tricks, #6 shows overlapping local memory to pare data.



Better would be to use pointer to memory area on STL or AT commands on SCL.

I think that TIA portal shows at least warning if you use overlapping local memory areas.



https://www.slideshare.net/DMCChicag...cksslide-share
  Reply With Quote
Old November 18th, 2018, 03:39 AM   #29
hill831017
Member
China

hill831017 is offline
 
Join Date: Nov 2010
Location: CC
Posts: 53
For a function you would like to use multi times, in this case you could create FC/FB.
In a old programming style, people use FC+FGDB, this is good if you are often modify the structure of DB, this will not cause any interface change conflict, but you have to make sure in FC you are still read and write to the correct position in the FGDB. Later people use more FB+IDB, this is good especially when you have a clear structure, so that you could use pointer like P#xxx, it's more easy and clear when you write a STL code.
For your case, you could use a MW for retain value, but you should only call you FC once, otherwise other calling of same FC will modify the M value. By the next PLC cycle, M will not be the expect value anymore.
Another issue for TEMP, any TEMP variable you read, should be initialize(Write) before, otherwise it could be also a unexpected value.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Siemens S7 to A-B ControlLogix EtherNet/IP Communications Robert.Yager@vw.com LIVE PLC Questions And Answers 7 January 9th, 2013 03:53 PM
Can someone please explain to me how to use a counter in siemens S7 Dave85 LIVE PLC Questions And Answers 7 August 21st, 2011 09:14 AM
Siemens S5 and S7 Dual Masters for Profibus daveswerld LIVE PLC Questions And Answers 15 December 16th, 2008 03:15 AM
Siemens S7 Indirect Addressing MaxRoberts22 LIVE PLC Questions And Answers 44 July 15th, 2007 04:31 AM
Siemens S7 ethernet protocol fzhang LIVE PLC Questions And Answers 3 May 19th, 2004 01:06 PM


All times are GMT -5. The time now is 10:54 AM.


.