S7-300 trouble direct addressing within FB STL

minerman

Member
Join Date
Nov 2012
Location
Columbus, OH
Posts
82
I have an FB that I'm trying to write to a data array inside of it's local DB.

I am trying to:
T LW 2272

So 2272 / 8 should give me local address 284.0, right?

When I attempt to download the program it says the address is out of range.

I'm new at this, maybe I don't understand how the local addressing works?
 
The 'local DB' is the instance DB and can be accessed with DIX/DIB/DIW/DID and in your case DIW 284 is relevant.

The LW accesses the Temporary memory stack, and byte 2272 is probably out of range for your CPU type.

Kalle

PS! Post your code, it might be more uncovered pitfalls.
 
Here's the STL code that I'm having trouble with...

Other than #temp_pointer, the other variables are loaded elsewhere...

Code:
A #S_Timer_Done
JC N33A
JU N33B
 
//Load S Count into Array if timer is done
 
N33A: L #S_Count_Array_Pos
L 284
+I
T #Temp_Pointer
L #S_Counter
T DIW [#Temp_Pointer]
 
//Clear S Counter
 
L 0
T #S_Counter
 
N33B: NOP 0

My data is not making it into the array. I am positive the array starts at 284.0 I can do a DIW 284 in a separate rung and it makes it there. I have verified that I do get the S_Timer_Done bit true, so that is not the issue.
 
Pointers resolve down to the bit address so if you want to access a byte then you must multiply by 8 or SLD 3, however, you have an array of words so a SLD 4 is required. I've added the offset by loading the pointer format directly.

Code:
A #S_Timer_Done
JC N33A
JU N33B   
//Load S Count into Array if timer is done
N33A: L #S_Count_Array_Pos
SLD 4 //index into array of words
L P#284.0 //offset to start of array
+D
T #Temp_Pointer 
L #S_Counter
T DIW [#Temp_Pointer]   //Clear S Counter   
L 0 
T #S_Counter   
N33B: NOP 0
 
Last edited:
Also note that if you use this FB as a multiple instance your DIW addressing will fail.

Yeah, I actually am using it in multiple instances, each with a separate data block, of course. It seems like Kalle was thinking the DIW would be referenced locally, so why would it fail?
 
You must be correct about the multiple FBs, because its not working. How do I make it work?

It's just constantly loading into the first register. I don't understand.

I just attempted taking the offset out. No luck. Now, I'm not recording at all, despite the fact that I am storing 284 in the S_Count_Array_Pos number now.
 
Last edited:
If you are calling each FB with it's own instance DB, this is not multiple instance so your code will be ok under these circumstances.
(multiple instance refers to when you embed FB's into the stat area of another FB, you can then use one instance DB and it will contain all the instance data of all the FBs)
 
Last edited:
Create a library, insert an S7 program into it, copy your blocks to the library, archive it and then post as an attachment.
 
Here's some test code that works - I'm incrementing the array index after each write and the data I'm writing is the array index + 100:

diwa.jpg
 

Similar Topics

Hello, I have my S7 PLC on my desk, it is the CPU only. Is it possible to get this thing to run my program without the associated IO attached...
Replies
4
Views
3,936
I am having some problems getting our laptop we just got to communicate with the Panelview 300 MMI through the DF1 port. I tried switching the...
Replies
1
Views
2,162
Hi, I want to start experimenting with the TP 170A and S7 312. I have the PLC soft and hardware and PC cable and I got a TP170A to test with...
Replies
4
Views
3,637
I'm attempting to download an application to a PV300 terminal, but I cant seem to get RSLinx to connect to the terminal:smas: . I am using an...
Replies
11
Views
4,518
Greetings! I've encountered strange trouble trying to establish online connection with PLC using Step7 (Simatic S7-300 station, CPU 3152DP) We...
Replies
3
Views
12,114
Back
Top Bottom