Technical Forum

STEP 7 (TIA Portal)

Calling a FC or FB with timers inside multiple times

Thread Starter: PaulieTheKid   Started: 5/23/2012 10:44 PM   Replies: 16

« Previous thread Next thread »
12» Page 1 of 2 (17 items)
  5/23/2012, 10:44 PM
Joined 5/23/2012
Last visit: 7/5/2012
Posts: 12
Rating:
Rated: Very Good [1.5 out of 5 / rated 2 time(s)]. (2) 
Rated: Very Good [1.5 out of 5 / rated 2 time(s)]. (2) 
Hi I'm new here,

First of all, is there a search function for this forum? I couldn't find it.

Although I programmed a couple machines with a S7-1200 CPU (TIA Portal V11 basic), I'm kind of new to Functions (FC) and Function Blocks (FB).

I'd like to make a couple FC's or FB's for simple tasks like a blink light and other stuff.

I just made some LAD code for the blinking light that contains 2 TP timers for on and off time.
I tested it inside a FC and later on also inside a FB.
It worked fine when I had main only calling it once. (Q1 starts blinking when I1 is high) .But I have trouble when I use it 2 or more times in the main program. Both outputs Q1 and Q2 start blinking when either input I1 or I2 goes high.

I think it has something to do with the timers inside the FC or FB. There name and address remain the same troughout the multiple FC's or FB's.

Does somebody know how to deal with this? It would really help me out, because I'm stuck at the moment...
Thanks , Paul



=== Edited by PaulieTheKid @ 5/23/2012 11:22 PM [GMT ] ===


Top
Thank you for this post from:
  5/24/2012, 1:02 AM
Joined 9/8/2009
Last visit: 5/22/2013
Posts: 511
Rating:
Rated: Outstanding [3.88 out of 5 / rated 32 time(s)]. (32) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
I think I understood your problem. You want to call FBs or FCs with dedicated inputs/outputs and you made a code that uses timers.

Obviously you can't use the same timer in every FC or FB call.

There are various possibilites. You can call SFB4 (TON) and SFB5 (TOF) in a FB. It will create a instance data for timer in a function block, however you can't use this in a FC because it doesent have a static memory.

The other way is to set a timer as a input parameter of a FC or FB and assign to every call a different one.

I do use SFB4 and SFB5 timers called in FBs for this task.
Top
Thank you for this post from:
  5/27/2012, 8:02 PM
Joined 5/23/2012
Last visit: 7/5/2012
Posts: 12
Rating:
Rated: Very Good [1.5 out of 5 / rated 2 time(s)]. (2) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
I tried it a couple of different ways with a FB, but I just dont get it to work.
It works fine when I only call it once in an OB, but when I call the same FB a couple of times for different outputs, it wont work.

I guess it is because of the timers inside the FB. Should I select single instance or multiple instance as a call type?

I attached the code inside the FB. Is there maybe an example file available somewhere?

Attachment: code.jpg  (192 Downloads)

Top
  5/27/2012, 8:02 PM
Joined 5/23/2012
Last visit: 7/5/2012
Posts: 12
Rating:
Rated: Very Good [1.5 out of 5 / rated 2 time(s)]. (2) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 

Ans here is the interface

Top
  5/27/2012, 8:02 PM
Joined 5/23/2012
Last visit: 7/5/2012
Posts: 12
Rating:
Rated: Very Good [1.5 out of 5 / rated 2 time(s)]. (2) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 

And here is the interface


Attachment: Interface.jpg  (185 Downloads)

Top
  5/28/2012, 9:32 AM
Joined 9/8/2009
Last visit: 5/22/2013
Posts: 511
Rating:
Rated: Outstanding [3.88 out of 5 / rated 32 time(s)]. (32) 
Rated: Good [1 out of 5 / rated 1 time(s)]. (1) 
Use multi-instance as you did.

You did eveverything ok.

Now, it can't be seen how you call this FB under OB, have you assigned for each FB its own DB, or you can call in new FB this FB multiply as multinstance, same way as you did for the timers.


You can still improve your code and make it more reliable. Instead using pulse timers use on-delay timers:
-delete M1
-delete M2
-delete N1
Replace pulse timers with on-delay timers.
Replace /M2 with /IEC_Timer_0_Instance_1.Q
Replace N with IEC_Timer_0_Instance.Q
Add new network, I will write a pseudo code of it : Q:= Enable AND /IEC_Timer_0_Instance.Q



=== Edited by Marko Bursic @ 5/28/2012 10:04 AM [GMT ] ===


=== Edited by Marko Bursic @ 5/28/2012 9:40 AM [GMT ] ===


=== Edited by Marko Bursic @ 5/28/2012 9:36 AM [GMT ] ===


Top
  5/28/2012, 5:43 PM
Joined 5/23/2012
Last visit: 7/5/2012
Posts: 12
Rating:
Rated: Very Good [1.5 out of 5 / rated 2 time(s)]. (2) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Thanks for helping me out. I knew the code could be optimized, but that doesn't really bother me at the moment. Although your suggestions sure are helpfull.
I attached the program, so you can see what I've done an how things are called in the OB "main". I'm only using 1 OB.

After downloading, rename the file to Test10.rar . It exeeds 3Mb as a zip file, so I made a rar file of it, but had to change the name to .zip to upload it here.

If problems occur, please pm me you mail address, so I can send you the file directly.

Thanks, Paul

Attachment: Test10.zip  (70 Downloads)



=== Edited by PaulieTheKid @ 5/28/2012 6:30 PM [GMT ] ===



Top
  5/28/2012, 6:25 PM
Joined 9/8/2009
Last visit: 5/22/2013
Posts: 511
Rating:
Rated: Outstanding [3.88 out of 5 / rated 32 time(s)]. (32) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
you forgot to attach, but I won't open a zip file, rather upload a snapshot like you did before.
Top
  5/28/2012, 6:40 PM
Joined 5/23/2012
Last visit: 7/5/2012
Posts: 12
Rating:
Rated: Very Good [1.5 out of 5 / rated 2 time(s)]. (2) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
I was editing the attachment, now it is ok.

Here is the screenshot reffering to the FB "A1" . Both the timers are configured as multiple instance DB's

Attachment: FB A1.jpg  (199 Downloads)

Top
  5/28/2012, 6:42 PM
Joined 5/23/2012
Last visit: 7/5/2012
Posts: 12
Rating:
Rated: Very Good [1.5 out of 5 / rated 2 time(s)]. (2) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
This is OB "Main"

Attachment: OB main.jpg  (162 Downloads)

Top
12» Page 1 of 2 (17 items)
Actions