S7 - Multiple FC calls in a loop

RMA

Member
Join Date
Sep 2004
Location
North of Hamburg, Germany
Posts
2,052
On restart of the PLC, I want to go through all the modules in the system and open all the motor driven switches. I've already got the FC to do this for one module which I use for the case when a module comes back on-line after having been powered down or had a DP fault. The number of the module concerned is passed to the FC as a parameter.

The simplest way to handle this seems to be to write another FC which initialises the Module Number with 21 (the highest module number) and then calls the existing FC to do the actual switching before LOOP-ing back to the start and repeating the process with the next lower Module number.

The problem is that the actual switching FC has a 1 sec Timer to create the Pulse which starts the motor in the switch. What happens if the FC is called again while this timer is running. Does S7 automatically create another instance of the FC, or do I have to wait until the timer has finished before calling the FC again?
 
Last edited:
Roy

Have you hard-coded the timer in the called FC? If so, and you then attempt to call the FC a second time while the timer is already running, you can certainly screw up the measurement of time.

I assume the calling FC and the called FC are both in the same S7 priority class (i.e. you're not using an interrupt or similar)? So, when you call the FC the first time, it executes to completion before passing control back to the calling FC. You then call it a second time, with a different set of parameters, and it too executes to completion. If a hard-coded timer is started within the first call, then control of this timer will be over-written by the logic conditions of the second call. Which in turn will be overwritten by the third call etc etc. I would guess your loop execution will take very much less than a second. If the timer is necessary for scheduling purposes, or to delay while waiting for feedback, then you need to maintain the execution of each call of the FC until you're sure the timer has expired. Could you build the timer in to the looping control, so that the loop only increments once each second, rather than embed it in the switching control? The alternatives would seem to be that, or passing the timer as another parameter to be altered on each loop.

The more I've read my answer, the less I'm sure I understood your question! I'm sure you'll let me know if my suggestions are gibberish.

Regards

Ken.
 
Why am I not surprised! If it looks too good to be true, it probably is!

I hadn't really looked at the timer situation in the called FC, I wrote it quite a while ago and had forgotten the details. Having looked, I see I am using hard-coded timers, so that's the end of that idea!

It's not really that much of a problem, I'll just have to set a busy flag in the called FC while it's running and check it in the calling FC before proceding. The calling FC will be a bit longer than its current 8 lines of code though! :(
 
If the called subroutine is a FB instead of FC you can use a TON timer that uses instance datablock memory instead of a system timer. If the calling subroutine is also a FB you can use it's datablock to keep the data for all the timers (If you need to know how to put the called data in the calling datablock I can elaborate)
 
Thanks DesertDog,

I solved the problem by setting a BUSY flag Merker on entering the called FC (clearing it when the Timers timed out) and changed the calling block to an FB where I keep the current Module number in a Stat. Then on entering the FB I just need to check if the BUSY Flag is set, if so I exit immediately, otherwise I decrement the Module number and call the FC again.

When I get done with Module number 1, I set a flag to say the whole business is finished and skip the FB in OB1.

This is only done once each day at switch on, under normal circumstances, so the 20-odd seconds it takes is no big deal - the HMI PC won't even have got to the operator log-in in that time.

It's working fine now. Wish some of my other problems were as easy!
 

Similar Topics

I have a practice program I'm writing. In it I have a error recovery subroutine. This subroutine is called from four different lines of code. Each...
Replies
6
Views
8,617
This is the first time I am working with Simatic Manager Step7 as I started my siemens journey with TIA which is pretty easy and do a lot of stuff...
Replies
3
Views
142
Compactlogix controller, program has 28 conveyors that use TON's to start the conveyors. The TT sounds a warning horn during start and the DN...
Replies
10
Views
485
I have 9 field devices, three METSEPM5110 power meters and six ACE949-2 rs285 interface modules. I want to read this Modbus rtu data through rs485...
Replies
8
Views
315
I'm trying to use DTM browser to make make modbus poll from RTAC. I'm able to get the points in first poll object. But not able to get anything in...
Replies
1
Views
123
Back
Top Bottom