Skip to content

Core Concepts

Before diving deeper into the language, it is important to understand the fundamental principles of Coldwave Script. These differ significantly from classic high-level languages. Once these concepts are internalized, programs become easier to read, write, and—most importantly—predict, which is essential for control software.

Programs, Blocks, Variables

Coldwave Script consists of three primary building elements:

  • Programs contain execution flow and logic. Each script has exactly one PROGRAM … END PROGRAM block.
  • Function blocks such as TON (timer) or CTU (counter). They have inputs, outputs, and internal state.
  • Variables & constants store data. Variables are declared with DIM, constants with CONST.

Example:

vb
PROGRAM 
    DIM T AS TON 
    DIM counter AS INT = 0  
    T(IN = TRUE, PT = T#1000ms)  
    counter = counter + 1  
    PRINT counter, T.Q  
END PROGRAM

A key syntactic distinction:

  • Assignments inside a program use =.
  • Connecting signals to block inputs uses the connection operator :=.

A detailed explanation with examples can be found in the chapter Functions & Blocks under
Parameter Passing (IN/OUT) and the Operators = / :=.

Memory Segments

Coldwave Script separates data into four logical areas:

SegmentPurposeTypical examples
INReading inputsSensor values, fieldbus registers, block inputs
OUTWriting outputsRelays, LEDs, actuators, block outputs
TMPTemporary working valuesIntermediate calculations, scratch space
CONSTFixed valuesParameters, thresholds, project configuration

For practical use:

  • Anything coming from the outside is read through IN.
  • Anything acting on the outside is written through OUT.
  • Pure computational values exist as normal variables; the VM places them internally in TMP.
  • CONST values are fixed at compile/deployment time and do not change at runtime.

Details on internal addressing and banking are only relevant to integrators and documented in the internal architecture chapters.

Lifetime of Variables and Blocks

Coldwave Script executes cyclically. Each cycle:

  1. Input values (IN) are acquired from hardware or fieldbus.
  2. The program runs once from top to bottom.
  3. Output values (OUT) are written to hardware or fieldbus.

Important to understand:

  • Program-internal variables (DIM) retain their values across cycles as long as the script runs.
  • Function blocks (e.g. TON, CTU, or custom BLOCKs) retain state across cycles. Time counters, edge detections, etc. do not reset every cycle.
  • CONST values are fixed configuration parameters.

On VM restart or device reboot, all non-persistent values are reset to their initial state.

Data Types

Coldwave Script supports the following data types:

TypeExampleNotes
BOOLTRUE / FALSElogical values
INT42saturating (−32768 … +32767)
UINT65000lower bound 0, no negative result
DINT2147483647saturating, 32-bit
REAL3.14, 1.2E3IEEE-754 floating point
LREAL1.0E100double precision
TIMET#500mstime spans in milliseconds
DATEDATE#2025-01-01calendar date
TODTOD#12:00:00time of day
DTDT#2025-01-01-12:00:00date + time
STRING"Hello"UTF-8 string

Specifics:

  • Saturating arithmetic: INT + INT exceeding 32767 → 32767.
  • Promotion: mixed types are promoted (INT + REAL → REAL).
  • Time values: all TIME internally stored as milliseconds.

Example:

vb
PROGRAM  
    DIM a AS INT = 32000  
    DIM b AS INT = 1000  
    PRINT a + b ' Output: 32767 (saturated)
    PRINT TO_REAL(a) / 2 ' Output: 16000.0  
END PROGRAM

Execution Model (Prefeed, Main Loop, Cycle)

Programs run in cycles. Each cycle contains three phases:

+-----------+     +------------------+     +---------+  
| Prefeed   | --> | Main Execution   | --> | Commit  |  
+-----------+     +------------------+     +---------+
  • Prefeed: Inputs (IN) are acquired and initial values prepared.
  • Main execution: Statements and blocks run in sequence; temporary (TMP) values are used.
  • Commit: OUT values are written to real outputs.

Example:

vb
DIM T AS TON  
PROGRAM  
    T(IN = TRUE, PT = T#1000ms)  
    PRINT T.Q  
END PROGRAM

Execution sequence:

  1. Prefeed: timer input IN is sampled.
  2. Main: timer increments ET and computes Q.
  3. Commit: output is applied if Q = TRUE.

Summary

  • Programs contain logic, blocks hold state, variables hold data.
  • Segments separate IN, OUT, TMP, CONST for safety and clarity.
  • Integer arithmetic is saturating; mixed types are promoted.
  • Cycle model: Prefeed → Main → Commit ensures deterministic behavior.