Program an operator-selected batch order with PLC stages

7 min read · Published November 14, 2026

Store the operator's six-chemical order as a position-indexed recipe table, check it when Start is pressed, then run one chemical at a time in stage logic while a position counter walks the table. Each stage's timer lives in its stage and executes on every scan, which is what a subroutine fired once by a button cannot give you.

You are building a six-chemical batch where the operator picks the order and each stage's target on an 8 in touchscreen before pressing Start. The build that works has three parts: a recipe table that holds the chosen order and setpoints, a validation check that gates the Start button, and stage logic that runs one chemical at a time while a position counter walks the table. Each timer lives inside its stage and executes on every scan, so it keeps time. Radio buttons that call subroutines in the chosen order fail all three parts, and the reason why is the place to start.

Why radio buttons and subroutines fail this job

A timer instruction counts while its rung executes. The rungs inside a subroutine execute when the routine is called, so a subroutine fired once by a button leaves its timer idle between calls. The stage then ends on the wrong elapsed time or never ends. That is why the standing advice for sequential control on this class of controller is to keep timers out of briefly called subroutines and place them in logic the scan always reaches.

Driving the chemical outputs straight from six buttons fails differently. Two selections can be on together, an output can stay commanded after the operator changes the order, and the sequence can advance with no completion test at all. The screen should edit data. The PLC should own execution.

Stage programming is the matching tool, and the method for relay-ladder controllers is well documented: divide the program into sections that represent process states, skip a stage whose bit is off, process the stages whose bits are on, and switch between them with jump instructions or with set and reset of the stage bits. Batch control standards such as ISA-88 draw the same line at any scale: the recipe lives on the batch side and the equipment phase state logic lives in the PLC.

What you need

  • A PLC with stage instructions in its instruction set, or plain state bits driven by an integer position value where it has none.
  • The 8 in touchscreen, for order entry and setpoint entry.
  • The process specification, giving the approved setpoint range for each chemical and the pH completion rule for pH stages: direction, tolerance and hold time.
  • Table memory for two copies of the recipe, plus one register for the current position.

The recipe table that holds the order

Index the recipe by position. Entry 1 runs first and entry 6 runs last. Each entry is three words:

Word Field Content
1 Operation identifier 1 acid, 2 caustic, 3 chemical 1, 4 chemical 2, 5 coagulant, 6 polymer
2 Target mode time or pH
3 Target value the setpoint with its unit, from the process specification

A chemical's identifier stays fixed while its position moves: acid is 1 whether it runs first or fifth. The other layout, a rank stored against each chemical and a search at each transition, runs with the same stage logic but is harder to display and harder to validate, so use the position table.

Keep two copies. The edit copy is what the touchscreen writes, and it accepts entries only while the batch is idle. The active copy is what the stage logic reads, filled by Start and left alone until the batch ends. Six entries at three words is 18 words per copy. If you will store named orders for reuse, multiply that out and check the limit first, as in planning an HMI recipe table's row limit. The basics of holding recipes in the controller are in storing HMI recipe tables in PLC memory.

How to build the program

  1. Plan the memory. Two recipe tables as above, plus one register for the current position: 0 idle, 1 to 6 running, 7 complete.
  2. Build the entry screen. One row per position: pick the chemical, pick the target mode, type the setpoint. Saving each numeric entry to the next indexed table word keeps the rows in order. Accept edits in idle only.
  3. Write the Start validation. On the Start button, check that every position 1 to 6 holds an identifier from 1 to 6, run the duplicate test, and check every setpoint against its approved range, the same discipline as validating HMI setpoints before they reach the PLC. Fail any check and the batch refuses to start, with the failing position named on the screen.
  4. Lay out the stages. One base stage, SG0, held on for the entire program, carries the general logic: Start and stop handling, the position counter, the recipe walk and the alarms. One stage per chemical, SG1 acid through SG6 polymer, carries that chemical's feed outputs, its permits, its timer and its completion test. On a controller without stage instructions, an integer position value gating six state bits gives the same behavior.
  5. Define each stage's completion test. A time stage ends when its timer reaches the entry's target; reset the timer on entry to the stage and leave its rung executing in that stage on every scan. A pH stage ends when the measured pH reaches the entry's target in the dosing direction, inside the tolerance and hold time the process specification gives. Acid drives pH down and caustic drives it up, so each test follows its own chemical's direction.
  6. Wire Start. Copy the edit table to the active table, set position to 1, reset the stage timer, energize the stage whose identifier matches entry 1, lock the edit table.
  7. Walk the table. In the base stage, test the active stage's completion condition. On pass, drop that stage's outputs, add 1 to the position, reset the timer, energize the stage named by the new entry. Add once per completion, on one scan, the same edge rule as in PLC counter scan timing and direction logic. At position 7 the batch is complete and every chemical output stays off.
  8. Write the stop and abort path, along the lines of starting and stopping a PLC sequence from an HMI button. Stop drops all chemical feed outputs at once, then either holds the position for an acknowledged restart or clears it for a fresh batch; pick one rule before the machine ships. Write the output drop so it works with the touchscreen disconnected, and keep the feed pump interlocks in the PLC.

