5/8/2024 1:50 PM | |
Joined: 1/5/2018 Last visit: 5/14/2024 Posts: 8 Rating: (0) |
Hello everyone, I am currently working with a Siemens S7-312 PLC and facing a peculiar issue related to function parameter handling. I have two functions: one to calculate the area in meters, and another to calculate the perimeter in centimeters. Both functions take two input parameters: length and width, originally given in centimeters. Here’s a breakdown of what happens:
This behavior leads me to question how the PLC handles parameter passing from the M area versus the DB. Specifically, I want to understand:
Any insights into how parameter passing is managed differently between these memory areas in the S7-312 CPU would be greatly appreciated. Additionally, if anyone has suggestions on how to ensure that the M area values remain unmodified when used as function parameters, that would be very helpful. Thank you! Attachment1.pdf (16 Downloads) |
5/9/2024 2:48 AM | |
Joined: 10/7/2005 Last visit: 6/5/2024 Posts: 3008 Rating: (1051) |
Hi geekpirate short answer is that S7-300's and 400's use pass by reference for FC parameters providing their address only occupies 4 Bytes (e.g. M, I, Q & L areas). Fully qualified DB adresses (e.g. DBx.DBWy) on the other hand occupy 6 Bytes and are thus passed by value (via a copy of their value into the local data stack of the calling block). Longer answer of what is going behind the scenes is available in THIS thread. Last but not least, IN parameters should be used as Read only inside an FC. |
Cheers |
|
5/9/2024 7:26 AM | |
Joined: 9/23/2005 Last visit: 6/5/2024 Posts: 4562 Rating: (705)
|
Just to augment the answer from our MVP fritz. This copying of DB value to local stack is done by automatically generated code around FC call and normally it is invisible in an editor. In case of Simatic Manager user is protected from himself by an editor which recognizes such an operation and doesn't allow to compile. In case of TIA, it seems that Siemens developers decided to give users more freedom and they only put a warning in such a situation. See orange colored tag names. Whenever you see it and you do not understand why, it means that unexpected may happen. Then try to adjust your code to get rid of such warnings. |
Regards, |
|
This contribution was helpful to2 thankful Users |
Follow us on