Masked equals help

Code Blagger

Member
Join Date
Oct 2020
Location
Midlands, U.K
Posts
19
Hi guys I'm struggling to understand this function.


I have an RFID reader that reads in LH and RH of a variant. The variant is set from the HMI.



Variant = [1].9 = 512
LH = [1].15 = 32768

RH = [1].16 = 65536


Total = 98816.


If I want to mask out the RH value, what value do I need the mask to be? I thought it would be 65536, but that doesn't seem to work.


snip 1.PNG
 
The mask would be 65535. The MEQ considers all the bits in the mask equal to 0 in the EQU evaluation. 65535 will cause the instruction to ignore bit 16 in the equal but consider all others. Is that what you really want it to do?

Keith
 
98816 = 16#1_8200 = 2#0001_1000_0010_0000_0000
65536 = 16#1_0000 = 2#0001_0000_0000_0000_0000
98304 = 16#1_8000 = 2#0001_1000_0000_0000_0000


With MEQ, only those bits which have a 1 in the mask are compared.

Looks to me like the MEQ will be TRUE, but as Commissioning CommBit.11 is false, so too is CommBit.12 not being latched.
The MEQ does not light up when it is true, you have to magically know the state of it.
 
Code_Blagger ....

You could do yourself a favour and enter your Mask values in Hexadecimal, or Binary format. It makes it easier to see which bits you are comparing (Mask bit = 1), or blocking (Mask bit = 0).

In your case, to compare the lower 16 bits of a DINT, the Mask value would be 65,535 decimal, or you could specify as either ....

16#0000FFFF

or ....

2#0000_0000_0000_0000_1111_1111_1111_1111

... either will work.

And don't forget you can, should you feel the need to, go and look at the Source and Compare tags in the database, and either ...

a: temporarily change the display radix to match - do this on the "Monitor Tags" display tab.

or,

b: permanently change the display radix on the "Edit Tags" display tab
 
When you say "mask out the RH value" do you mean you want to ignore it? You preface the MEQ instruction with
Type.InStation[1].15 AND Type.InStation[1].16

If you want to "ignore" the RH (.15) condition, can't you just delete the XIC Type.InStation[1].15 in your rung? Then it doesn't matter what that bit is set to. The rest of the rung will evaluate.

OR...

When you say "mask out the RH value" do you mean that you want to set it zero?

Can you clarify exactly what you are trying to do?
 
Actually I am slightly confused with your post ...

Code Blagger said:
Variant = [1].9 = 512
LH = [1].15 = 32768

RH = [1].16 = 65536

Did you mean that Variant = bits 0 to 9 and that bits 15 and 16 are just some sort of flag ?

If it is, then your MEQ should only be comparing the low order 10 bits, with a Mask of 16#000003FF, or 2#0000_0000_0000_0000_0011_1111_1111, or 1023 decimal
 
Caveat: I make many assumptions here, although I state them explicitly. That said, I agree with the other replies that your OP does not unambiguously tell us what you want to do; but fear not, for 'tis a common malady, and we are patient.


Do you want to ensure only two bits (9 and 16) of [1] have the same values as the two corresponding bits of RFID? Or are you interested in more bits being the same between the two DINTs?



  • In the particular example shown, as @ndzied1 mentioned, you already know the value of LH ([1].16)
    • I.e. it is 1
    • so any masking for that bit can be replaced by a test of that bit in the RFID value:
      • XIC _010_RFID_1.ReadType.16
    • And bit 16 (65536) can be 0 in the mask
    • Otherwise, if you don't want the XIC, and want to compare that bit in the MEQ, then bit 16 (65536) should be 1
  • You say you don't care about the state of bit .15 of _010_RFID_1.ReadType, so that bit, bit 16 (32768) should be 0 in the mask
  • So the only bit of interest is bit 9 (512), which must be 1.
  • My reading is that no other bits are of interest, so all other bits should be 0.
So either


Code:
  LH [1].15    RH [1].16   RFID.16
