Convert Floating point to Interger

Scorpio

Member
Join Date
Mar 2004
Location
I am here... Not there
Posts
2
Converting Floating point to two integers in PLC 5

I am working with AB PLC 5 and a Laser Control System that will only pass data via Integers.

When I need 32 bit integers I receive data in two words, which is easy to convert to a floating point to see actual data.

When I need to SEND a 32-bit word I do not understand how to convert this to two integers.

Example Reading Data:
When I reach my set point, the laser sends me the location in MM
N12:3 = -22151
N12:4 = 2
I convert this to a Floating Point
F8:0 = 174458

Another example is
N12:3 = 23921
N12:4 = 1
F8:0 = 89458

So as I have all my locations stored in a separate Data Table, I intended on simply moving the floating point value of the location, calculating the correct integers and sending these to my laser. Easy pleasy… But I can’t figure out the conversion…

Any help would be appreciated… (A LOT)

Ummmm I have been cookied so long at work with the board here, I forget my password... :)
I used to be called Rsviewrulz... Just so ya all know I have been around a little while.. (long enough to be forgetful)

Thanks...

Sam
 
I've done this on a SLC500 using its math register but I don't know how on the PLC5. Maybe you already know this stuff but I'll summerize. To get the upper level integer (your N12:4) divide the floating point number by 65536 and keep the integer portion of the answer in N12:4. Now Subtract this integer portion of the answer (N12:4) from the full quotient leaving only the fractional part. Multiply this fractional part by 65536. Now you have a number between 0 and 65535. If it's 0 - 32767 then you are ok, store this in N12:3. However if it's over 32767 then you will have to subtract 65536 from it, getting a negative number, storing it in N12:3.
 
I don't have PLC5 to try now but here is idea:

Use COMPUTE instruction with result going to float.
LES N12:3 0 CPT F8:0 (N12:4+1)*65536-N12:3+1
GEQ N12:3 0 CPT F8:0 N12:4*65536+N12:3+1

I am not sure if you need +1 at the end of second line
 
hey Contr_Conn

Looking at the logic... that is converting the Two 16 bit Intergers to Floating point....

I need to convert the floating point to two integers

Thanks guys.... I appriciate the input... I am playing with Bernie's idea now...

thx....

Sam
 
I see, I did not read your message correctly ;)

Use the same CPT instruction to do oppisite like reccomended in previos post.
 
maybe this will help ...

Greetings, Scorpio,

this same type of problem (but for the SLC platform) came up on another forum not too long ago ... the approach I’m attaching below seemed to work in that case ... maybe it will help you too ... the basic idea is to use a recursive loop to evaluate the floating point number and break it down into its corresponding binary bit pattern – and to spread that pattern over two consecutive 16-bit words ... the fundamental approach is the same “successive subtraction” method used in classroom lectures to teach binary conversions ... using binary locations for the output words (example: B10:0 and B10:1) allows us the major advantage of using indirect addressing for each successive bit in the pattern ... that greatly simplifies the transition from one word to the next ... using integer locations (example: N12:3 and N12:4) will not allow this simple transition ... you can always move the B words into the N words if your application really demands (not likely) the use of “integer” locations ...

here is a quick screen shot of a Custom Display Monitor that will give you some basic instructions ...

[attachment]

I’ll attach the actual program file in the next post ...

please post again if this is not exactly what you need ... we can also add the capability to handle negative numbers, etc. if your application needs them ... there are also ways to “speed up” the conversion by eliminating the XPY (X to Power of Y) instruction and using a basic (and quicker) division instruction instead ...

finally ... one advantage to this approach is that it lends itself to MANY other types of conversions ... including types that the PLC’s “built-in” conversion instructions aren’t always capable of handling ...

hope this helps ...

f_to_n_rsp.jpg
 
Last edited:

Similar Topics

Hi. If this is the wrong forum i apologize.. inserting a Float value to sql... I Got an Error in my scada system (indusoft, VBscripting) I got...
Replies
6
Views
4,975
I’m using a 05 PLC which cannot handle real (floating point) numbers. The operator must enter the cut length into the C-Micro panel. (I used a...
Replies
2
Views
3,578
Just curious. Does anyone know the specifics of how the PLC5 converts a single floating point to two integers and back using the COP command? Is...
Replies
3
Views
8,112
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,209
Hello, could someone kindly convert the attached RSP files that are currently used for SLC 5 PLC into PDF please
Replies
6
Views
473
Back
Top Bottom