# Timers Overview

Source: https://rungs.dev/docs/ladder-logic/instructions/timers

> Reference for Ladder Logic timer instructions in rungs.dev — TON, TOF, RTO, and RES — and the TIMER tag structure with preset, accumulator, and status bits.

Timers measure elapsed time. A timer instruction references a `TIMER` tag, which is a structure with a preset, an accumulator, and three status bits.

## Available Timer Instructions [#available-timer-instructions]

| Instruction  | Symbol                           | Purpose                                                                                                                        |
| ------------ | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| [TON](https://rungs.dev/docs/ladder-logic/instructions/ton) |  | On-delay timer. Starts timing when the rung goes true; sets .DN when .ACC reaches .PRE. Resets the moment the rung goes false. |
| [TOF](https://rungs.dev/docs/ladder-logic/instructions/tof) |  | Off-delay timer. Starts timing when the rung goes false; holds .DN at 1 for the preset duration after the rung drops.          |
| [RTO](https://rungs.dev/docs/ladder-logic/instructions/rto) |  | Retentive on-delay timer. Like TON, but the accumulator survives rung transitions. Must be cleared explicitly with RES.        |

## TIMER Tag Members [#timer-tag-members]

Every `TIMER` tag exposes the same fields. Access them with a dot (`MyTimer.DN`).

| Member | Type   | Meaning                                                            |
| ------ | ------ | ------------------------------------------------------------------ |
| `.PRE` | `DINT` | Preset — target time in milliseconds                               |
| `.ACC` | `DINT` | Accumulated time in milliseconds                                   |
| `.EN`  | `BOOL` | Enable — `1` while the rung is true                                |
| `.TT`  | `BOOL` | Timing — `1` while accumulating toward `.PRE`                      |
| `.DN`  | `BOOL` | Done — each timer (`TON`, `TOF`, `RTO`) decides when this turns on |

Reference these members as contacts:

```ladder
XIC(MyTimer.DN)OTE(Light)
```

## How Timers Use Scan Time [#how-timers-use-scan-time]

A timer measures how much simulation time passes between the times its instruction runs. The first scan that starts the timer adds no time: `TON` and `TOF` start at `.ACC = 0`, while `RTO` resumes at its retained value. The same goes for the scan after a [`RES`](https://rungs.dev/docs/ladder-logic/instructions/res) while the rung stays true: it restarts the timer and adds no time.

During **Start**, Studio uses the configured scan period, which is 100 ms by default. Small browser delays do not change those simulated scan times. If several scans are missed, the next scan catches the timer up to the latest scheduled scan time. Switching browser tabs pauses the simulation instead of creating a large jump.

Completion is checked only when the timer executes. With Studio's 100 ms scans, `.PRE = 2000` can finish exactly at 2000 ms. `.PRE = 2050` finishes at the next check, 2100 ms, and keeps that value — `.ACC` is not forced back to `.PRE`.

## Setting the Preset [#setting-the-preset]

The preset is stored on the timer tag, not inside the instruction. There are two ways to set it:

- **From the rung:** click the `Preset` row on the `TON`, `TOF`, or `RTO` block and type the value. This edits the `.PRE` default of the underlying `TIMER` tag in place — no need to leave the ladder editor.
- **From the Tag editor:** expand the timer tag's row and edit the `Default Value` of `.PRE`.

Either way, the value is the target time **in milliseconds**: `5000` = 5 seconds. The `Accum` row on the block is editable the same way and sets the `.ACC` default. During [prescan](https://rungs.dev/docs/scan-cycle/the-scan-cycle#before-the-first-scan) — the preparation pass before the first scan — `TON` sets `.ACC` to `0`, `TOF` sets it to `.PRE`, and `RTO` retains its current value.

Writing `.ACC` from a running rung takes effect on a ladder timer, but do not use `MOVE(0, MyTimer.ACC)` to restart a finished timer. Its `.DN` bit stays in the finished state, so a done `TON` or `RTO` can sit at `.ACC = 0`, `.DN = 1` while its rung remains true. Use [`RES`](https://rungs.dev/docs/ladder-logic/instructions/res) instead: it clears `.ACC`, `.EN`, `.TT`, and `.DN` together and re-arms the timer. Structured Text timers (`TONR` / `TOFR` / `RTOR`) overwrite their output members each time they run, so writing `.ACC` does not restart them either.

## Units [#units]

All timer values are in milliseconds. There is no separate time base — always multiply seconds by `1000`.