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
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