INT to REAL GE RX3i

NetNathan

Lifetime Supporting Member
Join Date
Nov 2011
Location
Corona, CA
Posts
2,199
I am reading in 2 integers as (Low and High). I need to swap the integers and convert to REAL.
Any ideas..how to do this in Machine Edition (ver 9.5)?

ME will let me build it by moving the integers into position using 2 new integer (%R) and doing a move of 2 into real...but then Validation chokes because I cannot use a "Move Int" to a Real

What I am doing now...
Data in as R1 (low) and R2 (high)
Move R2 to R3
Move R1 to R4

Now integers are in correct order with R3 as High and R4 as Low.

Now.... how to make real?
Convert to DINT first?
 
There are two SWAP instructions in the function set. SWAP_WORD interchanges the bytes in a 16-bit WORD. SWAP_DWORD interchanges the words in a 32-bit DWORD.
I'm not sure what you need to do to get to a floating point number. If you are reading in two INTs in the wrong order, then perform the SWAP followed by a DINT to REAL conversion. If the two 16-bit entities you're reading are supposed to be interpreted as floating point but they're out of order, then perform the SWAP which will have to have a DWORD variable as its output. You'll need to create another REAL variable with the same address as the DWORD output of the SWAP instruction to interpret the bits as IEEE-754 floating point.
 
Yes...when I am done I need Real, I have data behind the decimal point to monitor.
I forgot about SWAP_DWORD. I Will try.

In GE aren't a Word and an Integer the same at 16bit?
So confusing sometimes dealing with Word and Integer commands.
 
Last edited:
In GE, INT is a signed 16-bit, WORD is unsigned 16-bit. Consequently INTs have a range of values between -32768 and +32767 when you're viewing the data. WORDs have a range of values between 0 and 65535.
How do I combine 2 integers to make a DINT or REAL?
There are a couple of cases to consider.
First, if the DINT value is 12345678 and the two INTs are 1234 and 5678, the easiest way is to convert both INTs to DINT or REAL, multiply the one with a value of 1234 by 10,000 and add the second to the result. Note that the INT_TO_DINT instruction is only available in the Rx series. The 90 series doesn't have INT_TO_DINT, but it does have INT_TO_REAL and REAL_TO_DINT.
Second, the DINT value 12345678 will have a value of 24,910 in the low word and 188 in the high word. If you're faced with that situation, all you have to do is create a DINT variable with the same address as the low word.
 
Thanks for the clarification of INT and WORD.
Yes...I am on an RX3i.
Let me play around with your suggestions.
 
Steve,

I tried some of your ideas, but could not clear up.

Here is what I originally made that uses a "MOVE INT" of 2 into a REAL.
It chokes on validate with "type mismatch" on the last "MOVE INT" in each rung but it works.

Attached is the UDFB that was built.
You can import it in.

It is based on Profinet data from an ABB VFD.
I am using the same logic on converting Volts , Amps, Power, RPM, and Hz.
 
Last edited:
Here is an example of what I was suggesting. I don't have an Rx3i, so I can't use the SWAP instruction, but it works on a 9030 CPU374 with the MOVE_INT instructions.
The REAL value in %R103, %R104 is 123.456. The data in %R103 and %R104, interpreted as 16-bit INT is -5767 in %R103 and 17142 in %R104. As you can see, I have two different variables assigned to %R103. One of the variables is an INT, the other a REAL. As long as you select the correct variable in subsequent calculations, you'll get the correct value.
 
Here is an example of what I was suggesting. I don't have an Rx3i, so I can't use the SWAP instruction, but it works on a 9030 CPU374 with the MOVE_INT instructions.
The REAL value in %R103, %R104 is 123.456. The data in %R103 and %R104, interpreted as 16-bit INT is -5767 in %R103 and 17142 in %R104. As you can see, I have two different variables assigned to %R103. One of the variables is an INT, the other a REAL. As long as you select the correct variable in subsequent calculations, you'll get the correct value.

That looks good....
BUT.....
RX3i will not let me have 2 variables with the same Address....so... won't that be an issue having 103R as INT and REAL?

Here is what I am using now...
All are INT except "P" which is real.

RX3i-UDFB-Data.png
 

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,354
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
975
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,579
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,573
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,673
Back
Top Bottom