News:

  • August 17, 2026, 07:16:40 PM

Login with username, password and session length

Author Topic: Compare Values  (Read 10532 times)

RBPLC

  • Hero Member
  • *****
  • Posts: 586
Compare Values
« on: October 27, 2019, 08:48:01 AM »
Is there an equivalent command in Do-More to the CMPV command in Productivity Suite? This command basically performs: if x<y set c0=1 c1=0 c2=0, if x=y set c0=0 c1=1 c2=0, if x>y set c0=0 c1=0 c2=1. This would also be equivalent to CMP in Mitsubishi. I couldn't find an equivalent instruction in Do-More but assume is can be done with the MATH instruction possibly.   

Mike Nash

  • Hero Member
  • *****
  • Posts: 652
Re: Compare Values
« Reply #1 on: October 27, 2019, 10:37:39 AM »
Oddly, I haven't missed this from the DirectLogic series. I prefer the direct comparison instructions >,<,= myself since they are all available in the Do-more vs just a subset in DL.

You might look at ALHILO and ALDEV, but neither is a direct replacement. You could do a MATH, but it wouldn't be straightforward either since it can only affect a single address. You could write an entire byte with 1,2,4 but lose the other bits being useful, unless you can further manipulate by masking or something.

Mike Nash

  • Hero Member
  • *****
  • Posts: 652
Re: Compare Values
« Reply #2 on: October 27, 2019, 11:47:22 AM »
This seems to work, but I wouldn't want to use it myself. It doesn't affect the states of C3-C7. You could use other bits by changing the 0xF8 (1111_1000) and the the result values 1, 2 & 4.

Still, it's a kludge. (And those == get me every, single time!)


franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3843
    • Host Engineering
Re: Compare Values
« Reply #3 on: October 27, 2019, 01:37:47 PM »
There is something like that for Strings (STRCMP), since you can't do string comparisons in relational contacts.

I know some people like to do their ladder logic in MATH instructions:
MATH C0 "(X0 && X1) || !C2"
is the same as
Code: [Select]
.
 X0    X1                  C0
-] [---] [-+--------------(OUT)
           |
 C2        |
-]/[-------+
so I understand why some would like CMPV.

RBPLC

  • Hero Member
  • *****
  • Posts: 586
Re: Compare Values
« Reply #4 on: October 27, 2019, 03:39:02 PM »
A call to a subroutine works as well. I'm recreating code where this was used multiple times.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3843
    • Host Engineering
Re: Compare Values
« Reply #5 on: October 27, 2019, 04:42:53 PM »
A call to a subroutine works as well. I'm recreating code where this was used multiple times.

SWEET!  If you utilize the CALL Input and Output parameters, Designer pre-fills the subroutine side INPUT and OUTPUT parameters, then you only have to fill in the client side of the IN and OUT.

I've attached a screen shot where I already have one CALL to the CMPV subroutine with one set of the two INPUT compare values and one set of the three OUTPUT bits, and then when I do another CALL to the CMPV subroutine, it asks me if I want to re-use the "function signature" where it fills in the SUBROUTINE side's input and output parameters (first screen attachment), and then I only have to fill in the CALLer side of the input and output parameters (second attachment).

RBPLC

  • Hero Member
  • *****
  • Posts: 586
Re: Compare Values
« Reply #6 on: October 27, 2019, 05:41:26 PM »
For my usage, it looks like a call to a subroutine is the easiest and cleanest method.