Sign in to follow this  
Followers 0
Chavak

Convert DINT to 4 SINT

15 posts in this topic

Hi, How do I convert a DINT to 4 separate SINT? - on CJ2M CPU12 I need to sent the target position data over Profibus to a Festo servo controller. I managed to read and decode the actual position data coming from the controller using XFRB and convert it to floating point, but stuck in doing it back. My thoughts were to 1. Convert the target position data [floating point number] into a double integer 2. Split it into four SINT and sent it over network Maybe there are better ways. BTW I am using a Festo CMMS-AS servo controller with profibus. Thank You Best Regards

Share this post


Link to post
Share on other sites
Use the FIX instruction to convert your REAL (Floating point) number to a 16 bit integer (you will lose everything to the right of the decimal). Then do 3 MOV instructions to copy the converted value into three additional registers. You do not need to convert it to a DINT first. Example: If D100 has a real value of 1234.567 If you do this: FIX D100 D200 MOV D200 D201 MOV D200 D202 MOV D200 D203 Then you will have a value of 1234 (as an INT) in D200, D201, D202 and D203

Share this post


Link to post
Share on other sites
Hi Michael, Thank you for looking into it. I see using the FIX instruction I can extract the integer portion, but both the integer and decimal portions are important to me.It determine my axis target position. When I tried your example I get 1234 in all 4 D registers. The servo controller accepts the target position in DINT and convert it to real internally. But due to the fact the data is sent over Profibus [which talks in SINT] I need to convert it to SINT. I did several of this application in AB and it works very well. But this time around we are using Omron. Thank You Best Regards

Share this post


Link to post
Share on other sites
I had a somewhat similar problem a couple years ago. I used the FSTR(448) instruction to convert the floating point to string then used the NUM4(604) instruction to convert sections of it back to INT. It's a PAIN to do because you have to find the decimal point in the string in order to figure out where to start the conversion.

Share this post


Link to post
Share on other sites
Do a floating point multiply first. Let's say you need two decimal places. Multiply by 100.0. Then do as I suggested. 12.345 becomes 1234.5 and then converts to 1234 as an integer. So, 12.34 as a float becomes 1234 as an int.

Share this post


Link to post
Share on other sites
Hi Michael, Actually I am doing a floating point multiply and ended up in DINT due to longer stroke length, if I were to limit to INT, my axis stroke length is limited to 327.54mm, nothing beyond with a 2 decimal point accuracy. In fact in my current project I only need an axis length of 200mm max, so using an INT is alright, but I was getting prepared for longer strokes [for expandability of the function] Thank You Best Regards

Share this post


Link to post
Share on other sites
I was going to mention this fact in my previous post, but thought this was an obvious issue. You had mentioned that you had done this with an AB PLC a few years ago, but this limitation would still exist in an AB PLC. This is not an Omron math programming issue, it is a number format issue that would apply in any math calculation. There is no way to program around this issue. If it has to be a 16 bit signed integer, this is the limit. If you could do a 32 bit signed integer, then obviously the issue does not exist.

Share this post


Link to post
Share on other sites
Hi Michael, Sorry, I forgot to mention the AB PLC which it was implemented was a controllogix series. Being built on 32bit platform it does support, SINT, INT, DINT data types among other data types Attached is the screenshot of the code Thank You Best Regards

Share this post


Link to post
Share on other sites
Perhaps I really am missing what you are trying to do... When you said convert a DINT to 4 SINTs, do you really just mean break up 32 bits into 4 - 8 bit values? Because to convert a DINT to a SINT, the DINT would have to be between -128 and 127 which is a very limited range and will not work for your example. Does the Festo not accept the command as a DINT?

Share this post


Link to post
Share on other sites
Hi Michael, Yes, I wanted to break up a DINT into 4 SINT, sorry about the term I used - "convert' . Festo accepts the data in DINT, the trouble was with the Profibus network as its data structure is based on bytes, I have to break it up before I sent. Thank You for being patient with me Best Regards

Share this post


Link to post
Share on other sites
Leave it as a DINT. When you specify the memory area size, you can just say 4 bytes. Then in the PLC, the 4 consecutive bytes happens to be in DINT format. I don't believe that you have to do any of this.

Share this post


Link to post
Share on other sites
Hi Michael, I wish it was that simple. I have noticed the servo side receives the correct data when I do a byte swap [you can see that in the code I attached in previous post, in it - set points bytes 1,2,3 & 4 was swopped to target byte 4,3,2 &1]. When I tested it in CJ2 to Festo servo, I was using XFRB command to swop the bytes from my INT set point data bytes 1 & 2 to the target byte 4 & 3 to make it work. It works fine for axis length up to 327.54mm I have my PLC and servo controller given back to the wiring house to complete the panel, I will get it back only in another 1 weeks time - I will try it out further then. Thank You Best Regards

Share this post


Link to post
Share on other sites
Do you need something like this? Edited by vasekd

Share this post


Link to post
Share on other sites
Good suggestions, I would suggest nearly the same thing, just a little bit different (no BCD to DINT conversion, but a float to DINT conversion).

Share this post


Link to post
Share on other sites
Hi Michael, Vasekd, Thank you very much, the logic is working well [i tried it in simulator]. Cheers. Hi Vasekd, Welcome to the forum, Best Regards

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