32-bit word splitting

see if this works ...

Mikey,

based on what you’ve posted ... and on quite a few assumptions (gosh I hate that word) here are the specifications that I !-THINK-! you were interested in ...


when +9,999,999 is input at F8:0
N7:1 will contain 0000 0000 1001 1000

N7:0 will contain 1001 0110 0111 1111



when -9,999,999 is input at F8:0

N7:1 will contain 1111 1111 0110 0111

N7:0 will contain 0110 1001 1000 0001



when 0 is input at F8:0

N7:1 will contain 0000 0000 0000 0000

N7:0 will contain 0000 0000 0000 0000



when 32,767 is input at F8:0

N7:1 will contain 0000 0000 0000 0000

N7:0 will contain 0111 1111 1111 1111



when 65,535 is input at F8:0

N7:1 will contain 0000 0000 0000 0000

N7:0 will contain 1111 1111 1111 1111



when 65,536 is input at F8:0

N7:1 will contain 0000 0000 0000 0001

N7:0 will contain 0000 0000 0000 0000



when 7 is input at F8:0

N7:1 will contain 0000 0000 0000 0000

N7:0 will contain 0000 0000 0000 0111



when -7 is input at F8:0

N7:1 will contain 1111 1111 1111 1111

N7:0 will contain 1111 1111 1111 1001




if for some reason, I’ve got this wrong, then please use this same format and nail down EXACTLY what you !-DO-! want ... I’ll be glad to try again ...



good luck with your project ...



and incidentally ... the XPY instruction might “look” more glamorous and a lot of programmers would be tempted to use it for this application ... but ... XPY is a scan-time HOG! ... the approach that I used is based on a “brute force” longhand conversion - but the processor will be able to execute it a lot faster this way ... and ... it will also be a lot easier for someone else to understand further down the road ...

note: I've included both the .RSS format and the .PDF format in the zip file - just in case someone without RSLogix500 is interested ...
 
Last edited:
Not good

The above method doesn't check the exponent. All the significant digits are in the mantissa except bit 23 must be forced to a 1. It is just a matter of using the exponent to calculate how many times the mantissa must be shifted right OR left. A problem occurs only when shifting the mantissa left more than 8 times.
 
Greetings Peter,

first of all, I truly value your opinion ... but regarding your "not good" comment ... no offense taken ... and no offense intended ... but I really do think that it's "good enough" ... notice that my comments and examples have emphatically nailed down the idea that the allowable range for the input values (F8:0) must be WHOLE NUMBERS within the range of +9,999,999 to -9,999,999 (note negative sign) ... I specified that range (and had Mikey "sign off" on it) because anything outside of that range forces the floating point number to shift into exponential notation ... and because fractional/decimal parts would prove exceptionally onerous ... plus I don't think that Mikey's application uses or requires a fractional component for the input value ...

more specifically, please note this part of the comment for rung #0000 in ladder file #3:

It is the final programmer's responsibility to make sure that the value stored in F8:0 falls within the acceptable range (+9,999,999 to -9,999,999) and that no fractional (decimal) parts are included in the input. Input values which do not meet these criteria will be converted with unpredictable and possibly unsafe results.

moreover, the examples that I've given will work with the program I provided ... at least in my tests they do ... have you tried any valid numbers and found otherwise? ... I believe that Mikey will find my answer acceptable for his purposes ... if not, I've invited him to nail down further specifications and I've made an offer to try - try - try again ...

going further ... you might note that Mikey made his first request for help on October 7 ... I posted what I believe to be a workable answer on October 16 ... specifically, a full NINE DAYS later ... with no offense to Mikey, if he had nailed down his requirements on day numer one, then I would have probably written the answer that evening and posted it the very next day ... again, no offense intended to Mikey, but the poor guy is using the "shotgun" approach to working through this problem ... I (and others) have been trying to help him the best we can ... I simply had to let this one sit on the back burner until I finally got some spare time to knock it out ...

when I first posted my "answer" this morning, I had included a friendly advice "lecture" to help Mikey work through this type of problem in the future ... after I read it, I decided that the tone was perhaps a little (maybe a lot?) too brutal ... so I made an edit and removed the comments ... but based on what you've posted, I think that maybe I'll reinsert a slightly abridged copy of it here ... just to make note of the issues and limitations under which we've all been working ...

and so to Mikeylikes:

feel free to ignore this lecture and go ahead and try the program if you want to ... but maybe these comments will help you with problems like this in the future ... anyway, that’s the way I intended it ...

you said:

This has been something that has been difficult to wrap my head around.


the main reason that you’re having so much difficulty with this particular problem is that you haven’t taken the time to nail down exactly what you want ...


golden nugget of truth: if you can’t define it, then you can’t possibly program it ...

for example:

+/- 9,999,999 should be more then enough.


if this range is “more than enough”, then what (pray tell) is exactly enough? ... you need to nail down the precise range of values BEFORE you start trying to write the code ...

a lot of us are trying to help you ... for free ... but we have “issues” with things like this:

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.


first of all, the integer locations that you’ve mentioned are “words” (16 bits each) and not “bytes” (8 bits each) ... even so, we know what you mean ... but ... in the low word, the left most bit probably doesn’t really equal “16^2” as you’ve specified ... 16^2 actually turns out to be 256 ... I’ve got a hunch that you meant to say “2^15” ... and notice that it’s “15” and not “16” ... but even so, 2^15 actually turns out to be 32,768 and not the “65,536” value which you specified for this particular bit ...

now don’t go getting a burr under your blanket ... I’m not trying to beat you up over this - and I mean absolutely no offense ... but ... when you make post after post with statements which are “all over the map”, then most of us get the feeling that we’re going to spend a lot of time barking up the wrong tree (or maybe a whole series of trees) while we try to nail this thing down for you ... and PLEASE don’t take this the wrong way, but when you sum it all up with a statement such as:

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

then we “sort-of-kind-of” get the sinking feeling that maybe you don’t really know exactly how the two’s complement system works ... (gosh that sounds brutal ... but I’ve tried and I can’t think of a more polite way to say it) ...

so the point of all of this is: if you need more help with anything like this in the future, do yourself a favor and take the time - and the pencil lead - to map out EXACTLY what you want BEFORE you try to program it ... I actually gave you an “example of an example” format in an earlier post ... I’ve got a really big hunch that if you had taken the time to use the approach I suggested, then you’d have been quite capable of figuring out how to program this thing yourself ... basic idea: you write down some sample input values - and then map out the bit patterns that you want as a result - and then ask yourself “now how can I make the PLC do automatically what I just did longhand?” ...

anyway ... I hope that this little lecture helps ... and if it doesn’t help you, then I’m pretty sure that it will help someone else with a similar problem in the future ... and that’s what the forum is all about ...

and I just realized that I’ve spent more time writing this “friendly advice” lecture than I did writing the code that you requested ...

anyway ... now I’m down off the soapbox ...

and so to Peter ... as I said before, I honestly value your opinion ... but ... I still think that if Mikey will try this solution, then it PROBABLY will do everything that he needs for his particular application ... and considering the "issues" in his specifications, this is the best that I personally can do right now ... but if more information is forthcoming, then I'd certainly enjoy taking another crack at it ...

in the meantime, have you come up with a different interpretation of Mikey's requirements? ... and if so, would it be possible for you to post a solution which will meet those specifications? ... I'm always eager to learn something new and I'd sure like to take a look at it ...
 
Last edited:
Ron,



You nailed the format, and sorry about the 16^2. You were right to assume the 2^15. I forgot that there is a 2^0, an amateur mistake.🙃



Thank-you for the help, as well as the friendly advice lecture.📚

I am still sort of new to the advanced PLC logic programming, and will definitely take the time to write down what I'm doing and what I need. As well as giving more detail when asking for help in the future.
The reason I posted this originally is because I was asked to do this in a crunch, which is usually the case, but then it got delayed. I got flustered because what seemed like something easy to do did not work with everything that I had tried, or came up with. I thought about the brute force method, but thought there had to be a better way within the built in functions of RSLogix500.
 

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,802
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,908
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