floating point to two int

jimcav

Member
Join Date
Dec 2004
Location
new jersey
Posts
229
Hello Everyone

I am using a ab 1500 and i want to take a floating point value ie F8:0
and turn it into two int., n7:0 to the left of decimal and n7:1 to right of decimal. example if i have 16.0025 i want n7:0 to = 16 and
n7:1 = to equal 0025. i see a problem with n7:1.

thanks
jim cav
 
Move F8:0 in N7:0.
Subtract N7:0 from F8:0 and multiply by 1000, which can be done with one compute (CPT) statement. AB PLCs (in contrast to many others) will do all the conversion between datatypes for you
 
as far as i remember it rounds...
so if you have 16.058, result would be 16 and 58
but if ou have 16.888 result would be 17 and -112 for example.


(edit)

this means you need two instructions:
CPT N7:0  F8:0 - 0.5

and

CPT N7:1 ( F8:0 - N7:0 ) * 1000

 
Last edited:
Try it this way

BST MOV F8:15 N7:40 NXB SUB F8:15 N7:40 F8:16 NXB GRT F8:16 0.0 MOV N7:40 N7:41 NXB LES F8:16 0.0 SUB N7:40 1 N7:41 NXB LES F8:16 0.0 SUB F8:15 N7:41 F8:16 NXB MUL F8:16 10000.0 N7:42 BND

This way the decimal value is placed in N7:42 and
the whole portion is in N7:41

For example:
16.1234 would place 1234 in N7:42
16.123 would place 1230 in N7:42
16.12 would place 1200 in N7:42
16.1 would place 1000 in N7:42

My example just looks at the first 4 decimal places.
 
Very Nice

Panic Mode,
I like your solution a lot better than mine for the 50* processors but I don't think the 1500 has a compute function.
 
Mark, I think the 1500 can do it with a CPW instruction. I'm not sure on this though because I normally only use 5/01 and 5/03 processors.
 

Similar Topics

I need to check an axis actual travel position, and to compare it to the master travel position. To do this I have to multiply the axis travel...
Replies
6
Views
2,589
We have AOIs for projects, which handle material dosing (by hand or by pipes and pumps), obviously they have comparison between setpoint and...
Replies
50
Views
14,319
Hi eveyone. I need transfer signal from system 1 to DCS via modbus. System 1 only can send 32 bit floating point. DCS receive 16 bit integer. How...
Replies
20
Views
10,687
Hi, In my ladder logic, I've got a data register D60 whose value is -0.001 (when using monitor mode to see values). D406 is 0.250. But then...
Replies
5
Views
1,340
Hi, can anybody tell that how can we move floating point data from one Regiter to another register in Fatek PLC.?
Replies
0
Views
1,574
Back
Top Bottom