math question

irondesk40

Member
Join Date
Jan 2008
Location
nc
Posts
630
Have a question that is at the moment just not able to figure out.
Lets say in a allen Bradley micrologix 14 you have a value in a floating point register of 21.42857
I am trying to figure out how to place this value into two different N registers.
For example move the value of 21 into a register and then move the value
of the .42857 into another N register but enter it as a whole number of
42857 not .42857.
Afraid my math skills today is just not allowing me to quite figure this out.
Any advice?
Thanks
 
Does it matter if the decimal amount is indicating the proper value according to is place?
Sorry...I'm having difficulty explaining.
Does it matter is .23, is valued at integer 23, or can it be 23000? I'd think somewhere you'd need to keep a decimal converted to integer value consistent.
 
You need to pick a fixed number of decimal places to represent. If you are using 16-bit INTs, you have to stay within 32767 to -32768. So, you can do 4 decimal places pretty well. INT1 gets 21, INT2 gets 4286 for your example. If the number was 32.56 it would be 32 & 5600.

I'm doing this from memory...
F8:0 - the floating point number
F8:1 - scratch pad
N7:1 - whole portion
N7:2 - fraction portion

SUB F8:0 0.5 N7:1 results in 21.42857 - 0.5 = 20.92857 which rounds to 21.
SUB F8:0 N7:1 F8:1 results in 21.42857 - 21 = 0.42857
MUL F8:1 10000 N7:2 results in 0.42857 * 10000 = 4285.7 which rounds to 4286.
 
Last edited:
thanks for the reply. I think I have it. Had to just get away from the machine and take a break and when I got back it hit me like a baseball bat.
I am working with a sure servo unit and you put the positions you want to move to into two separate Modbus address in the servo.
For example if you want to move 21.428 revs of the motor which is a number I need for fabric that 15 inches wide due to fact that one rev of the motor with the way we have it set up is equal to .7 inches.
So 15 divided by 7 = 21.428 (decided thousands of resolution was good enough)

Desired width is 15 inches = 15/.7 = 21.428
21.428/1000 = 21 (This is moved into one N register and then into the Modbus address in the sure servo for the whole revs)
21.428 - 21 = .428
.428 * 1000 = 428 ( moved into another N register then into the Modbus
address in the sure servo for the steps or fractions of a whole rev)
Have to take the 428 and multiply it by 10 to get 4280. Just read in the sure servo manual that one rev of the motor is equal to 10000 counts.
At least I think I have it figured out, tired of messing with it today, will try it tomorrow.
 
Last edited:
irondesk40, make sure you look at mellis's example. Aside from not wanting the initial divide by 1000, in your example you will experience a certain amount of sadness when your division results in a decimal greater than 0.5.

Keith
 
I meant to divide the 21.428 by 1, not 1000. Will test tomorrow.
Thanks for replies, will look at suggestion.
 
thanks a lot, just got back from working out of the office and tried this on the bench and you was right, I ran into problems. followed your advice and sample and works great.
Thanks for the reply, this site is the best.
 

Similar Topics

... I followed a link dealing with Permutations and Combinations, and learnt a (to me) startling fact ! 0 * 0 = 0 agreed ? 0 * 0 * 0 = 0 agreed...
Replies
12
Views
3,507
See attached pic Why is R02451 reading 0 before the Real_to_Int conversion? It is reading 23 after, which is what it should read.
Replies
8
Views
1,658
Im using Wonderware Intouch machine edition v8.0. Question: How does the Math Worksheet/Task scripting work? I have the following expression...
Replies
3
Views
2,249
Hi Group, I'm the new owner of an AB MicroLogix 1400 processor and have been trying to decide the best way to de-pressurize a compressed air tank...
Replies
8
Views
1,939
🤷 I have a small cattle herd and am trying to create a feed estimate calculator. Each beast will eat about 3% of its body weight each day...
Replies
4
Views
2,750
Back
Top Bottom