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.
Made the boolean input of timer as retain. Timer restarts when the PLC is power cycled.
Made the whole timer block as retain. Timer output turns high when the PLC is power cycled.
Used both boolean input as well as the timer block as retain and checked.
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/retentive power up *)IF_usiState=0THENÂ Â Â Â (* This state should be only on first execution *)Â Â IFNOT_xInProgressTHENÂ Â Â Â Â Â _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=1THENÂ Â Â Â (* User triggered the timer - go *)Â Â IFxInTHENÂ Â Â Â _fbTimer.PT:=tElapsed;Â Â Â Â _fbTimer.IN:=TRUE;Â Â Â Â _xInProgress:=TRUE;Â Â Â Â Â Â Â Â _usiState:=2;Â Â END_IF(* Running state *)ELSIF_usiState=2THENÂ Â Â Â (* User has cancelled the timer - back to idle *)Â Â IFNOTxInTHENÂ Â Â Â _fbTimer.IN:=FALSE;Â Â Â Â Â Â Â Â _usiState:=1;Â Â Â Â (* Timer has completed - go to done *)Â Â ELSIF_fbTimer.QTHENÂ Â Â Â xDone:=TRUE;Â Â Â Â Â Â Â Â _xInProgress:=FALSE;Â Â Â Â _usiState:=3;Â Â END_IFÂ Â Â Â (* Update retentive elapsed time *)Â Â _tElapsed:=_fbTimer.ET;(* Done state *)ELSIF_usiState=3THENÂ Â Â Â (* Reset the timer *)Â Â _fbTimer.IN:=FALSE;Â Â Â Â (* User has lowered the xIn pin *)Â Â IFNOTxInTHENÂ Â Â Â 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;
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.
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.