TON in Text
Part of the Structured Text section of Coddy's PLC Programming journey. Lesson 6 of 17.
A timer in text is a variable too: its type is the block, TON. You call it with its inputs, and read its outputs with a dot:
VAR
T1 : TON;
END_VAR
T1(IN := PB1, PT := T#2s);
Green := T1.Q;IN is what powered the box on the rung, PT is the preset time, and T1.Q is TRUE once IN has been TRUE for PT. T1.ET is the elapsed time.
Call the timer on every scan, not inside an IF. A timer only sees IN when it is called: skip the call and it never sees IN go FALSE, so it never resets.
Pass a block's inputs inside its call, as here. Some editors also let you write T1.IN := PB1; before the call; this course always passes them in the call. In Siemens TIA Portal the timer gets an instance data block, and the call looks the same.
Challenge
EasyLight Green once PB1 has been held for 2 seconds. Releasing PB1 turns it off and starts the time again.
Press Run, try it on the machine, then Check.
Try it yourself
VAR
T1 : TON;
END_VAR
// Call T1 here, then light Green from T1.Q
All lessons in Structured Text
Practice on your own: PLC playground