July 22, 2026

Learn to Write AND & OR Operations in SCL

 

From Ladder Logic to Structured Control Language (SCL) in Siemens TIA Portal

Figure 1: Translating series and parallel LAD logic into an AND/OR SCL expression

Introduction

PLC programming is often taught using Ladder Logic (LAD) because its graphical representation is easy to understand and closely resembles traditional relay control circuits. However, modern automation projects increasingly use Structured Control Language (SCL), especially when programs become larger, more modular, and more data-oriented. One of the most important skills when moving from LAD to SCL is understanding how series and parallel contacts are converted into logical operators.

The two fundamental operations are AND and OR. In simple terms, AND means that all required conditions must be TRUE, while OR means that at least one of several conditions must be TRUE. Once these concepts are understood, many common LAD circuits can be converted into clear and readable SCL code.

1. Understanding AND Operation

In Ladder Logic, contacts connected in series represent an AND condition. The output can become TRUE only when every contact in the series is TRUE.

For example, consider an industrial machine that can start only when:
• The emergency stop circuit is healthy.
• The stop push button condition is healthy.
• A start command is received.

The logical expression is:

E_Stop AND Stop_PB AND Start_PB

In SCL, the same logic can be written as:

IF "E stop" AND "STOP PB" AND "START PB form field" THEN
    "LAMP ON" := TRUE;
ELSE
    "LAMP ON" := FALSE;
END_IF;

The AND operator combines Boolean conditions. If even one condition is FALSE, the complete AND expression becomes FALSE. This makes AND particularly useful for safety interlocks, machine permissives, process conditions, and sequence requirements.

A practical way to remember it is: AND means “all conditions are required.”

2. Understanding OR Operation

In Ladder Logic, contacts connected in parallel represent an OR condition. The output becomes TRUE when any one of the parallel conditions is TRUE.

Suppose a machine can be started from two different locations: a local field push button or a SCADA command. The machine should receive a start request if either command is active.

The logical expression is:

START_PB_Field OR START_PB_SCADA

In SCL:

IF "START PB form field" OR "START PB FORM SCADA" THEN
    "LAMP ON" := TRUE;
END_IF;

The OR operator is useful when multiple sources can generate the same command or when alternative conditions can satisfy a requirement. Typical examples include local/remote commands, automatic/manual selection, multiple sensors, alternative permissives, and alarm conditions.

A practical way to remember it is: OR means “any one condition is sufficient.”

3. Combining AND and OR Operations

Real industrial control logic frequently requires both AND and OR operations. The example shown in the accompanying image demonstrates this concept.

The ladder logic has two conditions in series followed by two start commands in parallel. Therefore, the logic can be expressed as:

E_Stop AND Stop_PB AND (Start_PB_Field OR Start_PB_SCADA)

The parentheses are important because they clearly define the OR group. In SCL, the complete logic becomes:

IF "E stop" AND "STOP PB" AND
   ("START PB form field" OR "START PB FORM SCADA") THEN
    "LAMP ON" := TRUE;
ELSE
    "LAMP ON" := FALSE;
END_IF;

Here, the AND operations create the overall permission, while the OR operation provides two alternative ways to generate the start command.

This is a very common pattern in industrial automation: mandatory conditions are combined with AND, while alternative commands or conditions are combined with OR.

4. Why Parentheses Matter in SCL

When AND and OR are used together, parentheses improve readability and help define the intended logic. They are especially important when converting a complex ladder network into one SCL expression.

For example:

A AND B OR C

may not communicate the intended control philosophy clearly. Instead, write the intended grouping explicitly:

A AND (B OR C)

or:

(A AND B) OR C

These two expressions can produce different results. Therefore, do not simply remove the ladder branches and place AND/OR operators in a line. First identify the logical groups in the ladder diagram, then reproduce those groups in SCL using parentheses.

A good practice is to read the statement from left to right and verbally explain it. For example: “The emergency stop and stop conditions must be healthy, and either the field start or SCADA start must be active.” If the SCL statement communicates exactly that sentence, the logic has been translated correctly.

