DriveLab
Account

Timers, counters and edges

TON, TOF and TONR with the S7-200 timer numbers and resolutions, CTU, CTD and CTUD, rising and falling edges, and classic patterns: delayed start, flasher, part counting, toggle. With timing diagrams.

40 min

Show me

On-delay timer TON

TON T37, +30: while the enabling input (IN) is 1, the timer counts time units; its current value (the word T37) goes up, and its bit (T37 as a contact) turns ON when the value reaches the preset PT. When IN drops, the value returns to 0 and the bit turns OFF.

The time unit depends on the timer number: T37 is a 100 ms timer, so PT = 30 means 3.0 s. The same number cannot be used by a TON and a TOF.

Ladder editor on a virtual PLC-200

Drag an instruction onto the rung (or click it, then click a place). Drop below a contact to put it in parallel. Click an element to edit its address; Delete removes it.

Network 1
SWITCHI0.0
T37TONPT +30 × 100 ms= 0 / 30
Network 2
DELAYT37
LAMPQ0.0
SIMATIC S7-200 · CPU 224SFRUNSTOP
I0.0SWITCH
Q0.0LAMP0
Timet = 0.00 s · 0 scans

No errors: the program compiles.

Open the Timing diagram tab while you operate the switch: you see SWITCH, the T37 bit and LAMP over the last 10 seconds. Switch OFF before 3 s: the timer restarts from 0.

Timer choice

The S7-200 timer number fixes its type and resolution. Enter a duration to see the preset of every group.

TypeResolutionTimer numbersPreset
TON/TOF1 msT32, T96+1000exact
TON/TOF10 msT33–T36, T97–T100+100exact
TON/TOF100 msT37–T63, T101–T255+10exact
TONR1 msT0, T64+1000exact
TONR10 msT1–T4, T65–T68+100exact
TONR100 msT5–T31, T69–T95+10exact

Now build it yourself: choose Exercise: delayed lamp, drag a TON into the first network, choose its number and preset for 3 s, and put a T-bit contact in front of LAMP. Check my program tests it at 2.8 s and 3.2 s.

Ladder editor on a virtual PLC-200

Drag an instruction onto the rung (or click it, then click a place). Drop below a contact to put it in parallel. Click an element to edit its address; Delete removes it.

Network 1
SWITCHI0.0
Network 2
LAMPQ0.0

A coil straight on the power rail is refused by Micro/WIN: put a contact before it (SM0.0 = always on).

SIMATIC S7-200 · CPU 224SFRUNSTOP
I0.0SWITCH
Q0.0LAMP0
Timet = 0.00 s · 0 scans

No errors: the program compiles.

Off-delay TOF and retentive TONR

TimerBitCurrent valueTypical use
TON on-delayON when value ≥ PT, while IN = 1counts while IN = 1, reset when IN = 0delayed start, time-out, star period
TOF off-delayON as soon as IN = 1, OFF when value ≥ PT after IN fallscounts after IN fallsfan run-on, "stop 2 s after the vehicle has left"
TONR retentiveON when value ≥ PTcounts while IN = 1, keeps its value when IN = 0; only R clears itrunning hours, cumulated on-time (TP 1)
ExplorerGo deeper: derivations and open questions

When do timers update? On the S7-200 a 1 ms timer is updated by the operating system every millisecond, a 10 ms timer at the start of each scan, and a 100 ms timer when its instruction executes. That is why a 100 ms timer must be executed exactly once per scan: skipped (inside a jump) it loses time; executed twice it counts double. The self-restarting pattern LDN T37 / TON T37, +n is safe with 100 ms timers; with 1 ms and 10 ms timers its done bit can be missed. This simulator executes every timer when its instruction runs.

Counters

CTU C0, +5 counts rising edges of its CU input; its bit turns ON when the value reaches PV; the R input clears it. CTD counts down from PV (loaded by LD) and its bit turns ON at 0. CTUD counts up and down.

Ladder editor on a virtual PLC-200

Drag an instruction onto the rung (or click it, then click a place). Drop below a contact to put it in parallel. Click an element to edit its address; Delete removes it.

Network 1
PARTI0.0
C0CTUR: CLEAR= 0 / 5
Network 2
C0
BOX_FULLQ0.0
SIMATIC S7-200 · CPU 224SFRUNSTOP
I0.0PART
I0.1CLEAR
Q0.0BOX_FULL0
Timet = 0.00 s · 0 scans

No errors: the program compiles.

In STL a counter takes two or three inputs from the logic stack: LD PART / LD CLEAR / CTU C0, +5. Look at the STL view: the first LD is CU, the second is R.

Edges

A rising edge –|P|– (STL EU) passes power for exactly one scan when the power flow before it goes from 0 to 1. Use it to count once per press, to toggle, or to copy a value once. Choose Edges and toggle above: each press of BUTTON toggles LAMP. Remove the P contact and the lamp flickers at scan speed while you hold the button.

Predict first

A counter counts parts with `LD I0.4 / LD I0.3 / CTU C0, +6`. Why does it count one per part and not one per scan while the part is in front of the sensor?

Patterns worth knowing

  • Flasher: two timers restarting each other (preset Flasher), or simply A SM0.5 for a 1 Hz blink.
  • Time-out: a TON enabled while a movement is commanded and its end position not reached; its bit latches a fault. TP 1, TP 3 and TP 5 all use it.
  • Measuring a time: a 1 ms timer (T32) running between two edges; copy its value with MOVW T32, VW… on the second edge. TP 1 measures the motor speed this way.
  • Proof of motion: a counter of sensor pulses reset at start; if it has not reached 2 within 3 s, trip (TP 5).