Timer in scl

MAHER

Member
Join Date
Jul 2007
Location
CAIRO
Posts
82
Hello,

please, what are the steps to insert ( S_ODT ) TIMER in SCL by using ( INSERT menu )?


Thanks in advance

Maher
 
SCL Help says:

Timer functions are called like functions. The function identifier can therefore be used anywhere instead of an address in an expression as long as the type of the function result is compatible with the first replaced address.

The function value (return value) that is returned to the calling block is a time value of the data type S5TIME.

Absolute or Dynamic Call

In the call, you can enter an absolute value, (for example T_NO:=T10) of the TIMER data type as the number of the timer function. Such values can, however, no longer be modified during runtime.

Instead of the absolute number, you can also specify a variable or constant of the INT data type. The advantage of this method is that the call can be made dynamic by assigning the variable or constant a different number in each call.

To achieve a dynamic call, you can also specify a variable of the TIMER data type.

Examples

//Example of an absolute call:
CurrTime:=S_ODT (T_NO:=T10,
S:=TRUE,
TV:=T#1s,
R:=FALSE,
BI:=biVal,
Q:=actFlag);

//Example of a dynamic call: In each iteration of a
//FOR loop, a different timer function is called:
FUNCTION_BLOCK TIME
VAR_INPUT
MY_TIMER: ARRAY [1..4] of STRUCT
T_NO: INT;
TV : WORD;
END_STRUCT;
.
.
END_VAR
.
.
FOR I:= 1 TO 4 DO
CurrTime:= S_ODT(T_NO:=MY_TIMER.T_NO, S:=true, TV:= MY_TIMER.TV);
END_FOR;

//Example of a dynamic call using a variable of the
//TIMER data type:
FUNCTION_BLOCK TIMER
VAR_INPUT
mytimer:TIMER;
END_VAR
.
.
CurrTime:=S_ODT (T_NO:=mytimer,.....);
 
They also give an example of timer functions:

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
 
This is my working code with example of timer instruction use.
May be it helps.
===========================
FUNCTION FC505 : VOID

VAR_INPUT
T_N : TIMER; //timer number
T_time:S5TIME; //time of timer
Differ:REAL; //difference
V_in: REAL; //input
END_VAR

VAR_IN_OUT
V_old:REAL; //old value
END_VAR

VAR_OUTPUT
V_out:REAL; //output
END_VAR

VAR_TEMP
Diff:REAL;
bcdvalue :S5TIME; //Time base and time remaining in BCD
set: BOOL;
TIMER_Q: BOOL;
END_VAR

// Statement Section
Diff:=ABS(V_in-V_old);
IF Diff>Differ THEN set:=1; ELSE set:=0; END_IF;

bcdvalue:= S_PULSE (T_NO := T_N ,
S := set ,
TV := T_time ,
Q := TIMER_Q) ;
IF Diff<=Differ THEN
V_out:=V_in; V_old:=V_in;
ELSIF TIMER_Q=true THEN
V_out:=V_old;
ELSE
V_out:=V_in; V_old:=V_in;
END_IF;
END_FUNCTION
================================
 
thank you very much ,Oleksandr_Husyev

it is a great effort which you did and very useful.

Thanks a lot
Maher
 

Similar Topics

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,219
I have an input that has to be on for 1 second before something can happen. How can I write this in SCL ?
Replies
9
Views
3,614
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,353
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
288
Question to anyone with ideas about my thoughts on upgrading a very vintage timer, which is being used to switch between 2 5hp domestic water...
Replies
14
Views
426
Back
Top Bottom