Sign in to follow this  
Followers 0
RFurey

How do you convert a floating point number into MSW and LSW?

7 posts in this topic

1746-HSTP1 SLC500 Stepper Module The stepper output can be a number up to 8,000,000 counts, which determines it's position. In my case 75,000 counts is the maximum number. However, since the module is using 16 bit integers, the count value is split into two integers, the most significant word (MSW) and the least significant word (LSW). The LSW is the first three digits. The MSW is the remaining digits. For the number 69,345 LSW = 345 MSW = 69 Any idea how I can split the floating point number 69,345 into two integers, 69 and 345 in the ladder logic? The solution is evading me.

Share this post


Link to post
Share on other sites
I know there must be a better way than this, but you could take the 69,345 and DIV by 1000 (69) and put that in an integer register as the MSW, then take that number x 1000 (69000) and SUB from the original number (69,345) for your LSW (345) .

Share this post


Link to post
Share on other sites
Is this a decimal fraction or the comma is the thousands separator?

Share this post


Link to post
Share on other sites
Open the help file for the DIV instruction. Read the very last line about the unrounded quotient and the remainder. Once you do the divide by 1000 (with a dummy destination, you won't be using it) move the math registers (S:13 and S:14) into two integers. I'm not sure which is which but it will be quickly apparent. As a note - you may have to make sure that the destination, even though it won't be used, in an integer ('N'). Edited by b_carlton

Share this post


Link to post
Share on other sites
I think the problem with this approach is if the number is 69,999/1000 (for example), it will round up to 70.

Share this post


Link to post
Share on other sites
Rfurey, EDIT: sorry after re-reading your OP, I don't think this helps. Do you need the two integers to be legible, that is, like in your example in your OP. I ask because I ran into a similar situation a while back and learned something new. Long story short, a PLC5 will convert a float into 2 integers if you use the COP command (don't know if the SLC will do the same). COP your float to first integer location with a destination length of 2. It creates two integer values. You can then recompile the original float by doing the reverse, that is, copy integer to float with length of 1. The problem is that the integers don't mean anything. They're giberish, at least to me. I've also used this where I had to FIFO floating point values. Edited by wildswing

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0