Initializing Instance Data Block in Siemens

yamangold

Member
Join Date
Nov 2004
Location
Plymouth
Posts
16
I am trying to find a way to initalize all my STAT data inside a FB to zero every time I call the FB. I have created instance Data Blocks for calling the FB. I was hoping to simply use a Fill Block (SFC21), but I can not figure out what the any pointer needs to point to... I can have the ANY pointer point to the specific instance data block, but I use the same FB for multiple Instance Blocks.
Does this even make sense?
Thanks!
 
Hello yamangold,

I'm not at work so I can't check the SFC21 and its parameters.

However, you can use the two following instructions in order to know which Instance DB is open and how many bytes long it is:

L DINO // Load (to ACCU1) Instance DB number that is open
L DILG // Load (to ACCU1)number of bytes of the current Instance DB

Then just program a small loop to set all the bytes of the DB to zero.
 
Is there really a need for an instance DB if you are going to clear it out each time?

The whole idea of an FB is to maintain state between calls and that is not the intent in this case. A FC using a DB would work too and would take less memory because only one instance of the data is allocated.
 
Thanks for the responses everyone.

So based on what Peter said I think I should be using a FC and not a FB. I have no need to save value states between calls, and freeing up DB memory would be a plus! As long as I can call this FC over and over again throughout my calling blocks.

So now the question is how to initialize the temp data in the FC? Or is this data initially zero every time the FC is called? I understand that I need to initialize the output data.

Thanks again!
 
Thanks for the responses everyone.

So based on what Peter said I think I should be using a FC and not a FB. I have no need to save value states between calls, and freeing up DB memory would be a plus! As long as I can call this FC over and over again throughout my calling blocks.

So now the question is how to initialize the temp data in the FC? Or is this data initially zero every time the FC is called? I understand that I need to initialize the output data.

Thanks again!

The initial values are set inside the FC in the Variable Declaration Table. When you call the FC, the tags will have those values, which are not necessarily zero.
 
Fariam, not sure if I am doing something wrong but I dont see a column for initial values in the FC.. this column only seems to show up for FB's..
 
Fariam, not sure if I am doing something wrong but I dont see a column for initial values in the FC.. this column only seems to show up for FB's..

You're right, I checked and you can't initialize values on FCs, only on FBs. Heh, I haven't used FCs for a long time, I've always preferred FBs. If the problem is the amount of DBs, then I use multi-instance.

However the amount of DBs is not a big issue, there's plenty of them unless you are using a low range CPU.
 
Can you post an example of the processing ?
If the values are all zero then why not load zero in the processing instead of loading the variable ?
 
Most of the variables do not need to be initialized as they are always calculated.. some of the variables are only calculated on a conditional basis, so rather than go through and determine which vars need to be initialized I was hoping to just initialize everything.
 
With that number of variables I'd go back to the FB + STATs and then write an FC that will fill the stat area:

fillstat.JPG
 
Source code for FC1 as follows:

Code:
FUNCTION FC 1 : VOID
TITLE =
VERSION : 0.1
 
VAR_INPUT
  pFirst : POINTER ; 
  pLast : POINTER ; 
END_VAR
VAR_TEMP
  pSrc : ANY ; 
  pDest : ANY ; 
  rReal : REAL ; 
  iSFC20Return : INT ; 
END_VAR
BEGIN
NETWORK
TITLE =
      L     0.000000e+000; 
      T     #rReal; 
      L     P##pLast; 
      LAR1  ; 
      L     P##pFirst; 
      LAR2  ; 
      L     D [AR1,P#2.0]; 
      L     D [AR2,P#2.0]; 
      -D    ; 
      SRD   5; 
      L     W [AR1,P#0.0]; 
      LAR1  P##pSrc; 
      T     W [AR1,P#4.0]; 
      TAK   ; 
      T     W [AR1,P#2.0]; 
      L     W#16#1008; 
      T     W [AR1,P#0.0]; 
      L     D [AR2,P#2.0]; 
      T     D [AR1,P#6.0]; 
      CALL SFC 21 (
           BVAL                     := #rReal,
           RET_VAL                  := #iSFC20Return,
           BLK                      := #pSrc);
      SET   ; 
      SAVE  ; 
END_FUNCTION
 

Similar Topics

I upgraded Factorytalk activation manager to version 5.01 from 5.00 and since then, Factorytalk Assetcentre stopped working! I receive the...
Replies
1
Views
459
Hey guys, I've been trying to configure AssetCentre to backup FactoryTalk View SE. For that, I restored a backup from an application. At the...
Replies
6
Views
4,931
I have a customer with a Kinetix 350 servo drive. They were having issues with the old servo motor so they replaced the servo motor with a new...
Replies
18
Views
8,361
hello I am facing a problem! we have a TSX17 old telemecanique PLC on a machine the machine was off for a several years so the PLC battery has...
Replies
9
Views
3,428
hi everyone. i have 1746-hsce2 card (class 4) that i cannot get initialized. it returns a programming error each time the counter config block...
Replies
2
Views
1,801
Back
Top Bottom