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.
| FB | Detects | I/O |
|---|---|---|
R_TRIG | Rising edge of CLK | In: CLK (BOOL); Out: Q (BOOL) |
F_TRIG | Falling edge of CLK | In: CLK (BOOL); Out: Q (BOOL) |
Signature (both R_TRIG and F_TRIG):
FUNCTION_BLOCK R_TRIG // and F_TRIGVAR_INPUT CLK : BOOL;END_VARVAR_OUTPUT Q : BOOL;END_VAREND_FUNCTION_BLOCKTiming — R_TRIG:
QisTRUEfor exactly one cycle whenCLKchanges fromFALSEtoTRUE.- On every other cycle
QisFALSE. F_TRIGis the mirror image, pulsing on theTRUE→FALSEtransition.
VAR rise : R_TRIG; fall : F_TRIG;END_VAR
rise(CLK := button);IF rise.Q THEN presses := presses + 1; // increment once per button pressEND_IF
fall(CLK := button);IF fall.Q THEN // button releasedEND_IF