I have an INT and TON defined
VAR
state : INT := 0;
timer_on : TON;
END_VAR
Now. The program is like this
IF (state = 0) THEN
timer_on(IN := TRUE, PT := T#5s);
IF (timer_on.Q = TRUE) THEN
timer_on.IN := FALSE;
state := 1;
END_IF
END_IF
When it is executed state is changed to 0 after 5 seconds. That's ok. But when I change state back to 0 it immediately goes back to 1. According to the documentation
Q is TRUE when IN is TRUE and ET is equal to PT. Otherwise it is FALSE.
In my case, after 5 seconds Q is always TRUE even when IN is FALSE
Changing the input variables of a function block does NOT execute the function block. You need to run it to see the change.
What happens when you run your program:
The solution is to change the timer_on.IN := FALSE;
line to timer_on(IN := FALSE);
. This will run the timer with IN false which, as the documentation states, will reset itself for the next use.