Rules / timer-off-delay-in-own-branch
TOF is only called while its input is high: the off-delay never runs
An off-delay must count while its input is low. If it is only called inside a branch that requires that same input, there is no call when the command drops, and the elapsed time stays at zero.
Severity: Critical
Rule id: timer-off-delay-in-own-branch
Off-delay is not called when it should be counting
What the rule checks
An off-delay counts while its input is DOWN: drop the command, the delay runs, the output goes off after the setpoint. If the timer is only called inside a branch whose condition requires that same input, then at the moment the command is dropped the branch does not execute, there is no call, and the accumulated time stays at zero. The delay never ends and the equipment never stops. For an on-delay the same code is correct, since it is meant to count while the condition holds, so the rule looks only at TOF and TONOF. Found by enumerating combinations and confirmed with a scan emulator: the accumulated time stayed at zero under every input behaviour tried.
What it does to the plant
Depending on the surrounding code the output either drops at once with no delay or never drops: run-on and purge do not work as designed.
Example
FUNCTION_BLOCK FB_FanRunOnVAR_INPUT xCmd : BOOL;END_VARVAR_OUTPUT xFan : BOOL;END_VARVAR tofRunOn : TOF;END_VARIF xCmd THEN tofRunOn(IN := xCmd, PT := T#30S); xFan := tofRunOn.Q;ELSE xFan := FALSE;END_IF
FUNCTION_BLOCK FB_FanRunOnVAR_INPUT xCmd : BOOL;END_VARVAR_OUTPUT xFan : BOOL;END_VARVAR tofRunOn : TOF;END_VARtofRunOn(IN := xCmd, PT := T#30S);xFan := tofRunOn.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
- Call the timer unconditionally and pass the condition to its input: put
t(IN := v, PT := …);outside the branch and keep the branch for the actions. - Test the stop, not the start: starting works correctly in this code, and the defect only shows at shutdown.
Upload a PLCopen XML or CODESYS .export file: the report is free and the code is not stored.
The same linter without uploading a file: command line and GitHub Action.
Related rules
2026-11-26