Example: acid first at pH 3.0, polymer last at 10.0 min

The inputs. The operator's order on this run: position 1 acid, 2 caustic, 3 chemical 1, 4 chemical 2, 5 coagulant, 6 polymer, with identifiers fixed by that list, 1 to 6. The acid entry carries mode pH and target 3.0. The polymer entry carries mode time and target 10.0 min. The approved ranges and the pH completion rule come from the process specification.

The rule. Start is accepted when all six positions hold identifiers, no two identical, and every setpoint sits inside its approved range.

The arithmetic. The duplicate test compares each entry with every later entry: 6 x 5 / 2 = 15 comparisons, which is 5 + 4 + 3 + 2 + 1. The operator's quick screen adds the six identifiers: 1 + 2 + 3 + 4 + 5 + 6 = 21, and any other total fails at the screen. The PLC still runs all 15 comparisons, because 1, 1, 4, 4, 5, 6 also totals 21. The Start copy moves 6 x 3 = 18 words.

The run. Start copies the recipe, sets position to 1 and energizes the acid stage, whose test watches the measured pH come down to 3.0. On pass, the outputs drop, position 1 + 1 = 2, and the caustic stage runs. The walk repeats through position 6: the polymer stage resets its timer on entry and runs to its 10.0 min target. Position 6 + 1 = 7, the complete state, outputs off.

The decision. Reject Start, naming the position, for any unfilled entry, any duplicate the 15 comparisons find, or any setpoint outside its range. Accept and run when the 15 comparisons come back clean.

Recommendation: Build the six-stage batch as a position-indexed recipe of six three-word entries, validated on the Start button with the 15-comparison duplicate test, executed one chemical per stage with the timer inside its stage and a position counter walking the table. Let the touchscreen edit the order only while the batch is idle, and treat Start as the one action that moves the recipe into execution. If the process must allow a skipped or repeated chemical, change the validation rule in step 3 and keep the rest of the build as it is.

How to check it worked

  • Reject test. Put acid at positions 1 and 4, then press Start. The reject names position 4 and no chemical output energizes.
  • Dry run. Enter the full order and run with the outputs disabled. The position register walks 1 to 6, and each stage's outputs drop before the next stage's outputs rise.
  • Timer test. Set every stage to time mode at 1 min per stage. The batch should reach the complete state about 6 min after Start.
  • Abort test. Press stop mid-stage. The feed outputs drop at once, and the position holds or clears per the rule you picked in step 8.
  • Power test. Drop controller power during the polymer stage. On return the outputs stay off until the acknowledged restart, and the stage timer begins from zero.

Questions

Why do timers lose time inside a subroutine?

A timer counts while its rung executes, and a subroutine's rungs execute only when the routine is called. A routine fired once by a button leaves the timer's rung idle between calls, so elapsed time goes missing or lands in one jump at the next call. Keeping the timer in the stage that runs every scan removes the problem. If a timer must live in a subroutine, call that subroutine every scan so the rung is evaluated each time.

How do I allow a skipped or repeated chemical in the order?

Change only the validation rule. Drop the duplicate test and check that each position holds a valid identifier from 0 to 6, where 0 means skip, then check every nonzero entry's setpoint against its approved range. Give the table walk a one-scan path for a 0 entry: energize nothing, add 1 to the position, read the next entry. The stage logic stays unchanged.

What happens to the batch on a power failure?

The chemical outputs return off. Declare the position register and the active recipe retentive so the batch stops where it was, and reset each stage timer on entry, so a restart after power returns repeats the current stage's full time target from zero. Decide before shipping whether the restart needs an operator acknowledgement at the held position or clears to idle.

How much table memory does a six-stage recipe need?

Two copies of six entries at three words each: 18 words per copy, 36 words in all, plus one register for the current position. Stored named orders use 18 words each, so plan the total against the controller's data table limit before the machine ships.

Planning information, not legal or engineering advice. Rules differ by place: check codes and permits with your local authority and your licensed trades.

Keep reading

Build your signAsk for a quote