Timer in ST / SCL

userxyz

Member
Join Date
May 2002
Location
any
Posts
2,768
I have an input that has to be on for 1 second before something can happen.

How can I write this in SCL ?
 
This is from SCl online help (it is for a pulse timer, but you get the idea):
FUNCTION_BLOCK TIMER

VAR_INPUT
mytime : TIMER ;
END_VAR

VAR_OUTPUT
result : S5TIME ;
END_VAR

VAR
set : BOOL ;
reset : BOOL ;
bcdvalue : S5TIME ;//Time base and time remaining in BCD
binvalue : WORD ; //Time value in binary
initialvalue : S5TIME ;
END_VAR

BEGIN
Q0.0 := 1;
set := I0.0 ;
reset := I0.1;
initialvalue := T#25S ;
bcdvalue := S_PEXT (T_NO := mytime ,
S := set ,
TV := initialvalue ,
R := reset ,
BI := binvalue ,
Q := Q0.7) ;

//Further processing as output parameter
result := bcdvalue ;

//To output for display
QW4 := binvalue ;

END_FUNCTION_BLOCK

As an alternative, you should also be able to call the IEC timers TON and TOF.
 
Last edited:
It can also be written much more condensed:
DelayTimer_bcd :=S_ODT  (T_NO:= T10, S:=M3.5, TV:=T#1s, R:=FALSE, BI:=MW100,Q:=M3.6);

The above example is an ondelay timer using T10, with a fixed setpoint of 1 second, input M3.5 and output M3.6

edit: The confusing bit is that the main returned value (DelayTimer_bcd), is only used for display of the remaining time in BCD format. You dont have to use it for anything.
The output you need to use is from the Q parameter.
 
Last edited:
Jesper

Thanks again Jesper, I'm learning a lot from you,

Could I write it like this ?

VAR_INPUT
Dender: TIMER;
INPUT: BOOL;
END_VAR

VAR_OUTPUT
SEE_TIME: INT;
END_VAR

TEMP_VAR
TMP: BOOL;
END_VAR

Delay:= S_ODT (T_NO:= Dender, S:=INPUT, TV:=T#1s, Q:=TMP);

SEE_TIME:= delay // monitor time

?


JesperMP said:
It can also be written much more condensed:
DelayTimer_bcd :=S_ODT (T_NO:= T10, S:=M3.5, TV:=T#1s, R:=FALSE, BI:=MW100,Q:=M3.6);

The above example is an ondelay timer using T10, with a fixed setpoint of 1 second, input M3.5 and output M3.6

edit: The confusing bit is that the main returned value (DelayTimer_bcd), is only used for display of the remaining time in BCD format. You dont have to use it for anything.
The output you need to use is from the Q parameter.
 
I would use the BI parameter, because you then can see the time with an INT tag in stead of going via BCD.
DelayTimer_bcd :=S_ODT (T_NO:= T10, S:=M3.5, TV:=T#1s, R:=FALSE, BI:=SEE_TIME,Q:=M3.6);

edit: And you have already declared SEE_TIME as an INT, so you should use the BI output.
 
k

DelayTimer_bcd :=

but this part is not needed ?








JesperMP said:
I would use the BI parameter, because you then can see the time with an INT tag in stead of going via BCD.
DelayTimer_bcd :=S_ODT (T_NO:= T10, S:=M3.5, TV:=T#1s, R:=FALSE, BI:=SEE_TIME,Q:=M3.6);

edit: And you have already declared SEE_TIME as an INT, so you should use the BI output.
 
I am not sure. You could assign it to a temporary variable.
It looks like that the way the S5 timers are called in SCL, that there has to be a return value, and this return value is the remaining time in BCD format.

Maybe it is possible to just write
S_ODT (T_NO:= T10, S:=M3.5, TV:=T#1s, R:=FALSE, BI:=SEE_TIME,Q:=M3.6);
that is, without a return value. Same as that you dont have to use the BCD output in STL.
Try it, and tell us how it goes.
 
:confused: This has got to be a first! Jesper recommending the use of S5 timers! Mark this date, gentlemen - your grandchildren will want to know what you were doing on this day. Why not good old IEC "TON" timers? Declare the timer itself as a VAR (stat) and then call it as any other FB -
Code:
VAR
Dender: SFB4;
END_VAR;
 
VAR_TEMP
See_Time : TIME;
Start : BOOL:
Delay : BOOL;
END_VAR
 
Dender (IN := Start,
	PT := T#1s,
	Q := Delay,
	ET := See_Time);
I haven't patched in any other code indicating what you might do with Start, Delay or See_Time.

Regards

Ken
 
ok

TIJD := S_ODT (T_NO:= DEMPER, S:=INPUT, TV:=T#5s, R:=FALSE, Q:=INPUT_DELAYED);

Like this is works


S_ODT (T_NO:= DEMPER, S:=INPUT, TV:=T#5s, R:=FALSE, Q:=INPUT_DELAYED);

This doesn't work
 

Similar Topics

Hello, please, what are the steps to insert ( S_ODT ) TIMER in SCL by using ( INSERT menu )? Thanks in advance Maher
Replies
4
Views
5,242
Hi guys, Is it possible to make a function to use a timer more than ones? I'll been trying it but cannot solve it Here is my function It's a...
Replies
4
Views
8,234
Ok I just got my S7 Pro upgrade. I want to read information into an array every 10ms. I have the for loop working but I cant figure out how to add...
Replies
4
Views
5,369
I have some logic that I have written within a 5380 series controller that tracks the time an event is started, while the event is running an RTO...
Replies
2
Views
94
Hi all, I have a simple question that I have overcomplicated and gotten stuck on. I have a variable, we can call it "light" that I need to stay...
Replies
4
Views
328
Back
Top Bottom