Skip to content

Edge-detection function blocks

Edge detectors convert a level signal into a single-cycle pulse on a transition. Both take a Boolean CLK input and produce a Boolean Q output.

FBDetectsI/O
R_TRIGRising edge of CLKIn: CLK (BOOL); Out: Q (BOOL)
F_TRIGFalling edge of CLKIn: CLK (BOOL); Out: Q (BOOL)

Signature (both R_TRIG and F_TRIG):

FUNCTION_BLOCK R_TRIG // and F_TRIG
VAR_INPUT
CLK : BOOL;
END_VAR
VAR_OUTPUT
Q : BOOL;
END_VAR
END_FUNCTION_BLOCK

Timing — R_TRIG:

  • Q is TRUE for exactly one cycle when CLK changes from FALSE to TRUE.
  • On every other cycle Q is FALSE.
  • F_TRIG is the mirror image, pulsing on the TRUEFALSE transition.
VAR
rise : R_TRIG;
fall : F_TRIG;
END_VAR
rise(CLK := button);
IF rise.Q THEN
presses := presses + 1; // increment once per button press
END_IF
fall(CLK := button);
IF fall.Q THEN
// button released
END_IF