Chris1967

Unsigned Integer Addition and Subtraction

5 posts in this topic

Hello and thanks for looking.

I have spent ages trying to get my head around all of the different data types in Omron and clear all of the warnings out of the compile window but I am stuck with an issue I can't shift.

I want to subtract one UINT from another in a CJ2M CPU but cannot find the instruction. I can Find /U and *U but not add or subtract. 

I used -(410) which works but gives a warning as obviously it is looking for a signed INT.

I also thought that maybe I could convert to UINT to INT and do it that way but still I can't find the instruction (if there is one) to do the conversion.

What am I missing, it is driving me nuts.

Share this post


Link to post
Share on other sites

At the end of the day the data is the same - it is just interpretation of the data. If you list a word as a UINT and get get a warning that it should be an INT it does not matter - how you use it is the only things that matters. The word types are standard - not just Omron. You can interpret a word as INT, UINT, CHANNEL, HEX - still the same data in the word.

Share this post


Link to post
Share on other sites

Hi There Bobb

Thanks for the response.

I kind of get what you are saying and it works fine. 

In fact I have found that if I List the words as channels the maths is correct and all the warnings disappear. The instructions seem to accept channels without any problem.

I am assuming that a Channel is just a word of data (16 Bits) and that the instruction reads it in in the format that it is expecting. Is this correct?

Also, is it possible convert a SINT to DINT or UINT to UDINT. I have no need to do this right now but have had to in the past.

I'm getting there slowly!

 

Share this post


Link to post
Share on other sites

Yep - CHANNEL is a throw back to older Omron PLCs. There are a number of throw backs in the software to cater for the old tigers. The attached snip shows how you can view data onlie. Integer, signed integer and HEX.

Also in the watch window you can look at everything including REAL.

At the end of the day there is no conversion that I am aware of. UINT to DUINT is not necessary - the lower word will be the original UINT and the upper word make up the DUINT. for SINT to DINT a bit more difficult. As bit 15 of the SINT is the sign bit just use MOVB to move the sign bit to bit 15 of the upper word I guess - cannot really see a use for it.

Word Types.JPG

Share this post


Link to post
Share on other sites

Thanks for your help Bob

I'm sure I'll be back but for now I have everything I need sorted. 

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