Convert WORD to BITS

henno2000 said:
Hi, Using S7, is there a simple way to convert a WORD into 16 bits?

Regards,
henno2000


What data type are you talking here, M Flags, Inputs, Outputs or or parameters passed into other blocks or TEMP/STAT words?

If Flags, inputs or outputs its easy, MW4 is also M4.0 to M5.7, similar for inputs and outputs.


If you have passed a word to into a block (like status word) and you want to use the bits in that block, then you would have to create TEMP boolean addresses for all 16 bits and do a block move SFC20.


If that is what you want then I or someone (or probably Simon as he's dead quick) can take you thorough how that is done.
 
A WORD already is 16 bits. It's just how you look at it.

For instance, if the WORD is a marker (M) locations, such as MW100, you can look at individual bits just by referencing them at the bit level (M100.0, M100.1, ... , M101.6, M101.7).

The same applies for data block values DB10.DBW10 can be referenced at the bit level (DB10.DBX10.0, DB10.DBX10.1, ... , DB10.DBX11.6, DB10.DBX11.7).

This is one of the things I really like about the Siemens products. All the memory is just memory. How you look at it determines what it means.

I hope that is what you were asking.

Keith

PS: I type too slow.
 
I am wanting to decrypt the status word sent from a drive and obtain the bits (IE - drive running/drive ready etc)

Regards,
henno2000
 
The simplest method is to create 16 consecutive bits say M8.0 to M9.7 and name these as per the status word bits (remember to get the byte and bit order correct) then transfer the status word into it.

example using M8.0 to 9.7 as above.

Code:
 L #Status_Word
 T MW 8

You can then use the bits from the flag word.


for more info see this thread:

http://www.plctalk.net/qanda/showthread.php?t=5872&highlight=sfc20
 
You could use a generalised word to bit mapper function as shown below:

Code:
FUNCTION FC 1 : VOID
TITLE =
VERSION : 0.1

VAR_INPUT
  wWord : WORD ; //w#16#1 will result in bit0 being true
END_VAR
VAR_OUTPUT
  bBit0 : BOOL ; 
  bBit1 : BOOL ; 
  bBit2 : BOOL ; 
  bBit3 : BOOL ; 
  bBit4 : BOOL ; 
  bBit5 : BOOL ; 
  bBit6 : BOOL ; 
  bBit7 : BOOL ; 
  bBit8 : BOOL ; 
  bBit9 : BOOL ; 
  bBit10 : BOOL ; 
  bBit11 : BOOL ; 
  bBit12 : BOOL ; 
  bBit13 : BOOL ; 
  bBit14 : BOOL ; 
  bBit15 : BOOL ; 
END_VAR
VAR_TEMP
  bTempBit0 : BOOL ; 
  bTempBit1 : BOOL ; 
  bTempBit2 : BOOL ; 
  bTempBit3 : BOOL ; 
  bTempBit4 : BOOL ; 
  bTempBit5 : BOOL ; 
  bTempBit6 : BOOL ; 
  bTempBit7 : BOOL ; 
  bTempBit8 : BOOL ; 
  bTempBit9 : BOOL ; 
  bTempBit10 : BOOL ; 
  bTempBit11 : BOOL ; 
  bTempBit12 : BOOL ; 
  bTempBit13 : BOOL ; 
  bTempBit14 : BOOL ; 
  bTempBit15 : BOOL ; 
END_VAR
BEGIN
NETWORK
TITLE =word to bit mapper
	  LAR1  P##bTempBit0; 
	  L	 #wWord; 
	  CAW   ; 
	  T	 W [AR1,P#0.0]; 
	  A	 #bTempBit0; 
	  =	 #bBit0; 
	  A	 #bTempBit1; 
	  =	 #bBit1; 
	  A	 #bTempBit2; 
	  =	 #bBit2; 
	  A	 #bTempBit3; 
	  =	 #bBit3; 
	  A	 #bTempBit4; 
	  =	 #bBit4; 
	  A	 #bTempBit5; 
	  =	 #bBit5; 
	  A	 #bTempBit6; 
	  =	 #bBit6; 
	  A	 #bTempBit7; 
	  =	 #bBit7; 
	  A	 #bTempBit8; 
	  =	 #bBit8; 
	  A	 #bTempBit9; 
	  =	 #bBit9; 
	  A	 #bTempBit10; 
	  =	 #bBit10; 
	  A	 #bTempBit11; 
	  =	 #bBit11; 
	  A	 #bTempBit12; 
	  =	 #bBit12; 
	  A	 #bTempBit13; 
	  =	 #bBit13; 
	  A	 #bTempBit14; 
	  =	 #bBit14; 
	  A	 #bTempBit15; 
	  =	 #bBit15; 
	  SET   ; 
	  SAVE  ; 
END_FUNCTION

Here's an axample call:

wmapper.JPG
 

Similar Topics

Hi! I've got a problem. There is a direct link method of communication between 2 Quantum PLCs. PLC1 HEX word to PLC2 - OK, i.e. converting from...
Replies
3
Views
7,127
Hello, I am new to Codesys 3.5 and I am trying to figure out how to convert a word into 2 bytes to send to another plc via ethernet/ip. Could...
Replies
5
Views
5,059
Thank you so much for your help! I am trying to use an INT or DINT as a setpoint for my remote device using Modbus TCP/IP. My code is...
Replies
2
Views
2,372
I may be being a bit slow here but is there any way in Step 7 that you can convert a Word value to a signed integer value? Am sure its possible...
Replies
5
Views
8,178
Hi, Im having a practice with a Siemens MM420, using siemens S7 via profibus, im struggling with the status PIW speed ref. I want to convert this...
Replies
9
Views
3,407
Back
Top Bottom