s7300 pointer revisited

kdeadman

Member
Join Date
Mar 2009
Location
Thunder Bay
Posts
6
Hello, I'm working on a S7 313C cpu and i am trying to use a pointer to grab a double integer data from a DB and move that value into the first register in that DB to be used as the output register.

i am looking for a check on my code to be sure that it will be correct or at least it should be doing what i expect it should be doing as i do not have a simulator to be able to check this.

Code:
 OPN   "75K BST CHART"             // whatever DB you are using
      LAR1  P#DBX 0.0                   // Load address register 1 with a pointer into open DB
      TAR1  MD    50                    // Save address base into a DWORD for later

      L     #Curr_Idx                   // Index into the actual double integer of the DB you want
      L     4                           // If indexing Dwords, Reals, multiply by 4,
      *D                                // Curr_Idx increments by 1 for each element 
      SLD   3                           // Shift left 3 places to make offset a Pointer
      LAR1  MD    50                    // Load AR1 with the base pointer
      +AR1                              // Adds in the calculated value above to AR1
      L     D [AR1,P#0.0]               //Loads value from register in DB into accum1
      T     DBD    0                    //transfer our value into the first double of the DB called "output".


This is a function call that I pass it a double integer from 1-115 and the DB has 116 DINTs(output is first element and 2-116 are the indexed elements). so if i need element 42 from the list i pass it 42 and it will move the data from the 42nd element into the first element.

I hope this makes sense.

K
 
The code does do as you require. Here's my implementation for comparison:
Code:
      OPN   DB     1                    // whatever DB you are using
      L     #Curr_Idx                   // Fetch Index of the actual double integer required
      SLD   5                           // Shift left 5 places for Pointer to dwords
      LAR1                              // Load AR1 with the pointer
      L     DBD [AR1,P#0.0]             // Loads value from register in DB into accum1
      T     DBD    0                    // transfer our value into the first double of the DB called "output".
 
Multiple opening of Different DB

I have a new question.

When i use this function (FC9) to open a DB (DB4) i cannot then use a second function FC8 to open DB2 to do the same code just on a different Data Block?

Do i need to close the Shared DB before i can open a new Shared DB? and how do i do that?

Thanks
Kris
 
What i was trying to do was with 2 different functions, open 2 different DB with them (one DB in each function) and basicaly do the same thing on both DB.

this is FC8

OPN DB 2 // whatever DB you are using
L #Curr_Idx // Fetch Index of the actual double integer required
SLD 5 // Shift left 5 places for Pointer to dwords
LAR1 // Load AR1 with the pointer
L DBD [AR1,P#0.0] // Loads value from register in DB into accum1
T DBD 0 // transfer our value into the first double of the DB called "output".

This is FC9
OPN DB 4 // whatever DB you are using
L #Curr_Idx // Fetch Index of the actual double integer required
SLD 5 // Shift left 5 places for Pointer to dwords
LAR1 // Load AR1 with the pointer
L DBD [AR1,P#0.0] // Loads value from register in DB into accum1
T DBD 0 // transfer our value into the first double of the DB called "output".

both of these functions are called within other different functions.

they do the same thing but to 2 different data charts.

when i was using this though only FC9 would work. if i changed FC8 to reference the same DB as FC9, it would work.

so Do i have to find a way of closing the DB opened in FC9 before i Open the DB in FC8?

I hope that helps
 
You cannot close a DB, you can only open one. However, the currently open DB is saved when you call an FC, if you open a DB inside the called FC, the original DB will be opened upon returning from the called FC. Here's an example that shows what's going on:

db009009.jpg
 
I think you can define the db as a "in" of type integer
Then in the FC you say

L iDbNumber
T Temp.something // this is of the type Word

Opn DB[Temp.something]

So no you give the number of the DB you want to work with in the FC when you call the FC
 
Code:
      OPN   DB     1                    // whatever DB you are using
      L     #Curr_Idx                   // Fetch Index of the actual double integer required
      SLD   5                           // Shift left 5 places for Pointer to dwords
      LAR1                              // Load AR1 with the pointer
      L     DBD [AR1,P#0.0]             // Loads value from register in DB into accum1
      T     DBD    0                    // transfer our value into the first double of the DB called "output".


Hi Is there any reason why the final move (T DBD 0 ) could not be moved to the block output directly? I realise the OP wanted it to be posted into the first dword of the datablock.

I am considering using spmthing like this but with a struct of 3 dwords for each lookup.

Cheers
 

Similar Topics

How can I integrate my S7-300 Simatic with the IFM AS-i Master AC1335 and its slave IOs, such as 2411 and Airbox 2041, into Simatic Manager?
Replies
0
Views
156
Hello everyone, One of our machine we use Siemens Cpu315-2dp. And this cpu communicate with 4 Lenze servo drives series 9300 via profibus. Also...
Replies
0
Views
200
Hi guys, I'm having problems converting WinAC (WinLC RTF F application) to S7 300 project based on CPU 319F-3PN or S7 400/416F-3PN. The problem is...
Replies
0
Views
631
Hi Any one here please helpmein simulation of s7 300 plc program with factory io. how to connect. plcsim 5 doesnot have option of s7 300 ..:
Replies
2
Views
1,047
Hi to all, Our company does not usually use Siemens PLCs, but have a press with one in it. We are trying to change the IP address in our Simatic...
Replies
2
Views
1,089
Back
Top Bottom