Step 7 Constant Values NOT Variables

timryder

Member
Join Date
Feb 2007
Location
Macomb MI
Posts
176
I'm from the Allen-Bradley world, when we have an instruction on the ladder and if we want to use a constant value instead of a variable we just put it in there... apparently I can't just insert a number as the second argument in a DIV instruction. So what do I do?

I want to divide ID298 by 1000 and move the value out to MD300

IN1 = ID298
IN2 = 1000 (What do I put here)
OUT = MD300

Thanks for the help.
 
What data type is it DINT or REAL.
If you type in 1000 the software assumes INT
If you want a DINT type in L#1000
If you want a REAL type in 1000.0

Step 7 does strict type checking so your data types must match.
 
I was able to figure out what I needed to do. Ultimately I was trying to Divide a Real number (Stored as a DINT) by another real and output result to a real.

Had to use the DI_R instruction to first convert the DINT to a real which basically just adds a xxxxx.0 to the end of your value. Then I had to do a DIV_R which will divide 2 real numbers and output the result into a real. That worked perfectly for me. So if anyone ever comes across this thread that's how you do it.

DINT-REAL-DIVISION.jpg
 
DINT and REAL store their numbers in completely different formats within a binary number. You can't store a REAL number in a DINT.

This will show you what a DINT looks like stored as binary:
http://www.binaryconvert.com/result_signed_int.html?decimal=050

This will show you how REAL numbers using IEEE 754 look like stored in binary format:
http://www.binaryconvert.com/result_float.html?decimal=050

They are completely different.
A REAL 2 would be 01000000 00000000 00000000 00000000
A DINT 2 would be 00000000 00000000 00000000 00000010
 
Tim,

As Mike said, S7 does type checking. When you type '1000' vs '1.0e+003' into the editor, it interprets totally different data and therefore compiles that for the processor in a different manner. It looks specifically for the decimal point and exponent to identify a constant REAL (if you leave off the exponent the editor converts it for you). For integers, it looks for prefix defining length (B#, W#, or L#) then the value as a decimal or a 16# for the value as a hexidecimal (i.e. W#16#FFFF is a single word, 16-bit integer).

Although the DI_R function works for you, that's not what you really want. If your'e using a DIV_R operator, you should use '1.0e+003'

-----
Sorry, after logging in to post I saw the attachment and realized I misunderstood your post. Yes, if your input format is an integer a DI_R conversion is necessary.
-Nate
 
Last edited:
Thanks Guys,

This world of Siemens can be PRETTY overwhelming when you're under the gun and time is crucial. So far everything seems to be working fine and now that I know what to expect there is a lot more available to the engineer through Step 7, you just need to know what's available and how to use it. I am working with a RexRoth IndraDrive servo motor over Profinet and there is nothing out there for how to setup the communication and how the bits handshake. Their documentation is GermEnglish which is really hard to interpret sometimes. But I'll make a nice tutorial and post my stuff on a new thread so anyone searching in the future will have help. As most of you probably already know ( i didn't ) Siemens like to reverse byte ordering within a word. So all of the addressing done by the Servo Controller is reversed which took some tinkering. Ah the joys :)

Thanks all again.
 
Tim,

Look at the CAD and CAW STL instructions to reverse the byte sequence in words / dwords.

Oh - its AB that has the byte sequence all messed up! :ROFLMAO:
 
Tia portal is a lot more user friendly though than step 7. So much easier to use once you get used to it.

If yu have spare time and you pc is powerful enough, it's worth requesting a free trial download from their website.
 
I have the TIA portal and WinCC v13 which I needed for the HMI KTP400 I used on the project. But I didn't feel like purchasing another license for the Step 7 v13 just yet. I plan on it for the next Siemens project which will likely come soon.

Again though this was my first big adventure in Siemens projects which were using more than discrete logic. Was lots of fun and learning.
 
I have the TIA portal and WinCC v13 which I needed for the HMI KTP400 I used on the project. But I didn't feel like purchasing another license for the Step 7 v13 just yet. I plan on it for the next Siemens project which will likely come soon.

Again though this was my first big adventure in Siemens projects which were using more than discrete logic. Was lots of fun and learning.

I'll agree with Diameter157, Portal is a much better environment than the older Simatic Manager, at least when it comes to learning. The hotkeys will change with the whole UI, but the programming concepts all carry over. If you have the opportunity, using a 1500 instead of a 300 will make it easier to program as well.
 

Similar Topics

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,191
I am having a step7 v5.4 program where the blocks are encrypted and locked. And the manufacturer is stopped the support. Is there any ways to...
Replies
2
Views
225
Good Morning, Hoping someone with some Siemens experience can give me a hand with this one. Customer has a S7-200 cpu, which has a 6GK7...
Replies
0
Views
271
HI! HOW COULD I OBTAIN THE NAMES OF THE STEPS OF A ROUTINE IN SFC LANGUAGE IN STUDIO5000? Or is there a system variable that gives me those...
Replies
0
Views
363
I'm just trying to figure out the right method of adding a DO card to an existing rack. It's not the *next* open slot, but I have to move the AO...
Replies
5
Views
592
Back
Top Bottom