Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pausing Timers In Structured Text

I need to be able to pause a timer and retain it's ET value when the timer is no longer being asked to run. The timer times when the input from a proximity switch is not present, but I only want it to time when the pump that forwards on the material is running. The pump may only run for 30 seconds, but the prox switch may be 120 seconds worth of pumping away, so it would take 4 runs of the pump before any material would be detected.

I'm using Codesys v2.3 if that helps

So far I have:

IF Motor AND NOT Proxy.P1 THEN (*If the motor is running and the proxy doesn't energise, then start that proxy's timer*)
    Proxy.P1_Timer.IN:= TRUE;
ELSE
    Proxy.P1_Timer.IN:=FALSE;
END_IF

But the above scenario will cause the ET value to reset when Motor goes off also, not only when Proxy.P1 becomes TRUE. The ET should only reset when Proxy.P1 is set to TRUE

Any advice on this? I'm surprised that there isn't just a retain option on the FB.

like image 814
LBPLC Avatar asked Nov 22 '25 06:11

LBPLC


1 Answers

Here is a TON_Pausable.

TON_Pausable behaves just like a normal TON. Additionally TON_Pausable is paused via the PAUSE Input, IN has to remain true while pausing.

FUNCTION_BLOCK TON_Pausable
VAR_INPUT
    IN : BOOL;
    PT : TIME;
    PAUSE : BOOL;
END_VAR
VAR_OUTPUT
    Q : BOOL;
    ET : TIME;
END_VAR
VAR
    rtPause : R_TRIG;
    tTimePaused : TIME;
    ton : TON;
END_VAR

IF NOT IN THEN
    tTimePaused := T#0s;
END_IF

rtPause(CLK := PAUSE);

IF rtPause.Q THEN
    tTimePaused := tTimePaused + ton.ET;
END_IF

ton(IN := IN AND NOT PAUSE, PT := PT - tTimePaused);

Q := ton.Q;
ET := tTimePaused + ton.ET;

This way the logic is encapsulated and reusable.

like image 114
Felix Keil Avatar answered Nov 23 '25 20:11

Felix Keil