Convert 4 Long to Float with Micrologix 1400

pautorras

Member
Join Date
Oct 2012
Location
Barcelona
Posts
18
Hi all,

I'm communicating with a modbus device which sends data in 32 bits data.
You can see the structure in this example:
N7:4 MW810 swap: enter c_conv_index
N7:5 MW811 swap: enter c_conv_index
N7:6 MW812 swap: decimal c_conv_index
N7:7 MW813 swap: decimal c_conv_index

I read modbus words and I put it in N7 map. Then I move two N7 words (N7:5 to n7:54 and N7:4 to N7:55 to swap the integer part) and the same with (N7:7 to N7:56 and N7:6 to N7:57 to swap the fractional part).

Then with instruction CPW I convert the 2 integer words N7:54 and N7:55 to long L10:7 (integer part).
Also with instruction CPW I convert the 2 fractional words N7:56 and N7:57 to long L10:8 (fractional part).

The result:
Now I have the integer value on L10:7 (25) and the fractional value on L10:8 (23658016).

The problem is that I need a float value of (25,23658016). I have tried some things without success.
I have tried with a CPT to divide and add the integer part: L10:7+(L10:8|100000000) to a float F8 but I have an error saying that "Operand sizes do not match!".

Could you help me? Do you know how to solve this problem?

Thanks in advance.

Pau
 
Change the CPT expression to - (L10:8|100000000.0)+L10:7

Note the added '.0' in the constant divisor. This forces the operation to floating point. The order insures that the addition will also be in floating point. (My copy of RSLogix500 changes the constant to '1E08')

Also note that a 32 bit float will probably not be able to hold all the precision implied by a 32 bit integer coupled with a 32 bit decimal portion. The resultant decimal portion of the float will probably be shortened. If the final value is critical it would be better to hold the two Longs for an external SCADA process, which may have 64 bit floats, to process.
 
Last edited:
Force the type cast to float before the computation occurs instead of after.

Try (L10:8|100000000.0)+L10:7


Edit: I see Bernie beat me to it.
 
Hi Bernie and TConnolly,

Thanks for your answers.
I still have the same problem.
5937625620621355153

https://plus.google.com/photos/1119...ms/5937625620621355153?authkey=CPnLuKSo17u8Tg

I use RSLogix Micro Starter.

If I put 100000000.0 it converts to 1E08 too without .0 ending.
I have tried to put L10:7*1.0 (it's a * not +). Also without this I have the error.

You don't have any error?

Thanks!
 
The Logic500 compiler can be a bit too rigid sometimes, it just doesn't seem to like having an L word in the CPT expression if the destination is not an L address.

It seems it also doesn't like it in the first position of discrete math instructions when the destination is not an L address.

So lets start with a MOV to move the Long words to floats.

MOV L10:7 F8:101
MOV L10:8 F8:102

and then rewrite our compute statement.

CPT F8:62 (F8:102 * 1E-8) + F8:101

I tested that and it verified just fine.

I inverted the constant because multiplication executes quite a bit faster than division.
 

Similar Topics

I have an Allen Bradley MicroLogix 1400. I am trying to display a value onto an HMI, however my HMI will not accept a Long (i.e. L10:2) as an...
Replies
6
Views
10,592
Hi all, I am communicating with a modbus device which sends data in 32 bits format. The MSW represent the integer part of the value and the LSW...
Replies
3
Views
5,582
Using Logix 500 with a AB Micrologix 1100, I need to convert a 5 character string to a long. example 99999(string) to 99999 (long). The function...
Replies
7
Views
3,188
Hello all, I'm currently working on a servo motor linear positioning system (ball screw). I'm all set up regarding communication between my HMI...
Replies
1
Views
92
I have an application using an incremental encoder and then I convert it to degree (0-360) using calculation program. For a while, the calculation...
Replies
8
Views
291
Back
Top Bottom