How can you mask an output card in Step 7?

O

Thread Starter

o4a0e1

G'day,

I'm new to this forum and to Step 7, so Hi to all and thx Siemens... What I'm trying to do is use 3 outputs on a card as a BCD to another device. I'm getting some obvious issues and would like to find out the best way to overcome them.

I'm using a S7-300 PLC and programming in statement list. I'm loading a decimal value, when an alarm happens, and transferring it to the output byte, which works well in the simulator. Now if I do this with the actual PLC... the rest of the card becomes useless because I'm writing to the whole card during my load and transfer statements, which means the other outputs are written to as well. I tried to make sense of the help file with the AW (and word) statement, as I have seen something like this before for "masking out" part of the byte so the rest of the card works for anyone else who comes along later and programs, but I couldn't do it. Is there an easier way? If not... Does AW work in a binary mode? Thx.
 
D
First, transfer the decimal value to a storage byte. Next use another storage byte to hold the results of your bit manipulation that will be writing to the other 5 output bits. Finally and both storage bytes together an transfer the results to the output byte.

David Adams
 
Hi,

Thanks for your reply.

I was going to do it that way, but I would have used a fair few m bits... I'm using 3 outputs as a BCD to another small PLC... So if I want to want to turn on say output 3 on card 7,

L 8
T QB7

and then for another alarm to the second PLC could be outputs 3 and 1 on card 7,

L 10
T QB7

As outputs 4 to 7 are spare at the moment, it's not a problem, but if I use them later, then the Load and Transfer will overwrite the new code... So I need to use the AW (and word) command, but I'm not sure how it works. I think it will mask out the outputs that I'm not using, so that they can be written to later without any problems...

Cheers
 
M

Michael Griffin

The conventional way of modifying certain bits in a word without affecting the rest is to use an AND with mask followed by an OR.

For example:

Temp1 = Destination AND 0x07
Temp2 = Source AND 0xF8
Destination = Temp1 OR Temp2

With a PLC though, nobody will thank you for doing it this way because it won't show up in a cross reference in an obvious way.
 
L

Luca Gallina

dear Michael,
I disagree with your last statement.

Masking an output byte is a commonly used method, regardless in PLCs or any other platform, and it's more elegant than chopping a number into a series of flags to be output separately. We just should do the masking in the proper place and possibly comment it out clearly.

If it were up to me, a mask using AND and OR instructions (just like your example) is the "obvious" way to go ;-)

Kind regards
Luca Gallina
 
Top