S7 symbols bits in a word

Werner

Member
Join Date
Apr 2005
Location
IJsselstein
Posts
336
Hi!

I have a word in a DB with the symbol "Control._word[1]" In this status word the bits have different meanings like "Forward/Reverse/Reset/Enable". For one part of the software I need to use the word and for other parts of the software I'm working with the bits. The problem is because the DB is created as a word the bits don't have symbols. Is there any way to give these bits a symbol.o_O
 
Werner said:
Is there any way to give these bits a symbol.o_O

In a word, No.

As you have defined it in the DB as a word, you cannot individually give each bit a symbol. You could transfer this word to another 'word' in your DB and define the new 'word' as bits, then you can give each bit a symbolic name or do the same but transfer the DB word to a memory word and name each bit of the memory word in the symbol table.

Paul
 
Sorry, Werner, but in standard Siemens (LAD, FBD, IL) programming an object can only be defined once with a name and a datatype. You can not have the same area of memory with two or more names or being treated as multiple datatypes.

However, in Structured Text (SCL, as Siemens call it) you can have this. There is a simple declaration instruction 'AT' which permits this. For example, you could have a function -
Code:
FUNCTION FC1
 
VAR_TEMP
TEST1 : WORD;
TEST2 : ARRAY[0..15] of BOOL AT TEST1;
TEST3 : INT AT TEST1;
END_VAR
 
BEGIN
 
TEST1 := IW256; 
 
IF NOT TEST2[15] THEN 
TEST3 := TEST3 + 128;
END_IF;
 
END_FUNCTION

The original declaration TEST1 is defined as a word at that address. TEST2 is defined as an array of 16 bits at exactly the same address and TEST3 is an integer at exactly the same address. A change to TEST1 is seen as a change to TEST2 and TEST3 and so on ... This way you can mix the operations you carry out on a value : logical; arithmetic etc
 
Werner said:
For one part of the software I need to use the word and for other parts of the software I'm working with the bits.

Could this be solution for you ?

Code:
FUNCTION_BLOCK FB 2
TITLE =
VERSION : 0.1 
 
VAR
CTRLWord : STRUCT 
bit0 : BOOL ; 
bit1 : BOOL ; 
bit2 : BOOL ; 
bit3 : BOOL ; 
bit4 : BOOL ; 
bit5 : BOOL ; 
bit6 : BOOL ; 
bit7 : BOOL ; 
byte0 : BYTE ; 
END_STRUCT ; 
END_VAR
BEGIN
NETWORK
TITLE =
 
	 A M0.0
	 =CTRLWord.bit0 //bit level access
 
	 LAR1 P##CTRLWord; 
	 L	 W [AR1,P#0.0]; //word level access
	 T	 PIW 700; 
END_FUNCTION_BLOCK
 
Nice solution. But in my case I just wanted to make the code more readable. At the point where you use the pointer it is not directly clear what the pointer is referencing (If the code is not as simple as the example you gave). For now I changed my software so that I'm not using the DB any more. Using normal memory I can give the word and bits symbols. (Option given by PLucas)
 

Similar Topics

this a program to send data to barcode printer I want to integrate a new printer in a new machine and i wanted to adapt the old prgram on it but I...
Replies
4
Views
163
Hello to all, Is it possible to export Codesys symbols to .txt, .csv or .xml in a similar manner like exporting symbol table in STEP 7? For...
Replies
0
Views
135
I'm a bit confused about how symbols and UDTs work... As far as I know, in offline mode FB gets symbols from the UDT declared in the "state"...
Replies
4
Views
421
I have a machine that was powered off for repairs, when powered back on the Panelview fails to upload the tag database from the PLC. Its a...
Replies
1
Views
1,543
Looking for some explanation/history between North American electrical symbols standards (how they relate, what are the latest, what is the...
Replies
3
Views
1,716
Back
Top Bottom