Calling Functions in BECKHOFF

Karl_Tanner

Member
Join Date
Jun 2016
Location
Bristol
Posts
7
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

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
146
I am looking to get an AB series 1774 (PLC1) from the 1970's up and running. I have all the parts, and it powers up just fine without errors if I...
Replies
12
Views
2,323
Hello all, I’ve recently begun using Automation Studio on my own time to boost my knowledge of controllers beyond AB/Siemens. To ease myself into...
Replies
0
Views
899
Hello I'm new to PLC programming and I'm programing in ST. Programming envirement is GX works 3. I can't figure out how to jump to subprogram or...
Replies
1
Views
1,462
I have some code i need to block until a super genie for data entry has completed (by operator input)as per below. FUNCTION New_Setpoint()...
Replies
5
Views
2,275
Back
Top Bottom