Chris Elston

Suggestions on COP Function in Allen Bradley in NJ? 32-bit to INT

8 posts in this topic

Not being an expert in Omron yet...I have some code I am porting over from Allen Bradley 5000 to an NJ CPU.

I have a rung in AB that I am using a COP function. What it's doing is a taking a 32-bit REAL (no decimal point) and copying that into two 16-bit INT registers. I can't seemed to find a way to do that in Omron. 

I tried to a CopyRealtoDWORD then a DWORD to INT, but the double word to a single INT doesn't copy right. 

Any suggestions?

Share this post


Link to post
Share on other sites

Just taking a shot but did you try CopyRealToNum?

The terminology is different but states it will do bit pattern copy to a signed integer.

Share this post


Link to post
Share on other sites

Have not tried that, but might work better to use the CopyRealtoNum...looks alot better.

Ok so now I have that in DINT format, how do I copy the 32-bit DINT into two consecutive INTs?

The place the number is going is 16-bit memory so I need to split the DINT into two INTs.

 

Share this post


Link to post
Share on other sites

I'm going to explain some concepts as I understand them first. Omron seems to be very strict when dealing with data types. Most instructions will warn "Must be the same Data Type". To me this means they will not allow you to manipulate a data type illegally.  

When dealing with raw data movement (no conversion) they want us to work with, what they call "Bit Strings". (D)WORD type which you have discovered already. With these, Omron seems to be strict about size. For example, I couldn't find a method of moving the upper 16 bits of a DWORD and placing them into a WORD.

I would go back to the CopyRealToDWORD first. Then you can DWORD_TO_WORD for your lower 16 bits. Shift (SHR) the DWORD 16 bits, then DWORD_TO_WORD again for your second WORD. From here it should be easy to copy the 16 bit WORDs to 16 bit INTs.

The other method of accessing the upper 16 bits is to create a Union. Union members occupy the same space.

Mr_PLC_DWORDtoWORDs.PNG.9aada1f16f993a46

From this example, your variable would be defined like, MyVar as data type u_DWORD. DWORD access:  MyVar.DWrd and WORD access:  MyVar.Wrd[1].

Share this post


Link to post
Share on other sites

Here is how I solved it. FINALLY...took awhile to find what I wanted as far as function blocks.

 

pic.png

Share this post


Link to post
Share on other sites
11 minutes ago, Chris Elston said:

took awhile to find what I wanted as far as function blocks.

There are a lot to choose from. I've been working with SS a while now and I still have to review many of the FB references when performing complex moves or working in bytes.

Share this post


Link to post
Share on other sites
19 hours ago, Chris Elston said:

Here is how I solved it. FINALLY...took awhile to find what I wanted as far as function blocks.

 

pic.png

This seems very odd to me.  You have a 32 bit float number and you want to essentially convert it into a 32 bit integer and then break that integer into 2 - 16 bit integers?  What is the purpose of this?  So, you start with 170000 as a Float and end up with 2 and -26608 as single signed integers?  I am trying to understand to perhaps provide alternatives.  Thanks.

Share this post


Link to post
Share on other sites
On 12/6/2019 at 11:46 AM, Michael Walsh said:

This seems very odd to me.  You have a 32 bit float number and you want to essentially convert it into a 32 bit integer and then break that integer into 2 - 16 bit integers?  What is the purpose of this?  So, you start with 170000 as a Float and end up with 2 and -26608 as single signed integers?  I am trying to understand to perhaps provide alternatives.  Thanks.

Yeah I know. The controller that is attached to the NJ is a EIP SLAVE. The EIP registers are only INTs. It can process a REAL number across two INTS with no decimal point. It's the design of the EIP slave attached, so you write a 15000 in the two INTS and it interprets that as 150.00 mm of course using two INTS (like a double), you get larger that the 32,000 or 320.00 mm number...

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