ST program calling FB with a TON inside it - TON not working help pls

matt_sd

Member
Join Date
Jan 2007
Location
Australia
Posts
96
This is a strange one, I have a simple alarm filter function block done in Structured Text (ST). I am calling it from a program. When this program is in Ladder it works OK but when the calling program is in Structured Text (ST), the TON timer inside the FB it calls doesn't time. Very strange. My code must have a bug in it but I have use FB calls like this elsewhere and worked ok.
This is programmed with Beckhoff Twincat but any IEC1131 should be the same.


This is alarm filter Function Block:-


FUNCTION_BLOCK alarm_filter_FB
VAR_INPUT
enable:BOOL; (*Enable this FB *)
Inhibit:BOOL; (*This is the inhibit input 1 = Inhibit Alarm*)
alm_in:BOOL; (*This is the Alarm in 1 = Alarm State*)
delay:TIME:=t#5s; (*This is the Delay in seconds (5 seconds is default)*)
END_VAR

VAR_OUTPUT
Alm_out:BOOL; (*This is the alarm output*)
END_VAR

VAR
TON: TON; (* Call TON standard block *)
END_VAR


(* If the inhibit is not set, when the alam input is set, after x time the alarm is generated *)
ton.PT:=delay;
IF NOT Inhibit AND alm_in AND enable THEN
ton.IN:=1;
ELSE
ton.IN:=0;
END_IF
Alm_out:=ton.Q;





THIS IS THE PROGRAM IN ST THAT CALLS THE FB:-



PROGRAM alarm_filter_instance
VAR
input: BOOL;
instance1: alarm_filter_FB;
output: BOOL;
END_VAR

(* Tank Level Low *)
instance1.Delay:=t#10s;
instance1.enable:=1;
instance1.Inhibit:=0;
instance1.Alm_in:= input;

output:=instance1.Alm_out;


If you look at the attached, this is the instance open, the timer is not timing and neither is the delay of 10s been moved into the PT?
Any help appreciated

Matt
 
I haven't done any Beckhoff programming for some time, but I can't see a call to the function block - your code just writes the input parameters and reads the output parameters.
 
You didn't call SFB TON, it should be called cyclically from your code for example:
ton(IN:= alm_in AND enable AND NOT inhibit,
PT:= delay);
Alm_out:= ton.Q;
 
Thank gregoryg & L D[AR2,P#0.0].

That seems like the problem. I have programmed ladder for 15 years but only programmed in ST in the last 6 months.

I thought that as TON was declared, it would be called (just like ladder)

ST is good in Beckhoff as there are not the modules created in ladder (unlike Control logix where all the modules exist in ladder)

Thanks again, you have saved me time :)

Regards

Matt
member.php?u=21496
 

Similar Topics

I have mapped data tags Vlt_1 and Amp_1 from a device_1 (with ip address) to a red lion programmable controller which is connected to it over...
Replies
1
Views
1,403
Does anyone have RSLogix 5000 ladder diagram program of tank leveling (factory IO). Fill valve, discharge valve, set point, level, etc? I looked...
Replies
2
Views
137
I am completely stuck on building a ladder program that requires a start button to be pressed 3 times to turn on motor 1. Then motor 2 starts...
Replies
20
Views
498
I'm a beginner in the automation field and I've set up an automation system connecting several devices (datalogger, radio, etc.) via Modbus RS485...
Replies
5
Views
181
Back
Top Bottom