32-bit word splitting

Mikeylikes

Member
Join Date
Oct 2005
Location
Toronto
Posts
6
Any one know how to take a floating point number and convert it so that it can be split to span 2 16-bit words in the +/- 0x7fffffff hex format, or signed 32-bit 2's compliment format? My application seems simple, but I can't seem to get it to work. I'm trying to control a servo motor using an Ultra3000i servo drive that is to be controlled from an Allen-Bradley SLC 5/04 PLC through Devicenet. The PLC does not support long integers, which would make this a snap. I've tried a few ways and I can't get it to come out in the right format. Maybe one of you has come across this in programming SLC's before.
In case you have the suggestion of using the 'COP' command, it won't work because it does not spit it out in the right format. It puts the signed bit in the low byte, which is not where it should be. Also, It puts an exponent value in there somewhere, which is not how the format is suppose to be. This is a stumbling block for me to be able to change drive parameters using the PLC, because some of my values that I want to be able change are high as 350,000.
 
I'm at home so I can't check this. But I THINK you can do a DDV by 1 and then get the two words from S:13 and S:14, which are the lower and upper words of the math register respectively. The DDV will take care of the typecasting for you. Just make sure you move the contents of S:13 and S:14 to integer memory locations before you do any other math.

Since you only need to go as high as 350,000 you can split the float apart youself with some math. You will need to manipulate bit 15 of the lower word youself but it can be done.

Keith
 
thankx kamenges for the help, but after scouring through this site some more I think I found out how to do it.

This site is the greatest
 
There is a technote in the AB knowledge about this.

I dont recall the particulars but I do recall seeing a technote on it. IIRC, you need to swap the order of the high and low words, and I think the technote did in fact use COP instruction. Its been a while since I saw it though to I might be fuzzy on the details.
 
Last edited:
Forget the statement of me finding what I needed on another thread in this forum, it did not work but its a start. If anyone has a suggestion on how I can convert a 32 floating point number to two 16 bit integers that emulate a DINT.

Thank you
 
You might want to give this a try:

This isn't actually a zip file. Just change the extension to .RSS and open it with Logix500. This should work for you. Let me know if it doesn't as the most likely cultrit is the '-0.5' in the lead CPT.

Keith
 
Greetings Mikeylikes,

if all else fails, you could help us out by giving us some specific examples of:

(a) the address of your floating point location
(b) the addresses for your integer locations
(c) what the most-positive floating point value will be
(d) what binary bit pattern you want (in each integer address) as a result
(e) what the most-negative floating point value will be
(f) what binary bit pattern (in each integer address) you want (in each integer address) as a result
(g) and a few other randomly selected floating point and corresponding bit-pattern examples so that we can check our results

example of an example:

when F8:0 contains -324576, I want
N7:1 to contain 1000100010010111 and
N7:0 to contain 1111000010101010

note: this is just intended to suggest a format ... the numbers I've used are meaningless ...

armed with that type of specific information, I'm pretty sure that we'll be able to come up with some specific answers for you ...
 
Thank-you Kamenges,

This has me one step closer, now I just have to figure out how to change it so that I can input negative numbers as well and still get the right format coming out. Ideally, I should be able to input any floating point representation of a double interger and have it work. The reason the range is so large is because of how many counts a high resolution motor may need to complete a full revolution.

I've seen another example on this site

http://www.plctalk.net/qanda/showthread.php?t=2878&highlight=Ab+SLC+FLOAT+Double+Int+Conversion

that the author said it would work. The program is the example.zip RUNG 15. I understand it and it seems like it should work, but it does not work properly because I tested it on my application.



For Ron Beaufort.

My floating point can be in the below range, but it may never be that high.

F8:0 = +/- 2147483647
N7:0 (Low Byte) = 1111111111111111 (FFFF)
N7:1 (High Byte) = 0111111111111111 (7FFF) or 1111111111111111 (FFFF)
 
Sorry about that. I inferred from your original post that you only needed to go from 0 to 350000. My mistake.

My method will only work up to +/- 9999999 without losing resolution. That is where a float will switch over to exponential notion in the SLC and you lose your least significant digit. I will tweak the code I posted to allow bipolar operation.

Keith
 
It's not a zip file, Arik. As Keith mentioned in post #6, you need to change the .zip to .rss after downloading.

:bberchug:

-Eric
 
Mikeylikes said:



My floating point can be in the below range, but it may never be that high.

F8:0 = +/- 2147483647




we have an “issue” ... as Keith has said, a floating point number (example: F8:0) can't go as high (or as low) as you've specified without shifting into exponential (scientific) notation and losing some resolution ...



specific question: can you (answer yes or no, please) live with numbers in the range from (and including) -9,999,999 up to (and including) 9,999,999 ?



if the answer is yes, then we can probably come up with some specific code to meet your needs ... if not, then as I’ve said, we’ve got some serious “issues” ...



if the range we’ve listed is acceptable, then it would probably be a good idea to take a few minutes and answer the requests for some “example” numbers in my previous post ... that way we can nail this thing down once and for all ...

 
OK Guys,

+/- 9,999,999 should be more then enough. It just has to be in the form

-High Byte 1111111111111111 - where the left most bit is the signed bit
-Low Byte 1111111111111111 - where the left most bit represents 16^2,
or 65536.

Just like a 2's compliment 32-bit word would be.

Thank-you for all the help so far. This has been something that has been difficult to wrap my head around.
 

Similar Topics

Hi. I'm struggling over some basic stuff here. 41001 I is a 16 bits integer that I'm able to read with InTouch. What I need to do is to read...
Replies
1
Views
96
Hello How to convert dword to bit in Siemens plc s7؟ Thank you
Replies
15
Views
2,805
All, Forgive my lack of attention to detail, today a student asked me why when he printed his ladder in an RSLogix 500 report, even though he had...
Replies
10
Views
1,925
Well I am trying to cleanly convert a decimal value in a DINT to the corresponding bit in a different DINT So if I have the number 11 on in...
Replies
11
Views
1,988
Hi everyone, I am reading a alarm word from a device via Modbus using Crimson. I would like to create a flag tag for each of the 16 bits so I can...
Replies
3
Views
1,394
Back
Top Bottom