Re-use timer S7 SCL?

Join Date
Sep 2005
Location
Niel (Antwerpen)
Posts
32
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 timer that runs when the INPUT RUN high is.
For so long INPUT PULS not get high the timer keeps running.
If the time is passed the OUTPUT STAT will be high ,otherwiss
the timer will be resetted.
It's a routine to check a moving elevator belt.
I'll have to check about 20 elevators and want to use 1 timer.

Thanks for all the help that you can give me (y)

FUNCTION_BLOCK FB_CHECKTURN_ELEVATOR
(*###############################################################################*)
(* // CHECK STATUS TOERENWACHTER ELEVATOR
FB_CHECKTURN_ELEVATOR.DB_CHECKTURN_ELEVATOR(TI := timer,
PV := preset value,
PVOLD_I := oude waarde timer(in),
PULS := puls cycle_motor,
RUN := run motor,
STAT := alarm status,
PVOLD_O := oude waarde timer(uit));
*)
(*###############################################################################*)
VAR_INPUT
TI : TIMER;
PV : WORD;
PVOLD_I : WORD;
PULS : BOOL;
RUN : BOOL;
END_VAR
VAR_OUTPUT
STAT : BOOL;
PVOLD_O : WORD;
END_VAR
VAR
TTIME : INT;
TTIME2 : S5TIME;
CVOUT : S5TIME;
END_VAR
BEGIN

IF (RUN = FALSE OR PULS = TRUE) THEN
//TTIME := WORD_TO_INT(PV);
//PVOLD_O := PV;
;
ELSE
TTIME := WORD_TO_INT(PVOLD_I);
END_IF;
TTIME2:=TIM_S5TI(IN:=DINT_TO_TIME(INT_TO_DINT(TTIME)));

// motor run delay
CVOUT := S_ODT (T_NO:= TI,S:= RUN,TV:= TTIME2,R:= PULS OR NOT RUN,BI:= PVOLD_O,Q:= STAT);

IF PULS = TRUE OR RUN = FALSE THEN TTIME := WORD_TO_INT(PV); PVOLD_O := PV; END_IF;

END_FUNCTION_BLOCK
(*###############################################################################*)
DATA_BLOCK DB_CHECKTURN_ELEVATOR FB_CHECKTURN_ELEVATOR
(*###############################################################################*)

BEGIN

END_DATA_BLOCK
(*###############################################################################*)
 
No, you cannot use a single timer multiple times. Like any other variable, it can have only one state at any given time. Timers are even more problematic, since they run asychonous to the process.

You have a few options: You could pass the timer instance into your function, you could use indirect addressing to reference a timer based on a varible you increment for every scan, or you could use a Siemens canned function (TON maybe?).
 
Use SFB4 as a multiple instance in your FB and create 20 instances of the FB and call the relevant instance FB for each of the 20 elevators. (Remove the timer number from the interface of course)
 
Thanks for all the replies!

I have solved it by using ob35 to generate 100ms pulses, then make into the fb a counter and keep the old values stored in merker memory. It works! I give you the example, please react if you think this is not the best way ;)

FUNCTION_BLOCK FB_CHECKTURN_ELEVATOR
(*###############################################################################*)
(* // CHECK STATUS TOERENWACHTER ELEVATOR
FB_CHECKTURN_ELEVATOR.DB_CHECKTURN_ELEVATOR(PV := preset value,
CV_I := oude waarde counter(in),
PULS := puls cycle_motor,
RUN := run motor,
BITM_I := hulpgeheugen,
STAT := alarm status,
CV_O := oude waarde counter(uit),
BITM_O := hulpgeheugen;
*)
(*###############################################################################*)
VAR_INPUT
PV : WORD;
CV_I : WORD;
PULS : BOOL;
RUN : BOOL;
BITM_I : BOOL;
END_VAR
VAR_OUTPUT
STAT : BOOL;
CV_O : WORD;
BITM_O : BOOL;
END_VAR
VAR
CV : INT;
xEdge : BOOL;
END_VAR
BEGIN

// GET MEMORIZED COUNTER OR RESET COUNTER
IF NOT RUN OR PULS THEN
CV := WORD_TO_INT(PV);
ELSE
CV := WORD_TO_INT(CV_I);
END_IF;

// FLANK EVERY 100MS (FROM OB35)
xEdge := Puls100mS AND NOT BITM_I;
BITM_I := Puls100mS;
BITM_O := BITM_I;

// COUNT
IF xEdge THEN
// Code
IF RUN THEN CV := CV-1; END_IF;
IF CV < 0 THEN CV := 0; END_IF;
END_IF;
// SET OUTPUT
IF CV = 0 THEN
STAT := TRUE;
ELSE
STAT := FALSE;
END_IF;

// MEMORIZE COUNTER
CV_O := INT_TO_WORD(CV);

END_FUNCTION_BLOCK
(*###############################################################################*)
DATA_BLOCK DB_CHECKTURN_ELEVATOR FB_CHECKTURN_ELEVATOR
(*###############################################################################*)

BEGIN

END_DATA_BLOCK
(*###############################################################################*)
 

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,235
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,644
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,364
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
91
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
310
Back
Top Bottom