Siemens S7 Indirect addressing help

PLCKeef

Member
Join Date
Nov 2005
Location
Australia
Posts
68
Hi all
I need a bit of help with the program below.
I have a thumwheel switch and I want to transfer the left hand three digits to a dat wod specified by the right hand digit.
The program works , but seems to transfer to the wrong data word.
for example if I have 1234 dialed up on the thumbwheel switch , 123 should be transfered to data word 4. But it actuall goes to data word 8?
The data at MW20 seems to be doubled when put into the pointer ?

Any ideas ?
thanks



//Indirect adddressing example
OPN DB 10 //open data block 10 as the resident DB

L IW 124

L W#16#F

AW

T MW 20 //left hand digit on it's own

//

L IW 124

AW W#16#FFF0

SRW 4

T MW 50 //right hand 3 digits on their own

//

//

L MW 20

SLD 4

LAR1 //put the right hand digit in the correct pointer format

//

//

L MW 50

T DBW[AR1, P#0.0] //transfers the data to the DW specified by MW20
 
I still don't understand , looking at what I have below , if MW20 has 4 in it
L MW 20
SLD 4
LAR1

then when I execute the next part

L MW 50
T DBW[AR1, P#0.0]

MW 50 gets transferred to DBW 8 , not 4 as I would expect ?
 
If you want to write to a byte address, you shift the number left 3 bits. You are shifting the number 4 bits left (as you should if you are writing a DBW), hence why you are writing to DBW 8.
 
Ok thanks
But how does 4 become 8 ?

I have
0000 0000 0000 0100
in MW20
I shift it left 4 spaces
0000 0000 0100 0000

so the pointer would be 4.0 ?
 
The bottom 3 bits of a pointer define the bit address, the remainder of the bits (when shifted right 3 bits) define the byte address. Pointer addresses increment as below:

0000 0000 = 0.0
0000 0001 = 0.1
0000 0010 = 0.2
0000 0011 = 0.3
0000 0100 = 0.4
0000 0101 = 0.5
0000 0110 = 0.6
0000 0111 = 0.7
0000 1000 = 1.0
0001 0000 = 2.0
0001 1000 = 3.0
0010 0000 = 4.0
0010 1000 = 5.0
0011 0000 = 6.0
0011 1000 = 7.0
0100 0000 = 8.0
etc.
 
Last edited:
S7 indirect pointing is simple. Pointer (DWORD) points the bit number in open memeory space.

"SLD 3", "LAR1" etc. are not necessary, but mostly helpful.

L L#3
T #Pointer // points bit 3 (from zero)
L L#1
+D
T #Pointer2 // 1-bit more (4) than #Pointer (3)

L DBD[#Pointer] // Loads bits 3-34 to accu
T DBD[#Pointer2]// Writes from accu to bits 4-35
 
seppoalanen said:
S7 indirect pointing is simple

Unfortunately, the code you have posted may have caused more confusion than anything else.

Firstly using the variable #Pointer is not possible because it is a reserved word. I would recommend cutting/pasting example code from the block editor into the thread - that way you can only post code that will be acceptable to the Step 7 block editor.

Secondly, you cannot reference a DBD from any address unless the bit number is zero (i.e. the bottom 3 bits of the pointer must be zero). Attempting to execute this code will cause the plc to fault out with an alignment error. I would recommend running code in the plc simulator before posting it, that way you know the posted code will do as you say.
 

Similar Topics

Hello guys, This works: L P#DBX 30.0 LAR2 But I need "DBX 30.0" to be input parameter to the function. I made pTag variable with data type...
Replies
19
Views
6,372
Hey all, I am currently working on converting many of my company's standard Rockwell Code to Siemens S7, and have run into an issue with indirect...
Replies
6
Views
4,796
I have spent a couple of weeks now hunting around for information to step7 indirect addressing. There are many, many discussions relating to this...
Replies
5
Views
10,362
Yes, I did search for information first. Yes I looked through the limited help files that came with my Step 7. No I do not have any other books...
Replies
77
Views
20,994
I'm new to S7 programming and finding it a whole lot like running backwards through a corn field! I am helping my company develop our current...
Replies
44
Views
31,363
Back
Top Bottom