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
On this page
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.
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.
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.
| Type | Resolution | Timer numbers | Preset | |
|---|---|---|---|---|
| TON/TOF | 1 ms | T32, T96 | +1000 | exact |
| TON/TOF | 10 ms | T33–T36, T97–T100 | +100 | exact |
| TON/TOF | 100 ms | T37–T63, T101–T255 | +10 | exact |
| TONR | 1 ms | T0, T64 | +1000 | exact |
| TONR | 10 ms | T1–T4, T65–T68 | +100 | exact |
| TONR | 100 ms | T5–T31, T69–T95 | +10 | exact |
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.
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.
A coil straight on the power rail is refused by Micro/WIN: put a contact before it (SM0.0 = always on).
No errors: the program compiles.
Off-delay TOF and retentive TONR
| Timer | Bit | Current value | Typical use |
|---|---|---|---|
| TON on-delay | ON when value ≥ PT, while IN = 1 | counts while IN = 1, reset when IN = 0 | delayed start, time-out, star period |
| TOF off-delay | ON as soon as IN = 1, OFF when value ≥ PT after IN falls | counts after IN falls | fan run-on, "stop 2 s after the vehicle has left" |
| TONR retentive | ON when value ≥ PT | counts while IN = 1, keeps its value when IN = 0; only R clears it | running 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.
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.
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.5for 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).