5. Why Are There Two END_IF Statements in Nested Logic?

When SCL uses nested IF statements, every IF must have its own END_IF. For example:

IF A AND B THEN
    IF C OR D THEN
        Output := TRUE;
    ELSE
        Output := FALSE;
    END_IF;
ELSE
    Output := FALSE;
END_IF;

The inner IF controls the C OR D decision, so it requires the first END_IF. The outer IF controls the A AND B decision, so it requires the second END_IF.

However, if the entire condition can be expressed in one Boolean expression, nested IF statements may not be necessary. For the example in this article, a single IF statement is simpler:

IF A AND B AND (C OR D) THEN
    Output := TRUE;
ELSE
    Output := FALSE;
END_IF;

Using the simpler structure can make the program easier to read, maintain, troubleshoot, and teach.

6. LAD-to-SCL Conversion Method

A systematic conversion method helps avoid programming mistakes.

Step 1: Identify series contacts. Treat them as AND conditions.

Step 2: Identify parallel branches. Treat them as OR conditions.

Step 3: Identify the output coil or assignment.

Step 4: Group parallel conditions with parentheses.

Step 5: Write the Boolean expression in SCL.

Step 6: Add the required IF, THEN, ELSE, and END_IF structure.

Step 7: Test the logic using different input combinations.

For example, the ladder shown can be read as:

“Turn the lamp ON when the emergency stop condition and stop push-button condition are TRUE, and either the field start command or SCADA start command is TRUE.”

That sentence directly becomes:

IF "E stop" AND "STOP PB" AND
   ("START PB form field" OR "START PB FORM SCADA") THEN

This method is much more reliable than trying to translate symbols mechanically.

7. Practical Industrial Applications

AND and OR operations appear throughout automation systems.

AND examples:
• Motor starts only when safety permissive AND start command are TRUE.
• Conveyor runs when upstream ready AND downstream available.
• Heater operates when temperature is below the setpoint AND process enable is active.
• Pump starts when low-level condition AND automatic mode are active.

OR examples:
• Start command comes from local OR remote station.
• Alarm is generated when sensor A OR sensor B detects a fault.
• A cooling fan starts from high temperature OR manual override.
• A machine stops from emergency stop OR critical fault.

Combined logic is even more powerful. A pump could be permitted when Auto_Mode AND (Start_PB OR SCADA_Start) AND Tank_Level_OK. This type of expression closely represents real machine-control requirements.

8. Best Practices for Writing SCL

Keep Boolean expressions readable. Use meaningful tag names instead of unclear memory addresses where possible. Use parentheses whenever AND and OR are combined. Break very long expressions into intermediate Boolean variables when this improves readability.

For example:

"Start_Request" := "START PB form field" OR "START PB FORM SCADA";
"Machine_Permit" := "E stop" AND "STOP PB";
"LAMP ON" := "Machine_Permit" AND "Start_Request";

This approach makes troubleshooting easier because each logical stage can be monitored online.

Also remember that good PLC programming is not only about making the code compile. The logic must be safe, understandable, maintainable, and consistent with the machine's functional requirements. Safety-related functions should always follow the applicable safety architecture and should not rely solely on ordinary PLC Boolean logic.

Conclusion

AND and OR operations are the foundation of Boolean logic in SCL. The key skill is learning to recognize the relationship between Ladder Logic structure and SCL syntax: series contacts generally represent AND, while parallel branches generally represent OR. When both are used together, parentheses should be used to preserve the intended logic.

The example in this article demonstrates a practical industrial pattern: mandatory machine conditions are connected using AND, while alternative start sources are connected using OR. Once this pattern becomes familiar, converting LAD programs into SCL becomes much easier.

The best way to learn is through practice. Take simple motor-start, conveyor, pump, alarm, and interlock circuits in LAD and convert them into SCL. Then test different combinations of TRUE and FALSE inputs. With regular practice, you can move confidently from graphical ladder programming to structured SCL programming and develop cleaner, more scalable PLC applications.

 


No comments: