Skip to content
PROCESIAby Aterra Ingeniería

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 ladderEn SCL
TON box with its input and its timeT_ARR(IN := ..., PT := T#3s);
Q output of the box going to a coilP_101 := T_ARR.Q;
3-second timeT#3s
  • TON, on-delay: while IN is TRUE, it counts. On reaching PT, it turns on Q. If IN drops before that, it goes back to zero.
  • TOF, off-delay: Q turns on as soon as IN becomes TRUE. When IN drops, Q stays on for PT.
INTON.QTOF.Qtime → PT PT

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

  1. 1Write or change the code
  2. 2Tap ▶ Run and test it on the plant
  3. 3Tap ✓ Check to review it
Program · OB1 (SCL)

Ctrl + Enter runs. Your code is saved in this browser.

TK-101 tank
FCV-102 45 % TK-101 LSH-101 LSL-101 P-101 EF-101 XL-101 XF-101
Level45 %
Watch table

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.

// Wrong: if O_101 is FALSE, T_ARR is never reset IF O_101 THEN T_ARR(IN := TRUE, PT := T#3s); END_IF; // Right T_ARR(IN := O_101, PT := T#3s);

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:

#T_ARR(IN := #O_101, PT := T#3S); "P_101" := #T_ARR.Q;

In an OB1 you can also use a single instance, with its own instance DB: "T_ARR_DB".TON(IN := ..., PT := T#3S);.

A challenge: in exercise 7, the watchdog only looks at LSL_101. What happens if the level starts at 50 % and the pump loses suction? Nobody finds out until the tank empties. How would you detect it if you had the analog transmitter from lesson 2?

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.