Sign in to follow this  
Followers 0
Fear_me

MM to inch conversion

13 posts in this topic

Hi All! I know the topic sounds like it should be simple, but i am just having one of those days! :*-( I have an IR device that is connected to my plc measuring distance. This is the problem: As the IR device moves it displays it distance in channels 304 and 305. 305 is the low word and 304 is the high word. example: 1048575mm is displayed like this: 304: 0000000000001111 305: 1111111111111111 (view word as decimal to get mm display) Now the problem I am having is how do I convert that to inches? I looked into using the scl and arp instructions but I have not gotten them to work! I was even thinking of doing simple long multiply but they set up like this: dm+1 dm x dm+1 dm but that uses the wrong word, i need that dm to be -1 not plus one, does this make any sense?? the plc i am using is a c200h cpu64 Thanks, Andrew Edited by Fear_me

Share this post


Link to post
Share on other sites
It's confusing, but the above will work: Example: MULL 304 D1000 D2000 translates to:              D305|D304 *           D1001|D1000 _______________________ D2003|D2002|D2001|D2000

Share this post


Link to post
Share on other sites
1048575mm is this: 304: 0000000000001111 305: 1111111111111111 I just double checked the conversion and that is correct. Also something else just came to mind, to convert mm to inches you have to divide by 25.4mm not multiply! Damit, and you can only use the multiply function when the word is in a bcd format. so does that mean i have to convert it to bcd first? Why can't things be simple?? ~Andrew

Share this post


Link to post
Share on other sites
Sorry, but I don't buy this. No data type would convert 1048575 to FFFF 000F - not even IEEE 754 Floating Point. What makes you believe that 304 and 305 hold the converted value? How does the value get into these specific words? Analog? RS232?

Share this post


Link to post
Share on other sites
Jay, i believe that first he has his data arse about, he eluded to this in his first post Therefore this would read FFFFF which is in fact 1048575 So before he scratches his head he has to reverse the data first...

Share this post


Link to post
Share on other sites
Seems odd since 1048575 mm equals 1048.575 metres. This is over 1 kilometre!! What kind of an IR device measures this far? Also, does the reading in 304 and 305 ever change to anything but a long string of 1's, ie: 0000000000001111 1101000110011101?

Share this post


Link to post
Share on other sites
OK, I see that 000F FFFF is 1048575 decimal MOV 304 D501 MOV 305 D500 BCDL D500 D510 MOV #0245 D1000 MOV #0010 D1010 MULL D510 D1010 D2000 DIVL D2000 D1000 D3000 translates to: 304 > D501 =000F 305 > D500 = FFFF 000F FFFF > 0104 8575     D511|D510 * D1001|D1000 _______________________ D2001|D2000 0104 8575 * 0000 0010 = 1048 5750  D2001|D2000 /D1001|D1000 _______________________ D2001|D2000 R D2003|D2002 1048 5750 / 0000 0245 = 0004 2798  remainder 0000 0240 42978 inches

Share this post


Link to post
Share on other sites
I will have to try that today when I have a chance! The device I am using can be found here: www.trimble.com It is the ICS5000 IR measuring device, it looks at a reflector and gives a distance reading as you are traveling away from the reflector, but because i needed to revers that and travel to the reflector it it will get higher and when the reflector is right in front of it I will get a max value of FFFFFFFF. I have already made a part of the program that will give me a 0 point, by storing the current distance when you press the 0 button and then it is always subtracting that value to the current value. The device is connected to a c2ooh plc via profibus. Very nice device used for measuring, I was just having problems converting to inches with it. Thanks, for your help, I will try it later today and let you know my results. ~Andrew

Share this post


Link to post
Share on other sites
Ok, I tried it and it is not correct! I am off by 1,000 inches! By using it your way: 1048575mm will equal 42978 inches By calculator: 1048575mm is 41282.48inches! That is a big difference because i need to try and have an accuracy of +/- .25 inches or better! Plus i need my end result to be like this: 5.00 inches = DM1000: 0500 I thank you all for your help, but is there another way i can try this so i do not loose my accuracy?? Thanks, Andrew

Share this post


Link to post
Share on other sites
In Jays code did you notice that he firsts multiplys you result by 10 before the division ???? ie 1048575 becomes 10485750 then he divides by 245 to get the result in inchs as said... if this is still not accurate enough then Look at FDIV (floating point division) You have to first convet your numbers to floating point though.... remember when converting back to bcd then the decimal is truncated..... A small note.... Unfortunately, Omron in the past i felt did not handle floating point math well HOWEVER this has been more then addressed in the latest CS1 and CJ1 PLC's BTW ESCI said in a previous post I aggree with ESCI are you really measuring 1.048 kM !!!!!! Or did you mean um Or if FFFFF - 1048575 indicating an error because you are to close to the sensor ?

Share this post


Link to post
Share on other sites
The device has a very far range! What the limit is I am not sure, but I remember them saying that it has an accuracy of upt to 1/2 mile i think..... But the device is made that in normal operation the device will travel away from a reflector and the values in 304 & 305 will increase starting at 0 which is right infront of the IR device, and decrease moving toward it In some cases(like mine) it is needed to travel towards the reflector, which gives you a value of FFFF FFFF when you are right in front of the device and when you move away it will get lower, move towards it and they get higher In my case I have to use it that way cause my machine is traveling toward the reflector. In my programming I am capturing the current value it sits at and storing that in a dm area, then I am always subtracting that dm value with the current so from that point on the value will increase as I move towrd the reflector! I hope that makes sense, I will let you guys see what I am doing by letting you download a copy of my progress. In return I would like your input on how my programming is. And if you have any more ideas, I will look into that floating point idea too Thanks, ~Andrew Progress .cxt file (Right click and save as) Edited by Fear_me

Share this post


Link to post
Share on other sites
Andrew, (sounds a lot more approachable then Fear_Me)... I had a look at your code...you really don;t need to convert to BCD, in fact it is preferable not to in this case...I suggest inputting you raw value in DM1652 straight in to the multiply instruction....On that issue I would also use MBSL and DBSL instructions (In my attached example i used *L and /L which is in the cj instruction list). Both the MBSL and DBSL are expansion instructions and will have to be mapped....You will notice now that i can use a multiplier of 1000 in lieu of 10 therby giving you a 2 decimal point accuracy....

Share this post


Link to post
Share on other sites
Attacted pdf of program... LadderLogic.PDF

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