free quality report for PLCopenXML exports

Rules / edge-lost-in-own-branch

R_TRIG fires only once: the edge detector never sees the input drop

An edge detector (and the count input of CTU) compares its input with what it saw on the previous call. If it is only called inside a branch that requires that same input, it never sees the drop, and every later edge is lost.

Severity: Critical Rule id: edge-lost-in-own-branch An edge input never sees the drop, so only the first event counts

What the rule checks

An edge input, on R_TRIG, F_TRIG and on the counting input of CTU/CTUD, is compared with what the FB saw at its previous call. If it is only called inside a branch whose condition requires that same input, it never witnesses the input going down: at that moment the branch does not execute. Its internal memory stays latched, and every later rise no longer counts as an edge. Measured on a scan emulator: a detector produced one pulse out of ten transitions, and a CTU counted 1 against a preset of 5. The trap is that the FIRST edge works normally, so a quick check on site (press it, it fires) shows nothing; the defect appears from the second time on.

What it does to the plant

The first edge passes, so a "press it and it works" check shows nothing; a start counter counts 1 instead of 5.

Example

Bad: the rule fires
FUNCTION_BLOCK FB_CountStartsVAR_INPUT    xCmd : BOOL;END_VARVAR_OUTPUT    xStarted : BOOL;END_VARVAR    trigStart : R_TRIG;END_VARIF xCmd THEN    trigStart(CLK := xCmd);    xStarted := trigStart.Q;END_IF
Fixed: the rule is silent
FUNCTION_BLOCK FB_CountStartsVAR_INPUT    xCmd : BOOL;END_VARVAR_OUTPUT    xStarted : BOOL;END_VARVAR    trigStart : R_TRIG;END_VARtrigStart(CLK := xCmd);xStarted := trigStart.Q;

Both listings are run through the linter by an automated test: the rule fires on the first and stays silent on the second.

How to fix

  1. Call the FB unconditionally and pass the condition to its input: r(CLK := v); outside the branch, and keep only the actions on r.Q inside.
  2. Test it twice in a row on site: the first pulse always works, the defect shows from the second.
Check your project

Upload a PLCopen XML or CODESYS .export file: the report is free and the code is not stored.

Local version on GitHub →

The same linter without uploading a file: command line and GitHub Action.

Related rules

2026-11-26

Processing happens in memory, and the uploaded code is not stored. The tool advises; code changes are up to the engineer (see what the linter can't see). What happens to your code → · Rule reference · Your code & privacy · Industry benchmark · Feedback · GitHub