How to create a Retentive/Accumulative Timer from On-Delay/Off-Delay Timers
A retentive timer can be built with an On Timer and supporting logic.
A typical TON implementation automatically clears the accumulating value when its input goes false. A retentive timer saves the value instead, so we'll need a way to capture the elapsed time outside the TON.
Create a variable to act as memory for the TON. When the timer needs to start, copy the memory into the Accumulator. Copy the Accumulator back to memory when the timer should pause. That just leaves resetting, which can be accomplished by clearing the memory or moving zero into the memory variable.
This example is for an Allen Bradley PLC, but the concept should work anywhere.
One thing to note: the rungs with MOV commands are placed before the TON to ensure that the .ACC value is saved or updated before the TON starts changing it.