Step 7 Multi Instance of SFB4 IEC Timer making FB fail?

HJTRBO

Member
Join Date
Jul 2008
Location
Melbourne
Posts
618
Hi,
I have a simple function block that does not function when I use multi instance SFB4 IEC Timer On Delay.

I could not attached a zip of the blocks. I moved them out of the main project into their own project but I still reached 900kB. I apologies for the PDF's.

FB2 doesnt work and I dont know why
FB22 does work and I dont know why I had to take the toggle bit outside of the block. It is declared in the stat area and there are no overlaps.

Basically the input to the block is treated as a toggle switch. The outputs of the block alternate with the toggle but are only on for 1 sec. There is a small bug (unrelated to my problem) which you may or may not find.:unsure:
 
Hi,
I could not attached a zip of the blocks. I moved them out of the main project into their own project but I still reached 900kB. I apologies for the PDF's.

Create a library (File>New>Library, insert S7 Program))and copy the blocks to the library - the zipped library will be small enough to attach.
 
Last edited:
You have a codng error in FC1 - you cannot use the state of an output before it is written, change it to an IN_OUT
 
You have a codng error in FC1 - you cannot use the state of an output before it is written, change it to an IN_OUT

You are the best. That fixed my problem. No to sure why that FC works everywhere else as in the example FC22 block, but alas, it is an error so sporadic operation is to be expected I suppose. For a joke I will tell you that FC1 does work in 90% of my program!

Thank you very much for your help, Nathan

N.B Attached (uncorrected) library for reference only.
 
When using the ladder editor, FC parameters are passed by pointer using the L area of the calling block.

The L area is a stack. Local data is allocated from the stack as each block is called. E.g. OB1 is at the top of the calling hierarchy, the local data used by OB1 is remembered(*) each time OB1 runs. As each block is called, a new section of the L stack is allocated.

If OB1 calls two functions (say FC1 and FC2 one after another) that both have the same Local data allocation, the two FC's are actually refering to exactly the same memory locations when referencing local data variables.

Depending on the call structure it is possible that the L area will remember the values in local data between block calls - a change to the call structure may then stop this behaviour.


(*) Beware that with indirect addressing using the V area, the local data area of a preceding block can be modifed by the block that is called. In the example above, FC1 is able to modify the local data associated with OB1
 
N.B Attached (uncorrected) library for reference only.

Looking at your code - had you considered using an FB for your toggle instead of an FC?

Using a toggle FB allows you to keep the FP store bit in the STAT section of the toggle FB without needing to "clutter" the calling FB with odd bits. You will have less parameters to pass to the FB, and you can use an output instead of an in_out as simple FB parameters are passed by value in the instance DB and are remembered between calls.

You still have to declare each instance of the toggle FB in the STAT section of the calling FB.

Reserve the use of FC's for functions that you pass input parameters and use the RET_VAL to return a value.

FC's with IN_OUT and OUT parameters have usually been based on something that is a hangover from an S5 to S7 conversion.
 
Looking at your code - had you considered using an FB for your toggle instead of an FC?

Hmmm, I probably do not follow the Step7 program flow design correctly so I try to keep the amount of DB's to a minimum. Obviously when multi instancing its not a drama. To be honest I seem to be able to code allright (including the unfortunate simple errors like you found) but it is the correct structure / program flow / design / workflow of the block principal that I seem to kinda doubt wether i'm taking a correct approach?
 

Similar Topics

When you create a Function Block in step 7 there is a ticky box for Multiple Instance Capability. I understand what it is but wondered why you...
Replies
2
Views
2,013
Hi, I'm doing some experimentation to try and expand my knowledge of Step 7 (specifically multi-instance stuff). I've created an FB with two...
Replies
2
Views
2,219
Is it possible to view online an multi-instance FB ? How do I now that I see the correct values?
Replies
9
Views
6,342
I am working on a new View ME project for a demonstration display using a PC Hosted version of ME Station. I would like to show a cylinder...
Replies
4
Views
3,157
Hi. I've got: CPU 317-2 DP / 6ES7 317-2AK14-0AB0 CP 342-5 / 6GK7 342-5DA03-0XE0 CP 343-1 / 6GK7 343-1EX30-0XE0 Basically S7 gathers a lot of...
Replies
7
Views
2,619
Back
Top Bottom