LEARN · PROGRAMMING · SCL 1
SCL from scratch: from ladder to text
Never written code? No problem. If you understand a ladder rung, in 7 short exercises you will write your first SCL program and watch it move a plant.
If you know ladder, you already know SCL
SCL is a way of programming the PLC by writing instead of drawing. The logic is the same as ladder: only how it is written down changes. This table is all you need to get started:
| In ladder | En SCL |
|---|---|
| Normally open contact of X | X |
| Normally closed contact of X | NOT X |
| Contacts in series | AND |
| Contacts in parallel | OR, in parentheses |
| Coil Y | Y := ... ; |
For example, the rung “if LSH_101 is active, turn on the pilot light XL_101” is written like this:
XL_101 := LSH_101;It reads “XL_101 takes the value of LSH_101”. The := means “takes the value of” and the ; ends the line, like a period. Whatever comes after // is a comment: the PLC does not read it.
In each exercise you will see the ladder rung next to the code, lighting up while the plant runs. First you read, then you change one word and finally you write it yourself.
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 logical operators
NOT a: inverts. TRUE ifais FALSE.a AND b: TRUE only if both are TRUE. It is a contact in series.a OR b: TRUE if at least one is TRUE. It is a contact in parallel.a XOR b: TRUE if they are different.
Order matters: NOT is evaluated first, then AND, then XOR and finally OR, just as multiplication comes before addition. When in doubt, use parentheses.
Latching, in one line
P_101 := (HS_101_MARCHA OR P_101) AND NOT HS_101_PARADA;It is the same rung from the hysteresis lesson, written as text: the OR P_101 is the pump contact in parallel with the start pushbutton, and the AND NOT is the normally closed stop contact in series. Since the PLC remembers the value of P_101 from the previous cycle, the pump keeps itself on.
In TIA Portal
In a TIA Portal SCL block, global tags go in quotation marks and local variables with #. This simulator accepts both forms, so you can copy your code as is:
AND "HS_101_PARADA", without the NOT. That way, if the wire breaks, the pump stops instead of being left with no stop.What comes next
In lesson 2: IF, ELSIF and ELSE, comparisons with numbers and the scaling of a 4–20 mA signal to meters.
Your program, on a 3D plant
In Procesia you write this same SCL on your real PLC or in PLCSIM and control the TK-101 tank in 3D, with pumps, valves and instruments. Use the full version free for 7 days, no card.