Sign in to follow this  
Followers 0
BJR

Help with compare

9 posts in this topic

I've converted a 16 bit number to 32 bit with the SIGN(600) command. I have then performed a long multiply and divide on it (/* and /L). My problem is now I need to make sure this double word is between -150 and 150. I came up with a <=SL(318) for the 150 but I am stumped how to do something like a >=SL D2312 &-150. BTW, my 150 value I was mentioning is the number I am interested in while viewing it in decimal. Can't seem to get any number that represents a negative value in the last paramter of >=SL that will compile. I don't know if I'll figure this one out! I'm open to any logic that will do my compare at all. Most I looked at were for 16 bit. Again I have a long word at D2312 that needs to be checked that it is in between &-150 and &150. Thanks!

Share this post


Link to post
Share on other sites
Hi, BJR.. maybe it was too easy thinking to the ZCPL function..that's why I think I didn't get your problem! Ciao, Mike

Share this post


Link to post
Share on other sites
mikecqm - It appears that ZCPL is for unsigned compares. My whole problem is finding a function that will accept a negative value and also 32 bit.

Share this post


Link to post
Share on other sites
I think I got it now! It's amazing what a fresh new day brings. I built a "calculator" with my double math *L and /L to see what a &-150 "looks" like in double word hex. So FF6AFFFF = &-150?? It compiles and I won't know until my machine gets turned back on but the online simulator seems to be happy. I thought of trying to convert this yesterday but ended up using windows calculator to try and get -150 in hex. Boy was it wrong. Although, it looked like from my memory that the high word and low word were swapped so maybe windows calculator is an OK tool if confusion sets in again. I'll be back late next week if this doesn't work

Share this post


Link to post
Share on other sites
That's why I was talking about ZCPL. Negative values have "F000" in the Most Significant Word. I normally use this function in order to determine if the valeu is negative or not.... BTW...Happy you find your way!! Ciao, Mike

Share this post


Link to post
Share on other sites
So when ZCPL says it is for unsigned compare, that is a data format and it does not mean that it can't be negative? Have I confused unsigned/signed and whether or not the value can be negative? I just went back and tried ZCPL with #FF6AFFFF as one of the limits and it seems fine. I guess my whole problem was converting the &-150 to hex correctly since the command won't let you just put in &-150 as a constant. I'd still like to learn what I am confused on with the question above concerning signed/unsigned and negative values. I know everything in the PLC is done in hex and it's recommended to just leave the data type as CHANNEL but it gets confusing when commands say they are for unsigned or a specific type. If it didn't matter at all wouldn't all of the math and compare functions just be separated into single word and double word commands? Edited by BJR

Share this post


Link to post
Share on other sites
Just have a look to the attachment... I hope this can help you... Mike Test.doc

Share this post


Link to post
Share on other sites
Hi, - enter -150 directly , do not enter &-150 You can enter signed integer constants directly into functions in CX-Programmer: Use the + and - operators without the & Have a read of the PLC Programming Manual W394 Section 2. See examples below. Edited by Nibroc

Share this post


Link to post
Share on other sites
Good news. Thanks for letting me know. Looks like I'll have to set aside some time soon to read a little besides just spending time in chapter 3 is it? The one that just lists the commands Thanks to all again!

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