Type to search, in English or Thai

  1. Home
  2. English lessons
  3. PLC Automation
  4. Timers · counters

// Chapter 22.4 · PLC · Timers & Counters

Timers and Counters to IEC 61131-3: TON, TOF, TP, CTU, CTD and CTUD with Timing Diagrams and Real-World Examples

Timers and counters are the main reason a PLC pays for itself against a relay panel. One timer in the program replaces a physical timer relay costing tens of dollars, and its time can be set precisely from the HMI. This page uses the names from IEC 61131-3, which is the template for the instructions of every brand.

By Ajarn ModUpdated
In 30 seconds
  • TON: IN must stay on for the full PT before Q = 1 · TOF: Q stays on for PT after IN goes off · TP: one pulse of length PT per rising edge
  • CTU counts rising edges of CU · Q = 1 when CV ≥ PV · R clears it
  • Accuracy ≈ ± one scan time
  • Very long times: use a minute timer feeding a counter

The three timer types Basic

INTON.QTOF.QTP.Q024681012141618Time (s)PTpulses shorter than PT → no TON outputholds 3 s after IN fallsIN during the pulse is ignoredET (elapsed time) counts up only while the timer is timing
Figure 1 · The same input (top row) driving the three timer types with PT = 3 s

T1 TON — on-delay

ET={min⁡(ET+Δt, PT)IN=10IN=0Q=IN∧(ET≥PT)ET = \begin{cases} \min(ET + \Delta t,\ PT) & IN = 1 \\ 0 & IN = 0 \end{cases} \qquad Q = IN \wedge (ET \ge PT)

T2 TOF — off-delay

Q=IN∨(ET<PT)where ET starts timing when IN:1→0, ET=0 while IN=1Q = IN \vee (ET < PT) \quad \text{where } ET \text{ starts timing when } IN: 1 \to 0,\ ET = 0 \text{ while } IN = 1

T3 TP — fixed-length pulse

Q=1 during [t0, t0+PT) after a rising edge of IN at t0 (not retriggered during the pulse)Q = 1 \ \text{during } [t_0,\ t_0 + PT) \text{ after a rising edge of } IN \text{ at } t_0 \ (\text{not retriggered during the pulse})

T4 Software timer accuracy

PT≤tactual≤PT+tscan+tbasePT \le t_{actual} \le PT + t_{scan} + t_{base}
Example T-1

A conveyor that sounds a horn for 5 s before starting, with a cooling fan that runs on for 2 minutes after it stops

  1. Run command M0.0 (seal-in from START/STOP) · T1 = TON(M0.0, 5s)

  2. Horn: Q0.1 = M0.0 & !T1 · conveyor: Q0.0 = T1 (runs once the 5 s are up)

  3. Fan: T2 = TOF(Q0.0, 120s) · Q0.2 = T2 — runs together with the conveyor and stays on for another 2 minutes after the conveyor stops

T5 Flasher from two timers

T1=TON(EN∧T2‾, ton)T2=TON(T1, toff)Q=EN∧T1‾(Tperiod=ton+toff)T1 = \text{TON}(EN \wedge \overline{T2},\ t_{on}) \quad T2 = \text{TON}(T1,\ t_{off}) \quad Q = EN \wedge \overline{T1} \quad (T_{period} = t_{on} + t_{off})

Counters Basic

CURCV123456QCV ≥ PV = 4CV keeps counting past PV (up to the data-type maximum) · RESET clears CV and Q
Figure 2 · CTU counts only rising edges of CU, so a part that stops in front of the sensor is counted only once

T6 CTU — up counter

CVk+1={0R=1CVk+1P(CU)CVkotherwiseQ=(CV≥PV)CV_{k+1} = \begin{cases} 0 & R = 1 \\ CV_k + 1 & P(CU) \\ CV_k & \text{otherwise} \end{cases} \qquad Q = (CV \ge PV)

T7 CTD — down counter

CV=PV on LDCVk+1=CVk−1 at P(CD)Q=(CV≤0)CV = PV \text{ on LD} \qquad CV_{k+1} = CV_k - 1 \text{ at } P(CD) \qquad Q = (CV \le 0)

CTUD combines both in one block (QU and QD). Use it to count how many items are inside an area, such as cars entering and leaving a car park, or parts in a buffer between two machines.

Example T-2

A filter change every 500 running hours, but the maximum timer PT is 24 h

  1. Create a pulse every hour while the pump runs: T1 = TON(Q0.0 & !T1, 3600s) (resets itself when done)

  2. Count the pulses: C1 = CTU(T1, I0.5, 500) · I0.5 = reset button pressed after changing the filter

  3. Warning: Q0.3 = C1 · make C1 retentive so its value is not lost in a power failure

Names in each brand

IEC 61131-3Siemens S7-1200/1500Mitsubishi FX5/iQOmron CP/NX
TONTON (IEC_TIMER)OUT T0 K50 (100 ms) / TON FBTIM / TON
TOFTOFTOF FB (or a circuit)TOF
TPTPTP FBTP
CTUCTUOUT C0 K10 / CTU FBCNT / CTU

Older timers in some brands are set as a number of “time-base” units, e.g. K50 on a 100 ms base = 5 s. Always check the time base when moving a program between models.

High-speed counters Intermediate

A CTU in the program can count at no more than about half the scan rate (it must see 0 for one scan and 1 for one scan). For example, a 10 ms scan counts no faster than ~50 Hz, and the input filter time must be subtracted too. Encoders and high-speed sensors must be wired to the CPU's high-speed counter (HSC) inputs, which count in hardware at tens or hundreds of kHz and support two-phase A/B signals.

T8 Software counter limit

fmax≈12 (tscan+tin)f_{max} \approx \frac{1}{2\,(t_{scan} + t_{in})}

Frequently asked questions

How accurate is a PLC timer?

A timer is updated when it is executed in each scan, so its error is about one scan time (plus the resolution of its time base, e.g. 1 ms, 10 ms or 100 ms). That is fine for general work, but if you need millisecond accuracy use a hardware timer, a cyclic-interrupt task or the CPU's pulse outputs.

A timer stops timing when it is in a part of the program that is not called. What is happening?

A software timer only times while its instruction is being executed. If it sits inside a function or a jumped-over section that is not running, it stops timing or freezes its value. Call the timer every scan and control it through its IN input instead.

Ajarn Mod · Teerawut Savangboon
Lecturer in Electrical Engineering, Dhonburi Rajabhat University, Samut Prakan · Profile