S7-300 Instance DB's

Join Date
May 2004
Posts
25
Is there any way to initialize variables in an Instance DB?

Example: In FB(X) I am using multiple instances of FB(Y). The Instance DB for FB(X) is DB(X). I would like to initialize the variables for each instance of FB(Y) in DB(X), but the initial values are not editable in either the Data View or the Declaration View. I am currently passing values to the addresses in the Instance DB for the variables I want initialized with move statements in OB100 (warm restart) or OB102(cold restart). This works, but makes a lot of extra code.
 
Marek,

In your FB, when you declare your variables, you should find that there is a column named 'Initial Value'. You can enter a value in here which is used as the basis for all instance DBs of this type.

Once the instance DB has been created, it should contain these values in both the 'Initial Values' and 'Actual Values' columns. You can't edit the initial values, but I've found I can certainly edit the 'Actual Values' for each instance. As far as I know it is these values which the PLC uses for execution.

Regards

Ken
 
Just guessing (because I work only with S7-400), but with the new S7-300 with the MMC card, you can use the function "copy RAM to ROM".
This will put the initial values to the actual values that is active at the time. It should be handy to save the values in one go without having to manipulate the initial values manually.

But I haven't tried this myself, so please verify it yourself (AND post the result here - I would like to know if it really works that way).
 
My problem lies in the fact that for each instance I have want different initial values. Therefore I can't use one set of initial values for the FB I am calling multiples of.
 
When you finish commisioning your project (and have set the actual values with STEP7 or the HMI or whatever) try to use that "Copy ROM to RAM" function.
I believe it will put the initial values to the actual values. And that it will be for each instance DB !
Try it - and let me know the result.
 
Marek,

Can you help - I'm not quite sure why you need different 'initial' values? If you have different initial values (from those defined in the parent FB) then strictly speaking the DBs are not instances of the same object, they are different objects.

What do the 'initial' values give you that the 'actual' values don't? If you download a DB with different 'initial' and 'actual' values to the PLC, it will start running using the 'actual' values. If you switch-off or power-down the PLC with the DB in it, it will start up again using the last known 'actual' values. Do you want to go to a specific set of 'actual' values at a given point during runtime? The only way I can think of achieving this is to use a BLKMOV command or similar.

Regards

Ken.
 
Upon checking up on some FAQs one Siemens support site, I think I can conclude the following:

1. Ken is right that the actual values will remain active, also after a power cycle (IF you have one of the new S7-300 with MMC cards, if it is one of the older ones then its a little bit more complicated).

2. The only reason why someone would want to manipulate the initial values, is if you want to save a "good copy" of the actual values into the initial values.
To use such functionality requires that you use the Copy-RAM-to-ROM function AND that the DBs in question get the non-retain flag set:
[attachment]
(again, as I am not 100% proficient in S7-300, you must verify this to be certain !)

dbnonretain.gif
 
Ken, this is inherited code so I am just trying to modify the original content without rewriting the entire program. Let me give an example of why I need different initial values.

FB10 has 4 instances in FB20. FB10 is a generic block for monitoring levels. Each instance controls a different device and monitors a different set of inputs.

The Instance DB for FB20 is DB20

FB10 has 4 inputs and 2 outputs.

Instance 1 has a range of DB20.DBD0 - DB20.DBD28
Instance 2 has a range of DB20.DBD30 - DB20.DBD58
Instance 3 has a range of DB20.DBD60 - DB20.DBD88
Instance 4 has a range of DB20.DBD90 - DB20.DBD120

The original code writes these inputs and outputs directly to the Instance DB20 addresses in OB100/OB102 using move statements, so you never see the inputs and outputs to FB10 in FB20. When you look in FB20 it looks as though all instances of FB10 have no variables assigned to inputs or outputs.

Ken, I would love to use the last known actual values, but on warm restart (switch-off or power-down the PLC with the DB in it) OB100 will overwrite any changes that have been made to the actual values via process tuning on the HMI. The HMI is also linked directly to the same range of addresses in DB20 for display and tuning of the Instances of FB10.

Jesper, I am using a 318-2DP with MC, not MMC
 
If you did NOT write to DB20 in OB100, then the program would keep running on the actual values after a power cycle, as long as you keep the backup battery plugged in. At least thats what I am led to believe when reading Siemens documentation about warm restart.
Check that DB20 has the Non-Retain flag set to OFF !

