Appearance
Standard Blocks
Coldwave Script includes a set of ready-made blocks that simplify common control tasks significantly. Instead of implementing counters or timers manually every time, you can rely on these proven components. All blocks have inputs (IN, PT, CU, …) and outputs (Q, CV, ET, …) and are instantiated like variables.
TON – On‑Delay Timer
Inputs:
IN(BOOL): start signalPT(TIME): preset duration
Outputs:
Q(BOOL): TRUE when IN has been active for at least PTET(TIME): elapsed time
Description: TON activates Q only when IN remains TRUE continuously for PT. ET exposes elapsed time.
vb
PROGRAM
DIM T AS TON
T(IN = TRUE, PT = T#2000ms)
PRINT T.Q, T.ET
END PROGRAMTOF – Off‑Delay Timer
Inputs:
IN(BOOL): input signalPT(TIME): delay duration
Outputs:
Q(BOOL): TRUE while IN=TRUE or delay time has not elapsedET(TIME): elapsed time since IN turned FALSE
Description: TOF keeps Q TRUE for PT after IN falls to FALSE.
vb
PROGRAM
DIM T AS TOF
T(IN = TRUE, PT = T#3000ms)
PRINT T.Q, T.ET
END PROGRAMTP – Pulse Timer
Inputs:
IN(BOOL): trigger signalPT(TIME): pulse length
Outputs:
Q(BOOL): TRUE for exactly PT after a rising edge on IN
Description: TP produces a pulse of length PT on a rising edge, regardless of subsequent IN changes.
vb
PROGRAM
DIM T AS TP
T(IN = TRUE, PT = T#1000ms)
PRINT T.Q
END PROGRAMCTU – Up Counter
Inputs:
CU(BOOL): count‑up trigger (rising edge increments)PV(INT): preset value
Outputs:
Q(BOOL): TRUE when CV ≥ PVCV(INT): current counter value
Description: CTU increments CV on each rising edge of CU. When CV ≥ PV, Q becomes TRUE.
vb
PROGRAM
ALIAS %I0 AS pulse ' CTU needs a rising edge as pulse
DIM C AS CTU
C(CU = pulse, PV = 3)
PRINT C.CV, C.Q
END PROGRAMCTD – Down Counter
Inputs:
CD(BOOL): count‑down trigger (rising edge decrements)PV(INT): start value
Outputs:
Q(BOOL): TRUE while CV > 0CV(INT): current counter value
Description: CTD starts at PV and decrements CV per edge. Q becomes FALSE when CV reaches 0.
vb
PROGRAM
ALIAS %I0 AS pulse ' CTU needs a rising edge as pulse
DIM C AS CTD
C(CD = pulse, PV = 5)
PRINT C.CV, C.Q
END PROGRAMCTUD – Up/Down Counter
Inputs:
CU(BOOL): increment triggerCD(BOOL): decrement triggerPV(INT): preset value
Outputs:
Q(BOOL): TRUE when CV ≥ PVCV(INT): current counter value
Description: CTUD combines CTU and CTD. Useful for bidirectional counts (e.g., encoders).
vb
PROGRAM
ALIAS %I0 AS pulse ' CTUD needs an edge as pulse
DIM C AS CTUD
C(CU = TRUE, CD = FALSE, PV = 10)
PRINT C.CV, C.Q
END PROGRAMR_TRIG – Rising Edge Detector
Inputs:
CLK(BOOL)
Outputs:
Q(BOOL): TRUE for exactly one cycle when CLK rises FALSE→TRUE
Description: Detects rising edges.
vb
PROGRAM
DIM F AS R_TRIG
DIM clk AS BOOL = TRUE ' this needs to come from a real input that creates edges
F(CLK = clk)
IF F.Q THEN
PRINT "Rising edge detected"
END IF
END PROGRAMF_TRIG – Falling Edge Detector
Analogous to R_TRIG, but detects TRUE→FALSE transitions.
vb
PROGRAM
DIM F AS F_TRIG
DIM clk AS BOOL = FALSE ' this needs to come from a real input that creates edges
F(CLK = clk)
IF F.Q THEN
PRINT "Falling edge detected"
END IF
END PROGRAMExamples
Blinking using TON:
vb
PROGRAM
DIM T AS TON
DIM state AS BOOL = FALSE
IF NOT T.Q THEN
T(IN = TRUE, PT = T#500ms)
END IF
IF T.Q THEN
state = NOT state
T(IN = FALSE, PT = T#500ms)
END IF
PRINT state
END PROGRAMDelayed shutdown using TOF:
vb
PROGRAM
DIM T AS TOF
DIM light AS BOOL = TRUE
T(IN = light, PT = T#2000ms)
PRINT T.Q
END PROGRAMCounting pulses with CTU:
vb
PROGRAM
DIM C AS CTU
DIM pulse AS BOOL = TRUE ' this needs to come from a real input that creates edges
C(CU = pulse, PV = 5)
PRINT "Count=", C.CV, " Done=", C.Q
END PROGRAMEdge‑triggered counting (R_TRIG + CTU):
vb
PROGRAM
DIM F AS R_TRIG
DIM C AS CTU
DIM clk AS BOOL = TRUE ' this needs to come from a real input that creates edges
F(CLK = clk)
IF F.Q THEN
C(CU = TRUE, PV = 3)
END IF
PRINT C.CV, C.Q
END PROGRAMExercises with Solutions
Task 1: Use TON to enable an output after 2 seconds.
vb
PROGRAM
DIM T AS TON
ALIAS %I0 AS trig ' Trigger-Input
T(IN = trig, PT = T#2000ms)
PRINT T.Q
END PROGRAMTask 2: Count 5 pulses and print "Done" when finished.
vb
PROGRAM
DIM C AS CTU
ALIAS %I0 AS trig ' Trigger-Input
C(CU = trig, PV = 5)
PRINT C.CV, C.Q
END PROGRAMTask 3: Detect rising edge and output a pulse.
vb
PROGRAM
DIM F AS R_TRIG
DIM out AS BOOL = FALSE
DIM clk AS BOOL = TRUE ' this needs to come from a real input that creates edges
F(CLK = clk)
out = F.Q
PRINT out
END PROGRAMSummary
- Timers (TON, TOF, TP) control time behavior.
- Counters (CTU, CTD, CTUD) count events.
- Edge detection (R_TRIG, F_TRIG) detects signal transitions.
- All blocks are stateful and must be instantiated.