-----] [----------] [--------] [------[MEQ       ]---
                                      [Src   RFID]
                                      [Msk    512]
                                      [CMP    [1]]
OR

Code:
  LH [1].15    RH [1].16
-----] [----------] [----------------[MEQ       ]---
                                     [Src   RFID]
                                     [Msk  66048] <= 65536+512
                                     [CMP    [1]]
zzz.png


xxx.png

yyy.png
 
Last edited:
Another approach you might like to consider is to map the LH and RH flags to internal bits, then unlatch them. The resulting value will just be Variant and you can use EQU.

Should make it clearer what is being compared ....

Conversely, if you want to "mask out" bit 16 from your comparison, just OTU it in the RFID variant value

2021-03-12_204105.jpg 2021-03-12_204356.jpg
 
Caveat: I make many assumptions here, although I state them explicitly. That said, I agree with the other replies that your OP does not unambiguously tell us what you want to do; but fear not, for 'tis a common malady, and we are patient.


Do you want to ensure only two bits (9 and 16) of [1] have the same values as the two corresponding bits of RFID? Or are you interested in more bits being the same between the two DINTs?

I hardly think an RFID tag would only produce a single bit of usable data (bit 9), which is why I queried his text


"Variant = [1].9 = 512"

Also, no designer in a right frame of mind would use bits 15 and 16 when bits 14 and 15 are free... doesn't make sense ....

I suspect there might be a language collision here, perhaps the RFID product hails from afar (to me anyway).
 
I hardly think an RFID tag would only produce a single bit of usable data (bit 9), which is why I queried his text


"Variant = [1].9 = 512"

Also, no designer in a right frame of mind would use bits 15 and 16 when bits 14 and 15 are free... doesn't make sense ....

I suspect there might be a language collision here, perhaps the RFID product hails from afar (to me anyway).




Yah, lots of caveats on this one (like so few others ;)).
 
Wow, I'm blown away by the responses here, thank you so much for all your help, I think I understand now. I will have another go at the code later when I get home.


In another part of the routine the guy before me has programmed a minus value mask in, how does that work?



snip4.PNG


Final question, I'd like to pay to support this forum as I've learnt so much, and you've all been a great help to me, is there a way I can pay through PayPal? As my security software goes nuts when I try to pay with my credit card through the support forum link.
 
In another part of the routine the guy before me has programmed a minus value mask in, how does that work?


That is a signed 32-bit integer; google "twos-complement"



A negative number means bit 31 is 1. So when adding the values for each 1 bit (1 if bit 0 is 1, 2 if bit 1 is 1, 512 if bit 9 is 1, ...), add -2,147,483,648 for bit 31, i.e subtract 2**31 instead of adding it.


As someone mentioned, it is much easier to deal with masks in a hexadecimal or binary mask; the decimal value has no meaning that can be immediately understood without breaking the number into its power-of-two decimal components (1,2,4,8,...,1,073,741,824 and -2,147,483,648).
 
Last edited:
Wow, I'm blown away by the responses here, thank you so much for all your help, I think I understand now. I will have another go at the code later when I get home.

Can you explain in more detail the data structure of your RFID data. All of the bits please ....

Your original explanation was unclear, and seemed to indicate only bit 9 was used .....
 

Similar Topics

Hello, I am using a UDT to track status from two different indexing lines that merge into one. Essentially, one indexing line is the part, and...
Replies
17
Views
3,708
Hey I'm new to rs logic 5000 I have the basics but I'm getting confused with this mvm instruction. Can anybody bum it down for pls Thanx in advance
Replies
3
Views
4,868
A known rule is that you should never open an attachment which seems suspicious... especially if the attachment is Allenbradleyupdate.zip...
Replies
11
Views
4,608
The title pretty much sums it up, but to elaborate I am using a PanelView Plus 700 and Machine Edition. I want to have a numeric entry screen...
Replies
18
Views
9,360
So I'm using a 1769-L35E. I'm trying to move two INTS through Masked Move Instructions to create a DINT together. I'm fairly new to this so...
Replies
14
Views
6,777
Back
Top Bottom