JesusRCh

Masked moved instruction

12 posts in this topic

Hi guys, I'm studying the Masked MVM instruction. Now I know what it does but can anyone tell me an example of an application in real life. I mean where would I use it? If I'm integrating something and I have to use that instruction, what would it be?

Thanks in advance.

Share this post


Link to post
Share on other sites

I was just looking at the help info for that instruction. It didn't make sense. A mask value of 0 is supposed to block the source bit and 1 passes the source bit yet 

Input a = 0101 0101 ... etc

Mask = 1111 0000 ... etc

Output = 1111 1111 ... etc

Description

The MVM instruction uses a Mask to either pass or block Source data bits. A "1" in the mask means the data bit is passed; a "0" in the mask means the data bit is blocked.

If you mix integer data types, the instruction fills the upper bits of the smaller integer data types with 0s so that they are the same size as the largest data type.

 

So basically I'm just camping out on your post to get an explanation that's useful.

Share this post


Link to post
Share on other sites

have not used MVM and don't have PLC to try it but, like with all asked operations, previous value of the target matters.

so if initial case is: 

Input a = 0101 0101 ... etc

Mask = 1111 0000 ... etc

Output = 1111 1111 ... etc

then after execution of MVM, i would expect output to become: "0101 1111 ...." because mask tells to overwrite four left most bits of the Output, and do not change the next four.

 

So my I would expect that MVM is basically 

temp1  = Input AND Mask

temp2 = Output AND NOT Mask

Output = temp1 OR temp2

 

1 person likes this

Share this post


Link to post
Share on other sites

MVM is rarely used but it does not work the way @Michael Lloyd described. Quite irritating when the book is wrong. Here's what's happening:

  • Source is the original data
  • Destination is where you want it to go
  • Mask is like a coffee filter that the original, raw data passes through to remove what you don't want it gets to the Destination.

To be clear, in the Mask, 1s are true and allow data to pass; 0s are false and do not allow data to pass. In the example mentioned above, if the original word value of 01010101 (170 decimal) is passing through a mask of 11110000 (15 decimal), then the data at the Destination would be 01010000 (10 decimal).This works whether moving data from one array to another, or moving data around in real-world IO.

I've attached three screen shots showing the tag monitor that proves this out on 1756-L7 controller using V32. I'm using Copy_Dummy[8] as the Source, Copy_Dummy[9] as the Mask, and Destination_dummy[0] as the Destination. 

As for the OP's question, you can use this instruction to conditionally ignore certain digital data, like inputs on a, IO card, or to filter out unwanted decimal places in analog data, etc. However, there are a hundred other ways this can be done so like I mentioned above, you won't see this instruction very often.

Hope this helps.

 

MVM Example.pdf

3 people like this

Share this post


Link to post
Share on other sites

Thanks for replying guys I appreciate it.

Yeah that's what I understood about this instruction. Basically is a filter of bits. @ElectronGuru You are saying that I can use this instruction to filter out unwanted decimal places in analog data. Can you explain this example with baby steps. Like where are you getting the data from, where you are sending it, for what purpose, why did you decide to do that? etc.

I don't want to sound annoying but I'd like to fully understand this instruction.

Thanks in advance

Share this post


Link to post
Share on other sites
4 hours ago, ElectronGuru said:

To be clear, in the Mask, 1s are true and allow data to pass; 0s are false and do not allow data to pass. In the example mentioned above, if the original word value of 01010101 (170 decimal) is passing through a mask of 11110000 (15 decimal), then the data at the Destination would be 01010000 (10 decimal).This works whether moving data from one array to another, or moving data around in real-world IO.

I've attached three screen shots showing the tag monitor that proves this out on 1756-L7 controller using V32. I'm using Copy_Dummy[8] as the Source, Copy_Dummy[9] as the Mask, and Destination_dummy[0] as the Destination. 

@ElectronGuru  What your examples fail to show is that the destination remains unchanged where the mask bit is a zero.

