S7 Real to Int ?

PLCdave

Member
Join Date
Apr 2003
Posts
15
Hi, can anyone show me how to convert from a Real to an Int in Step7?
It looks like I use the Round function to convert to a DInt then grab the last two bytes of the DInt and move them to an Int, surely there must be a more elegant way ????

Thanks in advance

PLCDave
 
I simply use "RND" and transfers the result to an INT.

As long as the result can stay within -32768 and +32767 there will be no problems with this approach.
I don't think that there will be an program error if the result is outside these boundaries. Transfer "T" simply moves as many bits from ACCU1 as can fit in the destination adress.

Could be interesting to know, if there is some way of detecting in a check reoutine if some kind of "conflict" had occurred in the program (like trying to transfer a value that doesn't fit in the destination for example).
 
I have not seen a REAL to INT function. Perhaps it is because you have four options: CEIL, FLOOR, TRUNC and ROUND. All 4 function convert a real to a double integer. So, just convert your real to double int and convert your double int to a int. I think the move command will convert a double int to int.
 
Hi
it's the move DInt to Int that I'm not sure about, someone suggested that this might result in the next two bytes after the Int being overwritten with the bytes from the DInt (if this makes sense)
i.e. DInt is 4 bytes Int is 2 bytes so the next variable in the datablock may be affected.
 

Similar Topics

Hi all. Me again still learning Rockwell. So I'll be polling an INT data array from a Modbus SE power meter with a L82 (with a Modbus ProSoft in...
Replies
56
Views
1,344
I seem to be making this harder than it should be, and Its not making any sense. I simply need to move a real variable to two integer variables...
Replies
8
Views
973
Situation: Single [EQU] instruction with single [OTE] on a rung, nothing else/simple. [EQU] operand(A) is a real number data type...
Replies
16
Views
2,577
I work at a cheese factory and we recently ran into a problem where in an older controller they where able to use a REAL Data type in OTU and XIC...
Replies
13
Views
2,569
Hello I have a question about SCL if I have a real value like valor: INT I would do valor : = 1.5 Or this trhow me an error? How can I save...
Replies
6
Views
1,672
Back
Top Bottom