Hi all,
I've trouble in making timer as retentive. Without retain option, timer value resets during power cycle/failure.
I tried following methods to make a retentive timer.
1. Made the boolean input of timer as retain. Timer restarts when the PLC is power cycled.
2. Made the whole timer block as retain. Timer output turns high when the PLC is power cycled.
3. Used both boolean input as well as the timer block as retain and checked.
4. used a blink function and counter block and retained the counter value. It is not matching with real time. There is a significant delay in that timing.
All the above failed. It is a very critical process so retentive option for timer is very much needed. Kindly help me to solve this.
Thanks,
Arvind
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Have you looked at the function block RTC. You can save the date and time as a retain and when powered back on it will start counting from where it left off.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I posted a reply on your GetSatisfaction query, but I figured it may be an idea to post my solution here too.
The idea is to use a Standard.TOF, which is easier to restart part way through than a TON due to it counting down rather than up.
As mentioned in my initial reply, this code has not been tested.
FUNCTION_BLOCKRetentiveTimerVAR_INPUT
  xIn : BOOL;
  tTarget : TIME;END_VARVAR_OUTPUT
  xDone : BOOL;
  tElapsed : TIME;END_VARVAR
  _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_VARVARRETAIN
  _tElapsed : TIME;
 Â
  _xInProgress : BOOL;  (* Whether the timer is running *)END_VAR============================================================(*Initial/retentivepowerup*)IF_usiState=0THEN
 Â
  (*Thisstateshouldbeonlyonfirstexecution*)
  IFNOT_xInProgressTHEN Â
    _usiState :=1;
  (*Powerinterrupted, continuerunning*)
  ELSE
    (*Updatetimerwithlastvalue*)
    _fbTimer.PT :=_tElapsed;
   Â
    (*Gotorunning*)
    _usiState :=2;
  END_IF(*Idlestate, waitingtostart*)ELSIF_usiState=1THEN
 Â
  (*Usertriggeredthetimer-go*)
  IFxInTHEN
    _fbTimer.PT :=tElapsed;
    _fbTimer.IN :=TRUE;
    _xInProgress :=TRUE;
   Â
    _usiState :=2;
  END_IF(*Runningstate*)ELSIF_usiState=2THEN
 Â
  (*Userhascancelledthetimer-backtoidle*)
  IFNOTxInTHEN
    _fbTimer.IN :=FALSE;
   Â
    _usiState :=1;
 Â
  (*Timerhascompleted-gotodone*)
  ELSIF_fbTimer.QTHEN
    xDone :=TRUE;
   Â
    _xInProgress :=FALSE;
    _usiState :=3;
  END_IF
 Â
  (*Updateretentiveelapsedtime*)
  _tElapsed :=_fbTimer.ET;(*Donestate*)ELSIF_usiState=3THEN
 Â
  (*Resetthetimer*)
  _fbTimer.IN :=FALSE;
 Â
  (*UserhasloweredthexInpin*)
  IFNOTxInTHEN
    xDone :=FALSE;
   Â
    _usiState :=1;
  END_IF
 Â
ELSE
  (*Shouldn't get to this state - go to idle *)
  _usiState :=1;END_IF(*Executethetimer!*)_fbTimer();(*CalculateelapsedtimeasusingTOF*)tElapsed :=tTarget-_fbTimer.ET;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all,
I've trouble in making timer as retentive. Without retain option, timer value resets during power cycle/failure.
I tried following methods to make a retentive timer.
1. Made the boolean input of timer as retain. Timer restarts when the PLC is power cycled.
2. Made the whole timer block as retain. Timer output turns high when the PLC is power cycled.
3. Used both boolean input as well as the timer block as retain and checked.
4. used a blink function and counter block and retained the counter value. It is not matching with real time. There is a significant delay in that timing.
All the above failed. It is a very critical process so retentive option for timer is very much needed. Kindly help me to solve this.
Thanks,
Arvind
Have you looked at the function block RTC. You can save the date and time as a retain and when powered back on it will start counting from where it left off.
Create an lreal as retain and increase it every cycle with the task cycletime.
Sent from my Moto G (5S) Plus using Tapatalk
Hi Arvind,
I posted a reply on your GetSatisfaction query, but I figured it may be an idea to post my solution here too.
The idea is to use a Standard.TOF, which is easier to restart part way through than a TON due to it counting down rather than up.
As mentioned in my initial reply, this code has not been tested.