How to initialise S7 IEC timer ?

JesperMP

Lifetime Supporting Member + Moderator
Join Date
Feb 2003
Location
ᚴᚬᛒᛅᚾᚼᚬᚠᚾ
Posts
16,239
Hi,

when using the IEC timers in S7, I cannot put an intial value to the .PT (preset time), when generating the DBs for the IEC timers, the initial values will allways be set to 0 because thats how it is defined in the SFB.

I have three alternatives to set the initial values to something meaningful (a preset time of 0 doesnt make much sense, does it):

1. Manually go thru all the IEC timer DBs to set the initial values. Disadvantage: It is very laborious to do.

2. Assign another DB STAT val to load the .PT, then this STAT val can get a meaningful initial value. Disadvantage: It uses more data memory for each timer.

3. Load the .PT with a constant value when an "initialisation" command is issued. Disadvantage: It uses more code memory for each timer.

Are there others out there that has given a thought to this "problem" ? Is there a more elegant way of doing it ?
 
Hi Jesper,

Couldn't you just assign a literal TIME variable at the PT formal parameter? Or do you want these timers to have variable presets once the code is executing?

If the intention is to have variable duration timers then I can't think of any way of assigning a preset that isn't either laborious, uses extra data memory or uses extra code memory.

Unfortunately, if a preset time of '0' doesn't make much sense, what time would make sense? T#1mS? T#1m? T#5d6h7m8.9s? I guess everyome will have their own ideal value for a sensible preset and nobody will agree!

Regards

Ken
 
I guess that I was unclear when I said that 0MS isnt meaningful.

The thing that nags me, is that the .PT address is allready free to change during program execution. You can have access to it anytime. So there should be no need to assign yet another address just to load .PT.
When using timers in one of my own standard blocks, I would like to assign initial values that are good default values. But IEC timers allways inherit the "0MS" from the parent SFB. If I have used 200 IEC timers, I have to manually set 200 initial values. If I have used 500 then ... you get the idea.

I think that the most obvious thing to do is to load .PT from a data address. That adress can then have a "correct" initial value.
Its just a pity because IEC timers are a bit "expensive" when it comes to data memory. With that extra initialising address, each timer will cost you 26 bytes.
 
Jesper,

Whenever I use several IEC timers, I always put them together in a single "all timers" FB. This FB contains nothing but the declarations of the SFB4s plus one call to each one with no actual parameters attached. I then call the parent FB every cycle of OB1. To control each individual timer I use access through the instance DB of the parent FB and this can be accessible anywhere in the code.

So let's say I have FB1 named "Timing" with 4 STAT variables "T01", "T02", "T03" and "T04" all of type SFB4. I call "Timing" with an instance DB1 named "Tmr". I can then use "Tmr".T01.PT or "Tmr".T02.Q anywhere in my code. This way, the data increment for each timer is only 22 bytes, not 26. Every little bit helps! 4 bytes x 500 timers = 2K = a smaller CPU sometimes!

Regards

Ken.
 
Ken,
I understand how you do.
But how do you initialise your timers ?
By writing to f.ex. "Tmr".T01.PT from another address that can get a unique initial value ? Or do you manually set initial values for each ?
Its the same "problem" as I described in my first post.

Personally I prefer to make standard FB "building blocks" and then embed the necessarry IEC timers within the same FB. In that way the data memory grows together with the code.
 
Jesper,

You're quite correct - the 'problem' of assigning an initial .PT value still exists. You just have to step through the entries in the instance DB. For this single FB approach to timers I have sometimes used a source file and then used text editing (copy-and-paste, search-and-replace) to build up many timers all with, say, T#10s presets very quickly. Maybe not 500 of them, but the principle should work just the same.

Regards,

Ken
 

Similar Topics

Hi All, I'm keep getting double quotes in between selections rather than the beginning and the end. Here's the script and please help to find...
Replies
7
Views
772
I've got an application where a robot is running 10 objects one after another past a camera so I need to buffer the result of the camera test...
Replies
20
Views
9,285
I got this error in Citect SCADA "Failed to Initialise Server Object Invalid Class String" I don't know what mistake I have made in Citect...
Replies
5
Views
6,128
Hi all, Breaking my head on this one: PLC: Siemens s7300 Programming language: STL/LAD Q: Initialise an array of 100 data words with random...
Replies
4
Views
2,177
I am trying to deal with fragmented data, and have been getting stuck. So far I am able to command the Fuchs VE Software version correctly and I...
Replies
0
Views
154
Back
Top Bottom