Rules / timer-reset-by-own-condition
TON pause lasts one scan: the timer input is cleared later in the same branch
The timer runs on a variable that is reset on every path further down the same branch. On the next scan the input is already FALSE, the timer is cleared, and the condition that waited for the delay is open.
Severity: Critical
Rule id: timer-reset-by-own-condition
Timer cleared by its own run condition
What the rule checks
A timer counts on a variable that is cleared on every path further down the same branch. Scan N: the input is TRUE, counting starts, the variable is dropped. Scan N+1: the input is already FALSE, the timer is reset together with the accumulated time, and the condition that was waiting for the delay is open. The pause lasts one task cycle instead of the setpoint. On a live site that was 0.01 s against the 30 s configured. The code compiles, reads as correct, the setpoint is on the screen, the operator adjusts it, and it changes nothing. The rule looks at the branch tree, not at adjacent lines: a reset under a condition (IF T.Q THEN V := FALSE) is the normal one-shot pattern, the timer does complete its delay, and such code is left alone.
What it does to the plant
A 30 s pause on site lasts one task cycle; the setpoint is on the screen, people adjust it, and it changes nothing.
Example
FUNCTION_BLOCK FB_ChangeoverVAR_INPUT xRun : BOOL;END_VARVAR_OUTPUT xPump1 : BOOL;END_VARVAR tmrPause : TON; xSwitch : BOOL;END_VARIF xRun THEN tmrPause(IN := xSwitch, PT := T#30S); IF NOT xSwitch OR tmrPause.Q THEN xPump1 := TRUE; xSwitch := FALSE; ELSE xPump1 := FALSE; xSwitch := FALSE; END_IFEND_IF
FUNCTION_BLOCK FB_ChangeoverVAR_INPUT xRun : BOOL;END_VARVAR_OUTPUT xPump1 : BOOL;END_VARVAR tmrPause : TON; xSwitch : BOOL;END_VARIF xRun THEN tmrPause(IN := xSwitch, PT := T#30S); IF NOT xSwitch OR tmrPause.Q THEN xPump1 := TRUE; ELSE xPump1 := FALSE; END_IF IF tmrPause.Q THEN xSwitch := FALSE; END_IFEND_IF
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
- Take the timer input from OUTSIDE the branch the timer gates:
pause(IN := run_both, PT := …); run_2 := pause.Q;. The branch then cannot clear the timer's own count even by accident, and usually the whole IF turns out to be unnecessary. - If there is no external signal, separate “what we time” from “what we clear”: arm the timer from a dedicated hold flag (
switching) that is set when the switchover starts and cleared onT.Q, and feed the run condition from that flag. - Verify the delay on site by measurement, not by reading the code: a pause like this expires in one task cycle, and on the screen it looks like an instant switchover at any setpoint.
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