If for example the destination already contained high bits in the destination:

Source - 1010 1010 - 170 Decimal

Mask - 0000 1111 - 15 Decimal

Destination 1111 0000 - 240 Decimal

After the MVM instruction is executed the destination will be

Destination 1111 1010 - 250 Decimal 

1 person likes this

Share this post


Link to post
Share on other sites

@chelton that's an excellent point. Thanks for bringing it up and showing a great example. Since the mask value 0 filters out source data from getting to the destination, the masked destination bits would remain unchanged after the MVM execution because the 0s are blocking any source data (0 or 1) from being written to those destination bits. This is just one more reason the MVM instruction isn't used that often. 

@JesusRCh I believe I miss-spoke myself regarding filtering out decimal places using MVM. When I worked in a power plant we used a lot of 16 bit transmitters to monitor things like oxygen levels, airflow, differential pressure, etc. Eight bits were the value of what was being measured (% of O-2, cubic feet of airflow per minute, etc) and eight bits were the status of the instrument, itself (run mode, calibration mode, alarm, etc). When moving something like the airflow data to an operator's view (like a DAQ station or LED display), we would use MVM to mask out the status bits. This would keep the display from showing extraneous data or outright gibberish. I had incorrectly remembered this as filtering out decimal places and spoke without thinking. Sorry 'bout that. 

At any rate, with the addition of Chelton's example above and the fact that we've both shown MVM is pretty limited, it's not likely an instruction you're going to run across often. 

1 person likes this

Share this post


Link to post
Share on other sites

@chelton That was a very good observation, thank you.

@ElectronGuru 

On 9/5/2021 at 11:49 PM, ElectronGuru said:

I had incorrectly remembered this as filtering out decimal places and spoke without thinking. Sorry 'bout that.

No problem, I really appreciate your time and patience. I can perfectly understand the example. Thanks you.

Share this post


Link to post
Share on other sites

@Michael Lloydout of curiosity I looked up and read the book description on MVM and I don't think the description is wrong, so much as poorly written. It specifically states that the picture shows the instruction before execution. To my way of thinking, they should show a before and after, but that's why it kind of misleads a person about where the 1s and 0s should be.

1 person likes this

Share this post


Link to post
Share on other sites

Ok now that everyone gets how it works the original question was why would you use it.

Generally I have used this instruction to sort out information from communication with a non AB device or a blob of data from some other device.  For instance if you have a DINT where not all of the bits are pertinent poop, you may mask out the unnecessary stuff to make it easy to do comparisons.  I use this in conjunction with some GSV statements that store certain data in 4 bit lumps.  I can mask out everything else and then do simple comparisons with the result.  I actually think I got this right out of the book for checking comm status on system modules.  Granted, in retrospect, I could have just done the comparisons using bits...  But mine goes to 11  (maybe someone will get that reference).

Screen Shot 2021-09-09 at 2.43.18 PM.png

1 person likes this

Share this post


Link to post
Share on other sites

spinal tap i guess...

not sure why one would use MVM. obviously it could be used to extract of combine data when information is packed. while use may be limited, it should be straight forward and reduce clutter that would otherwise be needed to accomplish the same thing. but i tend to like basic instructions, those that are found on every platform. this means operation is more transparent and code is easier to port to other platforms that may not have the special instruction. in fact i am still by number of posts where users are asking for specific instruction to solve their problem rather than try to just implement equivalent using what is already there...

personally, i am always on a lookout for tidbits to add to my toolbox...then when creating an application i have ready bits and pieces to throw in and get results quickly and reliably (since each clock is already thoroughly tested on previous jobs). 

Share this post


Link to post
Share on other sites

I have used mvm in the past to latch alarms for hmi's etc in PLC5 days.  My alarms in the plc logic were OTE instructions.

For my hmi alarms I would simply MVM source "alarm word" with mask "alarm. word" destination "HMI alarms".

If any bit in "alarm word" goes high,  corresponding bit in HMI alarms goes high and remains high.

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