Skip to content
PROCESIAby Aterra Ingeniería

LEARN · PROGRAMMING · SCL 4

SCL: CASE and step sequences

Program step by step a reactor that runs a complete batch on its own: it fills, heats to 60 °C, mixes for 10 seconds and empties. In 7 short steps, with the ladder of each step alongside.

Thinking in steps

Many processes do not always run the same way: they go step by step. A batch reactor fills, then heats, then mixes and finally empties. The orderly way to program it is to keep, in a variable, ETAPA, which step we are in.

Each step has actions, what is turned on while we are in it, and a transition, the condition to move to the next one. If you have seen GRAFCET, it is the same thing:

In ladderEn SCL
Comparator ETAPA = 10 at the start of each rung of the step10: inside the CASE
Coils that turn on in the stepXV_201 := TRUE;
MOVE box that loads the next stepETAPA := 20;

Drawn out, the reactor sequence looks like this:

010203040 RestFill · XV-201Heat · EH, AGMix · AG-201Empty · XV-202 STARTLSH-201TT-201 ≥ 60 °C10 sLSL-201

CASE

CASE chooses which block of code to run according to the value of a number. It is like an IF with many branches, but much easier to read:

CASE ETAPA OF 0: ... // if ETAPA is 0 10: ... // if ETAPA is 10 20, 25: ... // if it is 20 or 25 ELSE ... // any other value END_CASE;

The steps are numbered in tens on purpose: if tomorrow you have to add a step between filling and heating, you call it 15 and you don't have to renumber everything.

See a hint

  1. 1Write or change the code
  2. 2Tap ▶ Run and test it on the plant
  3. 3Tap ✓ Check to review it
Program · OB1 (SCL)

Ctrl + Enter runs. Your code is saved in this browser.

Reactor R-201
0 Rest10 Filling20 Heating30 Mixing35 Sample40 Emptying
— XV-201 AG-201 EH-201 0 % XV-202 LSH-201 LSL-201 TT TT-201 20.0 °C
Watch table

The outputs pattern

The program starts by turning off all the outputs and then the CASE turns on only those of the current step. It looks odd to write FALSE and then TRUE in the same cycle, but remember that the PLC writes the physical outputs at the end of the cycle, so the last value is the one that counts.

The advantage is enormous: it is impossible for a valve to be left open by oversight when changing step. If you did not do it this way, you would have to remember to close XV_201 in every transition that leaves filling, including the stop.

In TIA Portal

The CASE is written the same way. The usual approach is to program the sequence in an FB, with #ETAPA as a Static variable of type INT so that it keeps its value between cycles, and #T_MEZ as a TON_TIME multi-instance. TIA Portal also has the GRAPH language, which draws the sequence as in the diagram above, but a CASE in SCL works on any CPU and any brand.

A challenge: in exercise 7, what happens if the operator presses START to begin the batch and does not release the button until the mixing ends? Step 35 sees START pressed and skips straight past it without waiting for the sample. In a real plant that is solved with an edge: detecting the instant the button is pressed, not whether it is pressed.

What comes next

With these four lessons you already have the essentials of SCL: logic, IF, timers and sequences. The next step is to use it with a real PLC, on a complete plant.

Your sequence, on a 3D plant

In Procesia you program sequences like this one on your real PLC or in PLCSIM and control complete plants in 3D: filling, heating, mixing and packaging. Use the full version free for 7 days, no card.