Memory efficient use of timers in S7 PLC

Join Date
Jul 2007
Location
Kiruna
Posts
600
Hi all,

Can someone please advise me on this.

I have an application which is quite small in programming terms but requires a lot of monitoring of switches.

I'm hoping a smaller S7 will do the trick 312 or 313. I was going to use an FB as a standard block for switch handling and then another FB for multi instance so I would have all instances in a single DB.

I require some delay/debounce timers for each switch. Usually I use a one second pulse to increment a integer for my timers but seen a post here on the use of IEC timers SFB 4 & 5 within the FB. I've added these but notice they are 28 Bytes in size!

Surely these are not the most memory efficient way of approaching this or am I missing something?
 
Forget these arcaic S7-300 CPUs.
Use an IM151-8. It has 192kB of memory, ethernet etc.

How many timers does it add up to ?
If you have many thousands of timers, then maybe it could be worth considering alternatives to SFB4 and SFB5, otherwise not.
 
Hi Jesper,

Looking back at my question its not very clear of what I was asking but I'm glad you understand it.

Using my old method I had a UDT of 20 bytes for each Digital switch. I have a shared DB containing all instances of UDT. In an FC using indirect addressing I write the DB into FC local stack, process it and write it back out to DB and loop through until I reach end of db.

Each Digital Switch type is only 20 bytes. With the use of 3 IEC timers declared as STATs in my FB plus 3 variables of type TIMER (which I need to map my delay setpoints from INTs to for On Delay Presets) each instance now is 96 Bytes.

Wow!. This is not the way to do it.

How does everyone else requiring maybe 1000 timers do it in an S7.
 
Using instance DBs with embedded timers is an efficient way, because you only set aside the memory you actually use.
1000 timers x 28 bytes = 28kB. Not very much for a CPU with for example 256kB (315-2PN/DP).
I have a medium sized plant with approx 200 "objects", each with approx 5-7 timers and an IDB of approx 300 bytes = 60kB. Trivial for the 317-2PN/DP CPU that we use.
 
Hi Jesper,

Looking back at my question its not very clear of what I was asking but I'm glad you understand it.

Using my old method I had a UDT of 20 bytes for each Digital switch. I have a shared DB containing all instances of UDT. In an FC using indirect addressing I write the DB into FC local stack, process it and write it back out to DB and loop through until I reach end of db.

Each Digital Switch type is only 20 bytes. With the use of 3 IEC timers declared as STATs in my FB plus 3 variables of type TIMER (which I need to map my delay setpoints from INTs to for On Delay Presets) each instance now is 96 Bytes.

Wow!. This is not the way to do it.

How does everyone else requiring maybe 1000 timers do it in an S7.

You could make your own multi - TONOFF using 3 INT + 2 bits for each timer.

To give you an idea; here is an example for one such timer - you'll have to put it in a loop. Time resolution = the scan frequency. Remember to initiate by CPU start.

A IN // Input to the timer function
AN OUT // Output from the timer function
JCN M001
// Delayed ON
L iONDLY // Integer with on-delay setpoint
L iELAPSED // Elapsed time
<=I
S OUT // Time elapsed, set output
JC M008
+ 1
T iELAPSED
JU M009

M001: CLR
AN IN
A ON
JCN M008
// Off delay
L iOFFDLY // Integer with Off dely setpoint
L iELAPSED
<=I
R OUT // Time elapsed, reset output
+ 1
T iELAPSED
JU M009
M008: NOP 0 // Reset timer value
L 0
T iELAPSED
M009: SET
SAVE

The code is an extract from an FB, I hope there are no milspelsings.

Kalle
 

Similar Topics

Hey all, I'm doing a more standardize version of one of my programs and organizing things into UDTs and whatever else I can do to shrink the...
Replies
0
Views
419
Hello, I would like to see if anyone can give me some pointers on how to optimize this function block that I have written for a Omron CJ2M. It is...
Replies
17
Views
6,202
Hi folks, I'm not as accustom with Siemens & WinCC, however I've been asked to increase the amount of data an existing application is logging...
Replies
2
Views
65
Hi, Yesterday, I was at a customer site. I made one little change. Changed a dummy bool output to an actual output. I didn't add any tags, or...
Replies
15
Views
328
I have a c-more micro with a three digit input box on one of the screens. This is being written to a memory location in a DL05. I don't have the...
Replies
3
Views
109
Back
Top Bottom