ℹ️ Select 'Choose Exercise', or randomize 'Next Random Exercise' in selected language.

Choose Exercise:
Timer 00:00
WPM --
Score --
Acc --
Correct chars --

Conveyor Sequencing with Timer Delays and Batching

PLC Ladder Diagram (LD)

Goal -- WPM

Ready
Exercise Algorithm Area
1PROGRAM ConveyorBatchSequence
2
3VAR
4StartSignal : BOOL;
5StopSignal : BOOL;
6ProductSensor : BOOL;
7BatchCount : INT := 0;
8C1_Run : BOOL;
9C2_Run : BOOL;
10
11Timer_C1_to_C2 : TON;
12Preset_C1_to_C2 : TIME := T#2S;
13
14Timer_C2_RunTime : TON;
15Preset_C2_RunTime : TIME := T#1S;
16
17SystemActive : BOOL;
18C2_BatchCycleActive : BOOL;
19END_VAR
20
21// Main system activation and stop logic
22SystemActive := StartSignal AND NOT StopSignal;
23
24// Timer for delay between C1 and C2 start
25Timer_C1_to_C2(IN := SystemActive AND NOT C2_Run AND NOT C1_Run, PT := Preset_C1_to_C2);
26
27// Control logic for Conveyor 1
28// C1 runs if system is active, C2 is not running, and C1 has not started the C1->C2 transition timer.
29C1_Run := SystemActive AND NOT Timer_C1_to_C2.Q AND NOT C2_Run;
30
31// Logic for Batch Count trigger
32VAR
33ProductSensor_R_Edge : R_TRIG;
34END_VAR
35
36ProductSensor_R_Edge(CLK := ProductSensor);
37
38// Control for Conveyor 2 batch cycle activation
39// C2 batch cycle starts if system is active, C1 has transitioned, and C2 is not currently running its timed cycle.
40IF SystemActive AND Timer_C1_to_C2.Q AND NOT C2_Run THEN
41C2_BatchCycleActive := TRUE;
42END_IF
43
44// If C2 finishes its run time or system stops, reset C2 batch cycle active flag
45IF Timer_C2_RunTime.Q OR NOT SystemActive THEN
46C2_BatchCycleActive := FALSE;
47END_IF
48
49// Control logic for Conveyor 2 run time
50// C2 runs if its batch cycle is active and its run time timer is not done.
51Timer_C2_RunTime(IN := C2_BatchCycleActive AND ProductSensor_R_Edge.Q, PT := Preset_C2_RunTime);
52C2_Run := Timer_C2_RunTime.Q;
53
54// Edge case: If StopSignal is asserted, stop all conveyors immediately
55IF StopSignal THEN
56C1_Run := FALSE;
57C2_Run := FALSE;
58Timer_C1_to_C2(IN := FALSE);
59Timer_C2_RunTime(IN := FALSE);
60SystemActive := FALSE;
61C2_BatchCycleActive := FALSE;
62END_IF
63
64// Edge case: If StartSignal is removed, stop all conveyors and reset timers
65IF NOT StartSignal THEN
66C1_Run := FALSE;
67C2_Run := FALSE;
68Timer_C1_to_C2(IN := FALSE);
69Timer_C2_RunTime(IN := FALSE);
70SystemActive := FALSE;
71C2_BatchCycleActive := FALSE;
72END_IF
73
74END_PROGRAM
Algorithm description viewbox

Conveyor Sequencing with Timer Delays and Batching

Algorithm description:

This Ladder Diagram program sequences two conveyors with timed delays and batch-based operation for the second conveyor. Conveyor 1 starts, then after a delay, Conveyor 2 starts for a fixed duration triggered by a product sensor. Once Conveyor 2 completes its timed run, Conveyor 1 restarts if the initial start signal is still active. This is useful for systems where items are processed in batches, requiring controlled movement and timing between stages. Examples include automated packaging or assembly lines.

Algorithm explanation:

The algorithm uses two Timer On Delay (TON) blocks and a Rising Edge Trigger (R_TRIG) for batch counting. `SystemActive` controls the overall operation based on `StartSignal` and `StopSignal`. `Timer_C1_to_C2` manages the initial delay before `C2` can start. `C1_Run` is active when `SystemActive` is true, and the first timer hasn't completed its delay, and `C2` is not running. `C2_BatchCycleActive` is a flag that becomes true when `C1` has completed its transition and `C2` is ready to run its timed cycle. The `ProductSensor_R_Edge` detects individual products. `Timer_C2_RunTime` is triggered by `C2_BatchCycleActive` and a product detection, running for `Preset_C2_RunTime` (1 second). `C2_Run` is active only when `Timer_C2_RunTime.Q` is true. Edge cases for `StopSignal` and `StartSignal` de-assertion are handled by resetting all outputs and timers. The space complexity is O(1) due to a fixed number of variables and timers. The time complexity is O(1) as operations are constant time per scan cycle.

Pseudocode:

Initialize StartSignal, StopSignal, ProductSensor, C1_Run, C2_Run, SystemActive, C2_BatchCycleActive to FALSE.
Initialize BatchCount to 0.
Set Preset_C1_to_C2 to 2 seconds.
Set Preset_C2_RunTime to 1 second.

Loop indefinitely:
  Set SystemActive to TRUE if StartSignal is TRUE AND StopSignal is FALSE, else FALSE.

  If SystemActive is TRUE AND C2_Run is FALSE AND C1_Run is FALSE:
    Start Timer_C1_to_C2.
  Else:
    Stop Timer_C1_to_C2.
  End If.

  If SystemActive is TRUE AND Timer_C1_to_C2.Output is FALSE AND C2_Run is FALSE:
    Set C1_Run to TRUE.
  Else:
    Set C1_Run to FALSE.
  End If.

  Detect rising edge of ProductSensor.

  If SystemActive is TRUE AND Timer_C1_to_C2.Output is TRUE AND C2_Run is FALSE:
    Set C2_BatchCycleActive to TRUE.
  End If.

  If Timer_C2_RunTime.Output is TRUE OR StopSignal is TRUE OR StartSignal is FALSE:
    Set C2_BatchCycleActive to FALSE.
  End If.

  If C2_BatchCycleActive is TRUE AND rising edge of ProductSensor is detected:
    Start Timer_C2_RunTime.
  Else:
    Stop Timer_C2_RunTime.
  End If.

  Set C2_Run to TRUE if Timer_C2_RunTime.Output is TRUE, else FALSE.

  If StopSignal is TRUE:
    Set C1_Run, C2_Run, SystemActive, C2_BatchCycleActive to FALSE.
    Reset Timer_C1_to_C2 and Timer_C2_RunTime.
  End If.

  If StartSignal is FALSE:
    Set C1_Run, C2_Run, SystemActive, C2_BatchCycleActive to FALSE.
    Reset Timer_C1_to_C2 and Timer_C2_RunTime.
  End If.

  Output C1_Run, C2_Run.