Skip to content

Contact Decorators

Decorators extend contact behavior with timing, edge detection, and counting capabilities without requiring separate timer/counter rungs.

Overview

Decorators are attached to contact instructions (XIC/XIO) and modify how the contact's output affects rung power flow.

How Decorators Work

  1. The base contact evaluates its bit state (XIC: TRUE when bit=1, XIO: TRUE when bit=0)
  2. This result passes through the decorator chain in order
  3. Each decorator processes the previous output and produces a new output
  4. The final output determines rung power flow
Contact → [Decorator1] → [Decorator2] → ... → Rung Power

Available Decorators

Decorator Type Description
TON Timer On-delay — output goes TRUE after preset time
TOF Timer Off-delay — output stays TRUE for preset time after input goes FALSE
OSR Edge One-shot rising — single scan pulse on FALSE→TRUE transition
OSF Edge One-shot falling — single scan pulse on TRUE→FALSE transition
Debounce Filter Requires stable input for a configurable duration
Counter Counter Counts rising edges, sets DN when ACC ≥ PRE

TON Decorator TOF Decorator OSR Decorator OSF Decorator Debounce Decorator

Memory Integration

Timer and counter decorators are automatically assigned T: or C: memory addresses when created. This enables:

  • RES instruction support: Target the decorator's address with a RES instruction to reset its state
  • Memory synchronization: Decorator state (ACC, DN, TT, EN) is synced with the PLC memory manager each scan cycle
  • Symbol table entries: Auto-created variables (e.g., DEC_TON_0, DEC_TOF_1) appear in the symbol table

Note

Address assignment is automatic and avoids conflicts with standalone timer/counter instructions. Addresses are persisted in project files and restored on load.

Runtime State Inspection

During simulation, right-click on a decorator glyph to open a live state dialog showing:

  • Timer decorators (TON/TOF): Address, PRE/ACC values, progress bar, DN/TT/EN indicators
  • Counter decorators: Address, PRE/ACC values, progress bar, DN indicator
  • Debounce decorators: Debounce time, accumulated time, output state
  • Edge decorators (OSR/OSF): Triggered state

The dialog refreshes at 100ms intervals for real-time monitoring.

Decorator Chaining

Multiple decorators can be applied to a single contact. They execute in order from first (innermost) to last (outermost).

Example Chain: [Debounce:50ms] → [TON:2000ms] → [OSR]

  1. Contact evaluates I:0/0
  2. Debounce filters rapid changes (stable after 50ms)
  3. TON delays the stable signal (TRUE after 2 seconds)
  4. OSR converts to single pulse (one scan on rising edge)

Tip

Decorator chaining lets you build complex input conditioning in a single contact, keeping your ladder clean and readable.