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 ladder | En SCL |
|---|---|
Comparator ETAPA = 10 at the start of each rung of the step | 10: inside the CASE |
| Coils that turn on in the step | XV_201 := TRUE; |
| MOVE box that loads the next step | ETAPA := 20; |
Drawn out, the reactor sequence looks like this:
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:
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
- 1Write or change the code
- 2Tap ▶ Run and test it on the plant
- 3Tap ✓ Check to review it
Ctrl + Enter runs. Your code is saved in this browser.
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.
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.