R_TRIG — Rising-edge trigger
Pin layout
| Direction | Name | Type | Description |
|---|---|---|---|
| Input | CLK | BOOL | Signal to edge-detect |
| Output | Q | BOOL | TRUE for exactly one scan after CLK rises FALSE→TRUE |
Syntax
VAR
edgeRise : R_TRIG;
END_VAR
edgeRise(CLK := xButton);
IF edgeRise.Q THEN
iCounter := iCounter + 1;
END_IF;
Semantics
Per Annex F.5.1, evaluated on each call:
Q := CLK AND NOT _previousCLK._previousCLK := CLK.
The internal _previousCLK starts as FALSE on instance
creation. So the first call where CLK = TRUE produces a
rising edge regardless of how CLK looked outside the
program — useful for one-shot startup actions.
Why edge detection at all?
PLC scan cycles often see the same level signal TRUE for
many consecutive cycles. If you want “do X once when the
button is pressed”, you can’t just write
IF xButton THEN DoX(); END_IF; because that fires DoX()
every scan while the button is held down.
R_TRIG turns the level into an event:
edgeRise(CLK := xButton);
IF edgeRise.Q THEN
DoX(); (* fires exactly once per press *)
END_IF;
IEC reference
IEC 61131-3 third edition (2013), Annex F.5.1.
matiec conformance
Implemented per the standard. The instance-must-live-across-
cycles requirement (and therefore the FB nature) is the most
common LLM trap — R_TRIG(CLK := x) directly is a compile
error; only myEdge(CLK := x) works.