Timers are used in order to introduce delays in your code. Delays are just time intervals between two events. However in this case we refer to virtual (simulation) time and not real-time.
SCL timers are activated by a Boolean trigger. The trigger is provided on input. The time interval is also provided. The time interval is usually specified by a means of a time literal or a variable of a type TIME. The timer outputs the elapsed time and a Boolean flag indicating that the timer has elapsed.
Let's discuss time literals first. You can think of them like constants expressing time intervals in milliseconds. The time literals obey to a specific syntax of course. Here are a few examples:
You can already see that time literals can express time intervals ranging from milliseconds to days. You can use time units in any combination. The syntax is intuitive enough so I will stop here :)
Time literals are treated like values of type TIME.
Now let's jump to the timers. We have three basic FBs:
Timer On Delay (TON_TIME) - activated on rising edge of the trigger input. reset when the input is lowered. output is raised when the time elapses.
Timer Off Delay (TOF_TIME) - activated on falling edge of the trigger input. reset when the input is raised. output is raised until the time elapses.
Pulse Timer (TP_TIME) - activated on rising edge of the trigger input. reset then the timer elapses. output is raised until the time elapses.
All three function blocks have different behavior. Let's see how to use them in general:
You start by declaring a static variable choosing the proper timer type for your use case. This is to preserve the timer state between script executions. Then you should call the timer on every execution of the script passing the value of the trigger (IN) and the provisioned time (PT) like this:
On output the timer provides the elapsed flag (Q) and the elapsed time (ET).
Depending on your logic the trigger could come from anywhere. It could be a variable connected to a signal (like in this case) but it could also be the result of a function call or the output of another timer. Any Boolean expression will do the job.
It is up to you to decide.
Example: Imagine a situation where a timer is started when the resource is selected by the user. In this case you simply do this: #timer(IN:=IS_SELECTED(), PT:=T#5s);
Comments