How do timers work in PLC Structured Text (ST)? How do we declare them?
I've been studying a standard of PLC (IEC 61131-3), and they do not speak about timers in ST. I know the great majority of PLC programmers do them in ladder logic, but in this particular case I really need to declare timers in ST.
I am using a Rockwell PLC.
You can find explanations about timers and how to use (declare) it in the help system of your IDE. For example, in the CODESYS help you can read about timers of the standard library.
In general, you can declare timer-delay (TON) as:
VAR
MY_TON: TON;
END_VAR
(* standard.library should be added to the project *)
Then you can use it:
MY_TON(IN:= IN_VALUE,PT:= TIME_SET);
(*IN_VALUE - is BOOL variable that activates your timer
TIME_SET - is TIME variable*)
SOME_OUTPUT := MY_TON.Q;
(*Q - is the timer's output, and it can be used as BOOL variable. *)
You can also use constants to set up your timer:
MY_TON(IN:= True, PT:= t#5s);
As a BOOL variable, the timer's output can be used in IF and WHILE statements:
IF MY_TON.Q THEN
(*Some statements...*)
END_IF
WHILE MY_TON.Q DO
(*Some statements...*)
END_WHILE
All examples are run in CODESYS v3.5 SP5 and v2.3. For other IDEs there might be nuances.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With