0
0
FreertosHow-ToBeginner · 4 min read

How to Create Sequence Using Timer in PLC Programming

To create a sequence using a timer in a PLC, use timer instructions like TON (Timer On Delay) to delay transitions between steps. Each timer triggers the next step in the sequence after its preset time, enabling controlled automation steps.
📐

Syntax

In PLC programming, the common timer instruction for sequences is TON (Timer On Delay). It has these parts:

  • Timer Name: Identifier for the timer.
  • Input (IN): Boolean signal to start the timer.
  • Preset Time (PT): Duration to wait before timer finishes.
  • Elapsed Time (ET): Time counted so far (read-only).
  • Output (Q): Becomes true when elapsed time reaches preset.
structured_text
TON TimerName(IN:=StartSignal, PT:=T#5s, Q=>TimerDone, ET=>ElapsedTime);
💻

Example

This example shows a simple 3-step sequence using timers. Each step turns on an output for 3 seconds, then moves to the next step automatically.

structured_text
VAR
  Step1Timer : TON;
  Step2Timer : TON;
  Step3Timer : TON;
  Step : INT := 0;
  Output1, Output2, Output3 : BOOL := FALSE;
END_VAR

// Step 1: Start timer and output
IF Step = 0 THEN
  Step1Timer(IN := TRUE, PT := T#3s);
  Output1 := TRUE;
  IF Step1Timer.Q THEN
    Step := 1;
    Step1Timer(IN := FALSE, PT := T#3s);
    Output1 := FALSE;
  END_IF
END_IF

// Step 2: Start timer and output
IF Step = 1 THEN
  Step2Timer(IN := TRUE, PT := T#3s);
  Output2 := TRUE;
  IF Step2Timer.Q THEN
    Step := 2;
    Step2Timer(IN := FALSE, PT := T#3s);
    Output2 := FALSE;
  END_IF
END_IF

// Step 3: Start timer and output
IF Step = 2 THEN
  Step3Timer(IN := TRUE, PT := T#3s);
  Output3 := TRUE;
  IF Step3Timer.Q THEN
    Step := 0; // Loop back to step 0
    Step3Timer(IN := FALSE, PT := T#3s);
    Output3 := FALSE;
  END_IF
END_IF
Output
Output1 ON for 3 seconds, then OFF; Output2 ON for 3 seconds, then OFF; Output3 ON for 3 seconds, then OFF; sequence repeats.
⚠️

Common Pitfalls

  • Not resetting the timer input (IN) after the timer finishes causes the timer to keep running.
  • Forgetting to advance the step variable leads to the sequence freezing on one step.
  • Using timers without checking their Q output can cause premature or delayed step changes.
structured_text
(* Wrong: Timer input never reset, sequence stuck *)
Step1Timer(IN := TRUE, PT := T#3s);
IF Step1Timer.Q THEN
  Step := 1; // Step changes but timer keeps running
END_IF

(* Correct: Reset timer input to stop timing after done *)
Step1Timer(IN := Step = 0, PT := T#3s);
IF Step1Timer.Q THEN
  Step := 1;
END_IF
📊

Quick Reference

Use these tips for timer-based sequences:

  • Use TON timers to delay steps.
  • Control sequence steps with a step counter variable.
  • Reset timer inputs after completion.
  • Check timer Q output to move to next step.
  • Loop or stop sequence as needed.

Key Takeaways

Use TON timers to create delays between sequence steps in PLC programs.
Control the sequence flow with a step variable and advance it when timers finish.
Always reset timer inputs after the timer completes to avoid stuck timers.
Check the timer's Q output to know when to move to the next step.
Loop sequences by resetting the step counter or stop as per your process needs.