Batch Mixer Sequence
Batch mixing is a stress test for sequential control — multiple ingredients fill in parallel, weight checks gate transitions, and the cycle must handle aborts and faults gracefully. This example uses a CASE-statement state machine equivalent to an SFC.
I/O list
| Tag | Type | Description |
|---|---|---|
| MV_A | DO | Ingredient A inlet valve |
| MV_B | DO | Ingredient B inlet valve |
| MV_C | DO | Ingredient C inlet valve |
| MV_Drain | DO | Drain valve |
| Mixer | DO | Mixer motor |
| WeightCell | AI | Tank weight (kg) |
| Recipe_A | REAL | Ingredient A target weight |
| Recipe_B | REAL | Ingredient B target weight |
| Recipe_C | REAL | Ingredient C target weight |
| StartBtn | DI | Start button |
| Step | INT | Current state |
Structured Text code
PROGRAM main
VAR
MixTimer : TON;
InitialWt : REAL; (* Tank weight at start *)
Tolerance : REAL := 0.5; (* ±0.5 kg target *)
END_VAR
(* All outputs default off *)
MV_A := FALSE; MV_B := FALSE; MV_C := FALSE;
MV_Drain := FALSE; Mixer := FALSE;
CASE Step OF
0: (* IDLE *)
IF StartBtn AND WeightCell < 1.0 THEN
InitialWt := WeightCell;
Step := 10;
END_IF;
10: (* PARALLEL FILL: A, B, C all open simultaneously *)
MV_A := WeightCell < InitialWt + Recipe_A - Tolerance;
MV_B := WeightCell < InitialWt + Recipe_A + Recipe_B - Tolerance;
MV_C := WeightCell < InitialWt + Recipe_A + Recipe_B + Recipe_C - Tolerance;
IF NOT MV_A AND NOT MV_B AND NOT MV_C THEN Step := 20; END_IF;
20: (* MIX *)
Mixer := TRUE;
MixTimer(IN := TRUE, PT := T#5m);
IF MixTimer.Q THEN
MixTimer(IN := FALSE);
Step := 30;
END_IF;
30: (* DISCHARGE *)
MV_Drain := TRUE;
IF WeightCell < InitialWt + 1.0 THEN Step := 0; END_IF;
END_CASE;How it works
Step 0 (IDLE): waits for StartBtn AND empty tank. Records the initial tare weight.
Step 10 (PARALLEL FILL): all three ingredient valves open simultaneously, each closes when its cumulative target weight is reached. The math accumulates: A closes at InitialWt+RecipeA, B closes at InitialWt+RecipeA+RecipeB, etc.
Tolerance band: ±0.5 kg to allow valve close-time and avoid overshoot. Real systems use a fast-fill / slow-fill profile.
Step 20 (MIX): mixer runs for 5 minutes per recipe.
Step 30 (DISCHARGE): drain valve opens until tank returns to empty (within 1 kg of initial tare), then back to IDLE.
Production system: would add abort/hold buttons, fault recovery, recipe selection from HMI, batch number tracking, and ISA-88 batch state model.