Calling Functions in BECKHOFF

I've made a function that spurts out an adjustable bistable output, how do I call it in from another function block? I'm new to Beckhoff and ST programming, any help would be appreciated.

FUNCTION FN_PulseGen : BOOL
VAR_INPUT
SPin : INT;
END_VAR
VAR
(* Variables required to convert INT to Time *)
Val : INT;
SPVal :TIME;
(* Timer Off Variable setups *)
TON1 : TON;
TON2 : TON;
TmrOn : BOOL;
Tmr2On : BOOL;
END_VAR

SPin:= Val;
SPVal:=INT_TO_TIME(1000 * Val);

(* Set varibles up *)
(* Adjustable bistable output created by timers TON1 and TON2 *)
TON1( IN:= NOT Tmr2On, PT:= SPval, Q=>TmrOn, ET=>);

TON2( IN:= TmrOn, PT:= SPval, Q=>Tmr2On,ET=>);


I had a piece of code at the bottom to drive an output to prove it worked (which it did :) )

SPin picks up the variable setpoint. The idea that 4 instances will be using this Function, and each one has it's own setpoint defined elsewhere.. That's why I thought the use of Functions over Function Blocks...?

How do I get the timer pulse TmrOn result out of the Fn?

Kind regards,

Karl
 
a function gives a result, and you are using timers in a function, This way it wont work, However you can have a blinker easy with a standard FB.
have a look at oscat.de for a vast library with lots of functions etc.

To get a good blinker it is easier to use the time from the PLC, as with TON you will have problems when you call the program in a task.
 
What shooter say is right in that you can't use a function for that. A function has no memory. Every time you call it the variables are created and destroyed. For persistence between calls you need to use a function block. A function block will have storage allocated to it when you instantiate it. The TON is actually a FB and the timer name you create and declare are the instance storage for that timer. So you are actually calling a FB from a function and the instances of those timers are being destroyed when then function returns.

You can do strange things like pass timers or structures of timers as an In/Out parameter and keep your storage outside is you like working hard.

I seem to remember there being a standard library function(BLINK) for blinking and as mentioned before OSCAT has stuff for everything imaginable.
 
Hello!
Thanks for getting back to me guys, in the end that's how I did it (using FB's) For some reason I had in my mind that it could be done! I think I was confusing things so I went back to basics, called myself an idiot and realised where I was going wrong!

I got two timers (TON) to create the bistabe frequency, and also got it variable... If there is a better way of doing it that will be great to learn!

I'm off to have a look at OSCAT...

Thanks again,

Karl
 

Similar Topics

A pretty complex OEM program with S7-1516 PLC. Besides everything, there are two functions (FC) calling a helper Function (FB, in my case FB4) and...
16
Replies
1,211
Views
I'm new to the siemens platform and could use a little help. I have several Pop-up screens for pump controls, change of state confirmations and...
2
Replies
1,294
Views
Have anyone know how to scale this table with 0-10v output.....what is the formula to get this value? i try use this formula but its doesn't...
88
Replies
6,461
Views
Hi we imported a working function block diagram from one program into another. It verifies. However, we cannot select the function block diagram...
3
Replies
1,144
Views
Hi All, I am currently working with Mitsubishi GXworks3. I have created a function for analog output scaling with a simple formula, which I want...
4
Replies
1,167
Views
Top