What is this doing???????

Jezz

Member
Join Date
Dec 2002
Location
Kendal
Posts
399
Just found this bit of AB code and I can't get myhead round it any ideas

MEQ Source B42:10 Mask N20:51 Compare N20:51

:eek:
 
This conditional instruction compares 16-bit data of a source address to 16-bit data at a reference address through a mask. If the values match, the instruction is true. This instruction allows portions of the data to be masked by a separate word.


Rockwell Software 2000


If the value is a 1 and the mask is a 1 then a 1 is set.

1 and 1 = 1
1 and 0 = 0
0 and 1 = 0
0 and 0 = 0
 
Masked comparrisons allow you to ignore certain bits during the comparriosn.

I'll provide a 4 bit example.

Source B42:10 = 1111 = 15
Mask N20:51 = 0111 = 7
Compare N20:51 = 0111 = 7

The MEQ will evaluate N20:51 as being equal to B42:10, even though one value is actually 15 and the other is 7 because the mask tells the insstruciton to ignore the fourth bit. Set a 1 in the mask for the bits you care about, a zero for any bits which you dont care about.
 
Last edited:
I get that but N20:51 = 0100 for example so why use MEQ when your just looking at A single bit state would

xic B42:10/2 xic N20:51/2

Achive the same result
 
I have to think before replying in full

I am not good at this but it looks to like an easy way to see if different bits are true at the same time, not one individual bit state.

Lets say B42/1, 2, 3, 4 are bits directly corresponding to real world devices...ie pbs, switches etc. Instead of doing B42/1 AND B42/2 AND B42/3 you could use the MEQ to know when that has happened. Somewhere else you may want to know if B42/1, 5, 6, and 7 are true at the same time, then you would use a different mask.

I think the confusion comes from using the N file for the Mask, it implies that you are dealing with integers which may not be the case.
 
Last edited:
dalem said:
Could something else in the program change the mask?

Thats exactly what I was thinking.

You are correct that xic B42:10/2 xic N20:51/2 would achieve the same result if the mask does not change. I suspect that since the mask is not a constant that it does change. At the very least the programmer may have wanted an easy way to change the mask without modifying the program - even if it was just for debugging. Do a "Find All" for N20:51.
 
N20:51 is the destination of aa CPT instruction

2**(N103:1-1)

Not got a clue what ** does
 
Masks

I would first find out what b42:10 is. Do a search and find all B42:10 bits. In many cases not all the bits will be used. Next find all occurances of N20:51. The mask may be changing because B42:10 is changing and in different parts of the program B42:10 must have a certain bit pattern. What events create the bit pattern in your program? When the comparison is executed, are you writting into N20:51 from another part of the program? Break each part of the program into sections, looking at what conditions are needed and where changes occure. Eventually a big light bult will come on and you will have an "aha" experience. Remember, not all programmers solve problems the same way. The logic could be trying to do something very simple.
 
Jezz said:
N20:51 is the destination of aa CPT instruction

2**(N103:1-1)

Not got a clue what ** does

This is setting a particular bit in N20:51. its based on the value in N103:1 minus 1. ('1' sets bit zero, '2' sets bit one, '3' sets bit two etc) The "**" means 'raised to the power' which, when dealing with 2, just sets a bit. Though I wonder why they didn't just use the DECOde instruction (unless it wasn't available).
 
Is this a PLC/5? The PLC5 does not have a decode instruction, so this is one way to implement it.

2**0 = 0001 = 1
2**1 = 0010 = 2
2**2 = 0100 = 4
2**3 = 1000 = 8

The value N103:1-1 cannot be greater than 15.
 
Don't know if it's what you have going or not, but I use the MEQ instead of the SQI instruction as a test for step completion when programming sequencers. I also use MVM with indexed addressing instead of SQO. There are a bunch of reasons for this. Like I said, it may not be what you have going on, but it's a possibility.
 
As its a 5/05 I'm curious about why the DCD instruction was not used.

Perhaps the original programmer had done a similar task on a PLC/5 and just used the method he knew and/or he was unaware of the DCD instruction.

Out of curiosity, where does the value in N103:1 come from? Is it some sort of machine state or step number?
 
Last edited:
N103:1 apears to be the station number 1-10 dependent on the product requirements from the blending system.
 

Similar Topics

I am latching and unlatching "result_Data_latch" bit within same rung. Will This copy/move instruction execute correctly??
Replies
4
Views
204
Hi All, I have a click plc the I need to bit strip and 16Bit int. This is to get the alarms from these bits in the int. Do anyone know how to bit...
Replies
1
Views
517
In Easy Builder Pro: Unexpected results... I've got a toggle switch set to trigger a macro to write a specified integer or a 0 depending on the...
Replies
7
Views
2,323
Good Morning , Since I’m loading a new laptop , what are you doing for the 32 bit FactoryTalk View projects that you run into ? Are you...
Replies
8
Views
3,828
Is K4M101 a constant? Is K7 a constant? What does this instruction do? Thanks
Replies
19
Views
5,149
Back
Top Bottom