Help get this topic noticed by sharing it on Twitter, Facebook, or email.

How to make retentive timer in E+PLC?

Hi all,
I'm using E+PLC400. I've trouble with timer block. It is not retaining the values during power cycle. Is there any way to make the timer block to retain the values and continue during power cycle?

Regards,
Arv
1 person has
this question
+1
Reply
  • Stephen Daly (Software Support Engineer) August 02, 2018 08:31
    Hi Arv,

    If you open your timer FB, move the declaration of your main timing variable to a VAR RETAIN structure, e.g.:

    VAR RETAIN
    uiSeconds : UINT;
    END VAR

    This will allow the value to remain through a power cycle, but it will reset on download. If you wish it to remain through a download, look up PERSISTENT in the CODESYS help.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • Hi Stephen,

    Thanks for the quick reply. Can you upload a screenshot?

    And I can retain the input and Preset values(IN and PT pins) of the timer. I want the timer to hold the elapsed value during the power cycle and continue the timer from that point during the power cycle, as seen in the setpoint programmer.

    Regards,
    Arv
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • Hi Ar,

    I think below image help you.

    Regards
    Ramarao

  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • I need a timer which counts down to preset value. The value can be in hours or in minutes. And it is alterable in HMI. After the preset time reaches, an output is to be triggered.
    When the timer starts, the output will turn on after the preset time is reached. But during power failure, the timer resets and starts from 0ms. During such power failure, the timer has to retain the value and resume from where it left. But it is not happening. Kindly advice me in this regard.

    Arv :)
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned sad, anxious, confused, frustrated kidding, amused, unsure, silly

  • Hi ar,

    U try like in the below image. it may help u.

    Regards
    Ramarao
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • Stephen Daly (Software Support Engineer) August 06, 2018 08:56
    Arv,

    I have pulled some code together which should be close to what you need. Create a function block using Structured Text and paste the following code.

    Please note that I have not tested this code:


    FUNCTION_BLOCK RetentiveTimer
    VAR_INPUT
    xIn : BOOL;
    tTarget : TIME;
    END_VAR
    VAR_OUTPUT
    xDone : BOOL;
    tElapsed : TIME;
    END_VAR
    VAR
    _usiState : USINT; (* 0 = Initial/retentive power up, 1 = idle, 2 = running, 3 = done *)

    _fbTimer : Standard.TOF; (* Use count down timer as it's easier to start over mid-way *)
    END_VAR
    VAR RETAIN
    _tElapsed : TIME;

    _xInProgress : BOOL; (* Whether the timer is running *)
    END_VAR

    =====================================================================

    (* Initial/retentive power up *)
    IF _usiState = 0 THEN

    (* This state should be only on first execution *)
    IF NOT _xInProgress THEN
    _usiState := 1;

    (* Power interrupted, continue running *)
    ELSE

    (* Update timer with last value *)
    _fbTimer.PT := _tElapsed;

    (* Go to running *)
    _usiState := 2;
    END_IF

    (* Idle state, waiting to start *)
    ELSIF _usiState = 1 THEN

    (* User triggered the timer - go *)
    IF xIn THEN
    _fbTimer.PT := tElapsed;
    _fbTimer.IN := TRUE;
    _xInProgress := TRUE;

    _usiState := 2;
    END_IF

    (* Running state *)
    ELSIF _usiState = 2 THEN

    (* User has cancelled the timer - back to idle *)
    IF NOT xIn THEN
    _fbTimer.IN := FALSE;

    _usiState := 1;

    (* Timer has completed - go to done *)
    ELSIF _fbTimer.Q THEN
    xDone := TRUE;

    _xInProgress := FALSE;
    _usiState := 3;
    END_IF

    (* Update retentive elapsed time *)
    _tElapsed := _fbTimer.ET;

    (* Done state *)
    ELSIF _usiState = 3 THEN

    (* Reset the timer *)
    _fbTimer.IN := FALSE;

    (* User has lowered the xIn pin *)
    IF NOT xIn THEN
    xDone := FALSE;

    _usiState := 1;
    END_IF

    ELSE
    (* Shouldn't get to this state - go to idle *)
    _usiState := 1;
    END_IF

    (* Execute the timer! *)
    _fbTimer();

    (* Calculate elapsed time as using TOF *)
    tElapsed := tTarget - _fbTimer.ET;
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned sad, anxious, confused, frustrated kidding, amused, unsure, silly