Siemens S7 return overloading

LilleCarl

Member
Join Date
Oct 2013
Location
Skövde
Posts
4
Hello!
I just got a task in school on controlling a motor (frequency thingy, idk the english name for it)

Anyhow, so i wrote up a FC function to convert scales, as the frequency thingy uses 4k hex as max value, whereas the rpm then would actually be 1375.

I wonder if there are any way to overload the returns (without creating multiple ones) To return "any" (word, int, dint, real) type.

With multiple return values i must use a temp var to catch the unused types, but functions such as move uses overloading. Is this something you can do, or is it some "s7 secret function"

Regards, Carl Hjerpe!

PS: No you're not doing my homework, this is more then expected :p
 
Hej Carl.

Siemens PLCs uses strict and fixed typechecking. Overloading isnt possible. You could theoretically try to handle multiple types in code, but I think it will be a mess.

And for what purpose ? Get used to write PLC code that uses fixed types. It forces you to think about what you do and how to do it.

In your example, the input to the scaling function would be an INT (no, not a WORD), and the output would be REAL. You could also program it so the output will be an INT, but that would be a poor scaling function.

The MOVE instruction doesnt use "overloading" as such.
MOVE "blindly" transfers the content from one memory register to another.
If for example a DINT register is MOVE'd into a REAL register, the content in the REAL register will be garbled.
 
Just as a curioso, I can mention that AB PLCs actually support "a kind of" overloading.

If for example a multiply (MUL) instruction has an integer value and a floating point value as input parameters, the multiplication will be done with floating point precision. If the output is an integer, the resulting floating point value will be rounded to an integer.

So in short, in AB floating point takes precedence over integers.
 
Thank you for your answer Jesper!

I think it's kinda sad that you cannot do something like overloading.

If i would've done this in C++ (i am programming come basic c++ as a hobby, nothing serious)

One base function using floating point.
Functions with the same names converting to and from float with proper rounding and conversions.

Coming from computer programming to programming PLC's is very odd, it feels like i am handicapped! Haha!

About PLC's, i can't really decide what PLC to use, we have one S7 model in school. That's about it, i'm just bit of a perfectionist.

To make things easier i guess ill write up a "library" to convert between all possible siemens types.

Thanks once again for the quick answer! :)
 
To make things easier i guess ill write up a "library" to convert between all possible siemens types.
If you program in LAD or FBD, there are already functions to convert between types.
See the "converter" folder in the instructions library.
In SCL there are also a lot of type conversion functions.
 
If you program in LAD or FBD, there are already functions to convert between types.
See the "converter" folder in the instructions library.
In SCL there are also a lot of type conversion functions.

I'm doing ladder, but lets say i wanna convert from int to real, then int -> dint -> real is really uncool, making functions for those conversions was what i meant! :)
 
Hej Carl.

I think you are making a complex solution to something that is already fixed. Just to tell you what I do:

Everywhere in my program I use 'engineering values', i.e. REALs.
Analog process values (INTs) have to be converted to engineering values (REALs) just once. There are standard functions to do the scaling for you, FC105 SCALE and FC106 UNSCALE.

In the (very) rare case that I have to convert an INT to a REAL in LAD, I write a few STL lines, like this:
L "IntVal"
ITD
DTR
T "RealVal"

If I have to convert from a REAL to INT, I do like this:
L "RealVal"
RND
T "IntVal"

Notice in the above, there is no check if for example the converted REAL value can fit in the INT. This has to be checked or taken care of by other means.

For more complex calculations I use SCL. Everything is REAL. For the rare case that I have to convert I do for example:

"RealVal2" := "RealVal1" + INT_TO_REAL("IntVal1) ;
 
Coming from computer programming to programming PLC's is very odd, it feels like i am handicapped! Haha!

:)

If you started off by studying machine code/assembly code rather than a high level language then you would find it very natural.

In AB you can multiply a real by an int and it assumes that you wanted a floating point calculation but what if you actualy wanted the calculation to be done as an int?

Happy learning,

Nick
 
Hej Carl.

I think you are making a complex solution to something that is already fixed. Just to tell you what I do:

Everywhere in my program I use 'engineering values', i.e. REALs.
Analog process values (INTs) have to be converted to engineering values (REALs) just once. There are standard functions to do the scaling for you, FC105 SCALE and FC106 UNSCALE.

In the (very) rare case that I have to convert an INT to a REAL in LAD, I write a few STL lines, like this:
L "IntVal"
ITD
DTR
T "RealVal"

If I have to convert from a REAL to INT, I do like this:
L "RealVal"
RND
T "IntVal"

Notice in the above, there is no check if for example the converted REAL value can fit in the INT. This has to be checked or taken care of by other means.

For more complex calculations I use SCL. Everything is REAL. For the rare case that I have to convert I do for example:

"RealVal2" := "RealVal1" + INT_TO_REAL("IntVal1) ;

Converting int to real isnt really uncommon if you do this frequency controller tasks we're doing atm, we're working with scaling values etc.. Then you want precition, but imho the only reason we did this is because we want REAL output, and converting inside the function was too much!

Anyways, i've gotten more then all the answers i was looking for! Thank you a lot guys!
 
Converting int to real isnt really uncommon if you do this frequency controller tasks we're doing atm, we're working with scaling values etc..
Like I said, you have to do the scaling just once per value. Really, it is a non-issue.

Then you want precition, but imho the only reason we did this is because we want REAL output, and converting inside the function was too much!
I dont understand what you mean.
 

Similar Topics

Hi, I need to send a command from a S7-300 with a CP341 in ASCII format (RS485). I can get the command to send fine, what I need to do is add...
Replies
1
Views
6,245
if i used a conditional RETURN -(RET) [or BEC (Block End Conditional)] at the start of an FB, and the RLO of the RET network is ONE. 1. are the...
Replies
2
Views
2,500
I have established an online connection to a machine using an S314 processor. I am using an mpi connector and simatic manager. The online...
Replies
2
Views
37
Hi everyone, i have a Siemens S7-300 Cpu 314C-2 DP with several cards of i/o and servos my laptop has TIA version 16 and 17 loaded and...
Replies
4
Views
132
Hi all, Currently having trouble getting a speed reference to write over modbus to an Omron M1... I can successfully write a run command and...
Replies
6
Views
212
Back
Top Bottom