S7 Constant Format

Join Date
Jun 2012
Location
England
Posts
64
Hello
Does anybody know how to enter an integer constant in LAD?

I am trying to use an OR block to turn some bits on in a Word. I know I can turn Type-Checking off and it works, but I am trying to keep everything in LAD so that it’s easy to follow for the maintenance guys.
Thanks

Constant-Format.gif
 
For a WORD:
Format the value as a hexadecimal constant this way:
W#16#nnnn
For example W#16#0100 is hexadecimal for 256 decimal.

edit: Just to make it absolutely clear.

For an INT:
Format as a nnnn decimal without fraction.
For example "256"

For a DINT:
Format as a L#nnnn decimal without fraction.
For example "L#256"

For a REAL:
Format as nnn.mmm floating point with decimal part and fracion part.
For example "256.0"
STEP7 often convert it immediately into scientific notation
 
Last edited:
The block WOR_W expect WORDs. That is why.

Switch to STL to bypass the typechecking.
for example:
Code:
      L     W#16#100
      L     MW    50
      OW    
      T     MW    52

deleteme.gif
 
Last edited:
The error shown in the graphic, states that an Int is expected.
I get the feeling that it might be another Siemens quirk/bug!
I know it works in STL, I just thought I was entering the wrong format LAD.
Thanks for your help Jesper
 
You can turn the type checking off for ladder in the options menu in the ladder editor.

Error messages in Step 7 have to be read very carefully!
 
I wouldnt turn typechecking off.
When I started using STEP7 I found typechecking a nuissance. After I while I changed my mind and found it helpful.
You always have the option of coding in STL if you really want to bypass typechecking, even for a rung in the middle of LAD or FBD rungs.
In that case it is the programmer that decides for some reason to not use typechecking for just the piece of code that cant be programmed with typechecking.
 
I agree that the type-checking is useful. I prefer to keep it on at all times as switching it on and off is time consuming. Switching to STL is also a problem when you have already filled in a block in LAD, it won’t switch until the block is error free or deleted.

Mike, you are right, I didn’t realise the error message could be read in two ways. I read the first part as a statement, the entry is for data type INT... Even more confusing when you type in a Word as Jesper suggested, I got this (see image) when I hit Enter.

I have worked out this message is a bug, as it shouldn't be shown, the entry is correct and if I hit Enter again, it accepts the value.

Constant-Format-word.gif
 
You can make it as binary code and in the ladder logic set the bits representing the value. Give the bit there value as name/symbol so maintenance guys can understand it.

You have now the word with the constant value you want.

Simple and in LAD
 
Thanks Jera, that is a convenient way of controlling bits in Word. I only used the WOR_W because I was dealing with a Profinet output word (PQW). I don’t think bit access is possible directly?
 
You mention PQW, and then you must be aware that it is a peripherial output word, not a 'normal' output word. Special conditions apply.
Read this regarding peripherial inputs and outputs:

The "P" in PQW does not relate to if the outputs are addressed via Profibus or not.
The "P" relates to that the address is outside the process image.
If outside the Process image, the output(s) must be set by a Peripherial access, like this:
L "SomeStatusWord".
T PQW256

Individual bits outside the process image cannot be read or written.
The smallest size of peripherial data that can be read or written is a byte.
It is possible to use an intermediary address, for example a merkerword if you want to access individual bits.
For example:
L PIW256
T MW20
A M20.0 // using one bit from the peripherial input word
= "somestatusbit"
A M20.1 // using another bit from the peripherial input word
= "otherstatusbit"
etc.

But the typical way to avoid this hassle is to assign bits within the process image. Words (for example analog i/o) are typically assigned to addresses outside the process image.
 
Please explain in detail what the application is.
I have a feeling that you are transferring data to and from an intelligent slave. Maybe a drive or a DP/DP coupler. Is that right ?
If that is the case, you cannot do it this way.
 

Similar Topics

I am new to using Functional Block Diagram (FDB) language programming in CCW. I want to set a variable to a constant if a contact is closed...
Replies
7
Views
410
Hello all, this is my first time working with a PLC and dealing with hardware, so please have patience with me. I have an electric rod-style...
Replies
21
Views
3,018
Hello, I have posed a similar question before, but the DB then provided me with pre-allocated "spares". In this instance I need to declare a...
Replies
13
Views
4,121
Hello gentlemen, Why does this work: VAR CONSTANT SIZE_OF_dutEVENT : UDINT := SIZEOF (DUT_Event); MAX_SIZE_OF_dutEVENT : UDINT := 5...
Replies
2
Views
1,605
Hi! I know there is a lot of skilled people with Schneider somachine in this forum, so i have to ask something. How and why do you use constant...
Replies
4
Views
2,197
Back
Top Bottom