On-Delay Timer

So, I want to duplicate the on-delay timers you see in ladder logic. I’ve figured out a way to do that with an up timer but I wanted to see if anybody had a better solution. Sorry if this was repeated elsewhere. I tried searching but came up empty.

This is what it looks like in ladder. If the condition is true, the timer times up until the preset is reached. Then the timer stops and the Done bit is set. If the condition is false, the timer resets and starts over when the condition becomes true again.

Condition
—||------------| T1 |

T1
—||-------------(Output)
DN

This is what I’ve done in OptoScript.

if (not Condition) then
// Stop the timer if the condition is not active
StopTimer(T1);
elseif (T1 == 0) then
// Start the timer if the condition is active and it isn’t already running (non-zero value)
T1 = Preset
elseif (HasTimerExpired(T1)) then
// Pause the timer if it’s expired
PauseTimer(T1);
endif
Output = HasTimerExpired(T1);

I use a single If-Elseif-Endif structure to start/stop the timer. If the condition is not active, the timer is stopped. If the timer is active and it’s value is 0, it’s started by assigning it the preset value. If the timer has expired, I pause the timer. I do that because I’m not sure if it will just keep timing up indefinitely.

This seems pretty verbose to me and I was hoping someone had a more elegant solution.

Thanks.

I suspect what you seek is the “Start Off-Pulse” command, described in the manual: “To turn off a digital output for a specified time, or to delay turning it on.”

This command leverages the built-in intelligence of our brains. Since it happens at the brain level, you can send this command from a controller then move along in your logic, not having to worry if communication is lost, say, between the controller and the brain in between the time you issue this command (start timing) and when the output goes on. This could be especially important if, say, that output is connected to the shutoff on the pool-filling valve at your boss’s house, for example.

Also see [U][B]this related post[/B][/U].

Would that work for you? If not, could you tell us a little more about the big picture?

-Optomary

Thanks for the reply. Not quite what I’m looking for though.

Let’s say I want to run a feed conveyor but only if a downstream device is already running and has accelerated up to speed. So, I would turn on the downstream device and use it’s “running” input as the condition for my timer (call it an acceleration timer). When the timer expires, I know the device is ready and I can turn on my feed conveyor to deliver material to it.

Now, let’s say the downstream device has a problem. Maybe it faulted or a user turned it off manually. So, my “running” input goes low which causes the timer to not be done. The feed conveyor stops because the timer is no longer expired. When the device starts up again, the timer restarts and the conveyor starts when it expires again.

Does that make sense? Could I put the timer code in subroutine? I could then pass it the condition, preset, and timer. Then I would need just one line of code. For example, UpdateTimer(Condition, Preset, UpTimerVariable).

Thanks.

I’m still not convinced one of the pulse commands isn’t your best bet (also see [U][B]this post[/B][/U] which sounds similar).

If you’re set on using a strategy timer (rather than letting the brain do the timing w/a pulse) an UpTimer would be more intuitive to me (using the HasUpTimerReachedTargetTime condition). However, I don’t think the code for that would be much more concise or elegant than what you showed using a down timer.

As far as using a subroutine: unless you’re going to be using this logic in more than one place, I don’t think a sub would simplify much.

Besides making your system as robust as possible (and work how it’s supposed to), I’d say the main thing here is that your logic makes sense to you – and will still make sense 2 months from now. Glad to see you’re including comments, that’s always a good idae!!

I can’t read ladder logic.

Ok, now that is out of the way…

What is the timer for?
I’m not clear on why there is even a timer in the mix.
Sounds like its just used to link the downstream conveyor with the upstream one?