Right, you cannot use the COPY-RAM-to-ROM function with MC cards.
I sometimes manipulate the initial values in the DBs. This I described in THIS thread.
It works with shared DBs, but I do not know if STEP7 will allow you to do it with instance DBs. Maybe it will generate one of the "timestamp conflicts".
 
I thought of not writing to the DB in OB100. But then you would have to initially set all the values manually through the HMI after any updates to the DB. Unless the Non-Retain flag allows you to update the DB without re-initializing. That would be unacceptable to the Process people.
 
It think this may be covered by Marek Tenerowicz but to put it very simply. If you make the references to FB(Y) as multiple instance calls from FB(X) and include them in FB(X) the data will be contained in DB(X) and you will not need DB's for FB(Y). This will allow a separate initial value for each call of FB(Y).

However, the initial values are only relevant when downloading the code (or copy RAM to ROM) because with the memory cards all data is retained and the last values will be saved during a power cycle.

I have used OB100 moves or HMI startup scripts in the past to put in the initial values I wanted on power cycle.
 
Marek,

I'm running out of ideas!

As the FBs are true multi-instance FBs then they will determine the 'initial' values of the DB at the point of creation i.e. when they are first declared.

Sure, then you can modify the 'actual' values at runtime with either code or input from an HMI. But you say that existing code in OB100 overwrites these 'actual' values at restart.

The trouble is I don't believe 'initial' values have any purpose other than to define the values at creation. I don't know of any command in code which will move 'intial' --> 'actual' values at runtime. The only way of doing this is in the offline copy of the project where the programmer can select 'Edit / Re-initialise values' in the DB editor (or something similar, I don't recall the exact menu instruction now). You still have to save and download the DB for this to be effective in the PLC.

Even if you were able to define different 'initial' values for each instance, surely the OB100 code would still overwrite the 'actual' values derived from these at the first re-start? And you would have the same problem every time.

I'm sorry to say it, but I think it's the OB100 code which needs to be attended to! You need to get the right values in there so that the 'actual' values are reset to the desired values at every restart. I don't think there's any alternative.

Good luck, let us know how you get on.

Regards

Ken.
 
Ken,

You stated:

"As the FBs are true multi-instance FBs then they will determine the 'initial' values of the DB at the point of creation i.e. when they are first declared.

The trouble is I don't believe 'initial' values have any purpose other than to define the values at creation. I don't know of any command in code which will move 'intial' --> 'actual' values at runtime. The only way of doing this is in the offline copy of the project where the programmer can select 'Edit / Re-initialise values' in the DB editor (or something similar, I don't recall the exact menu instruction now). You still have to save and download the DB for this to be effective in the PLC."

That's the problem! If you re-read my initial question, even offline the initial values in the instance DB are uneditable. There is no way to re-initialize the values to anything other than what they were at creation. Even when you declare a new instance you can not set the values internal to that instance.

It looks like I may have to live with it or pass values to the instances from another DB that can be initialized.
 
Marek,

I'm sorry if we seem to be going round in circles.

In STEP7 the initial values of STAT declarations are regarded as characteristics of the object (i.e. the FB), not the instance i.e. the DB.

If you need to have 4 identical level monitors with identical initial values, then these can be regarded as multiple instances of the same FB. If you need to have 4 level monitors with different values, and you're not prepared to parameterise these values, then they are not instances of each other.

I'm sorry but I don't see a way you can declare non-parameterised values and then expect to change them for every individual call of the object.

Regards

Ken.
 

Similar Topics

Hello all, Newbie in Siemens, I want to ask if there will be any issue when I download the instance datablock of a certain Function block? Also...
Replies
6
Views
4,362
Hello, Using LAD, how can I generate an array of 50 numbers and then calculate an average of them? I don't know how to define an array as a...
Replies
29
Views
11,381
What determines if a FB can be used as a multi instance? According to Berger "Prerequisite is that both the calling function block and the called...
Replies
10
Views
5,818
Hi, When opening instance DB I am receiving message: "Time stamp of the FB or SFB for symbol XXX in FB101 is more recent than the time stamp of...
Replies
6
Views
6,174
Dear sir, I am using SIMATIC 300, CPU 315-2DP , (6ES7 315-2AF03-0AB0) VIPA 603-1CC21 A1.0 RAM 32KB, Firmware=V4.0.8 The problem Im using MPI...
Replies
1
Views
63
Back
Top Bottom