LEARN · PROGRAMMING · SCL 3
SCL: TON and TOF timers
The ladder TON and TOF box, written in SCL: start with a warning, anti-wave filter, the fan that keeps running after stopping and a watchdog that detects a pump with no water. In 7 short steps, with the ladder alongside.
What is new in this lesson: time
Until now the program reacted instantly. But in a plant almost everything has times: waiting before starting, ignoring a signal that lasts very little, keeping something running a little longer. In ladder you use the TON or TOF box. In SCL it is the same box, written in two lines:
| In ladder | En SCL |
|---|---|
| TON box with its input and its time | T_ARR(IN := ..., PT := T#3s); |
| Q output of the box going to a coil | P_101 := T_ARR.Q; |
| 3-second time | T#3s |
- TON, on-delay: while
INis TRUE, it counts. On reachingPT, it turns onQ. IfINdrops before that, it goes back to zero. - TOF, off-delay:
Qturns on as soon asINbecomes TRUE. WhenINdrops,Qstays on forPT.
Just like in the previous lessons: first you read and try, then you change a time and finally you write. The ladder shows each box with its elapsed time, ET, counting live.
See a hint
- 1Write or change the code
- 2Tap ▶ Run and test it on the plant
- 3Tap ✓ Check to review it
Ctrl + Enter runs. Your code is saved in this browser.
The most common timer mistake
Calling the timer inside an IF. If the IF condition is false, the timer is not called, does not find out that its input changed and stays frozen at its last value. Always call it on every cycle, outside the IFs, and put the condition on its IN input.
Try it in exercise 4: write the wrong version, press start and then stop, and watch in the watch table how T_ARR stays with Q at TRUE.
In TIA Portal
Inside an FB, each timer is declared in the Static section as a multi-instance of type TON_TIME or TOF_TIME and is used with #, just as here:
In an OB1 you can also use a single instance, with its own instance DB: "T_ARR_DB".TON(IN := ..., PT := T#3S);.
What comes next
In lesson 4: CASE and step sequences. A reactor that fills, heats, mixes and empties on its own, step by step.
Your timings, on a 3D plant
In Procesia you program these same timers on your real PLC or in PLCSIM and watch them act on pumps, valves and instruments in 3D. Use the full version free for 7 days, no card.