Parallel logic (OR condition) in PLC Programming - Time & Space Complexity
When using parallel logic with OR conditions in PLC programming, it is important to understand how the program checks inputs.
We want to know how the time to decide the output changes as the number of inputs grows.
Analyze the time complexity of the following code snippet.
// Example of parallel OR logic
IF Input1 OR Input2 OR Input3 OR Input4 THEN
Output := TRUE;
ELSE
Output := FALSE;
END_IF;
This code checks multiple inputs in sequence using OR conditions to set an output.
- Primary operation: Checking each input condition with OR.
- How many times: Each input is checked once per program scan.
As the number of inputs increases, the program checks each input one by one until it finds a TRUE or finishes all.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | Up to 10 checks |
| 100 | Up to 100 checks |
| 1000 | Up to 1000 checks |
Pattern observation: The number of checks grows directly with the number of inputs.
Time Complexity: O(n)
This means the time to evaluate the OR condition grows linearly as more inputs are added.
[X] Wrong: "The OR condition checks all inputs instantly, so time does not grow with more inputs."
[OK] Correct: Even though OR logic looks parallel, the program checks inputs one after another until it finds TRUE or finishes all, so time grows with input count.
Understanding how OR conditions scale helps you explain how PLC programs handle multiple signals efficiently and when delays might occur.
What if we changed the OR condition to an AND condition? How would the time complexity change?
Practice
Input1 ---| |---+---(Output)Input2 ---| |---+Solution
Step 1: Understand parallel logic in PLC
Parallel contacts represent an OR condition, meaning output activates if any input is ON.Step 2: Analyze given inputs
Since Input1 and Input2 are in parallel, output activates if either Input1 or Input2 is ON.Final Answer:
Output activates if either Input1 or Input2 is ON -> Option CQuick Check:
Parallel logic (OR) = Output ON if any input ON [OK]
- Thinking parallel means AND condition
- Assuming output needs both inputs ON
- Confusing series and parallel contacts
Start and Reset to control Motor?Solution
Step 1: Identify OR operator syntax
In PLC structured text, OR is written as 'OR' between conditions.Step 2: Match correct expression
Motor := Start OR Reset;uses 'Start OR Reset' which correctly represents OR condition for Motor.Final Answer:
Motor := Start OR Reset; -> Option DQuick Check:
OR operator syntax = Motor := Start OR Reset [OK]
- Using AND instead of OR
- Using XOR which is exclusive OR
- Negating the OR condition incorrectly
---[ ]---+---( )--- Start | Motor ---[ ]---+ Stop
Where
[ ] is a normally open contact and ( ) is the coil, what is the output state of Motor if Start is OFF and Stop is ON?Solution
Step 1: Understand parallel contacts behavior
Motor coil energizes if either Start or Stop contact is closed (ON).Step 2: Check input states
Start is OFF (open), Stop is ON (closed), so current flows through Stop contact to Motor coil.Final Answer:
Motor is ON -> Option AQuick Check:
Parallel OR logic = Motor ON if any input ON [OK]
- Assuming both inputs must be ON
- Confusing normally open with normally closed contacts
- Ignoring parallel wiring effect
---[ ]---[ ]---( )--- Input1 Input2 Output
Solution
Step 1: Analyze contact arrangement
Contacts are placed one after another (series), which means both must be ON for output.Step 2: Compare with OR condition requirement
OR requires parallel contacts, so this is an AND condition, not OR.Final Answer:
Contacts are in series, not parallel, so it's an AND condition -> Option AQuick Check:
Series contacts = AND, parallel contacts = OR [OK]
- Confusing series and parallel wiring
- Ignoring contact types
- Assuming output coil is missing
SensorA, SensorB, SensorC) detect a fault. Which ladder logic arrangement correctly implements this parallel OR condition?Solution
Step 1: Understand alarm activation logic
Alarm should activate if any sensor detects fault, so OR condition is needed.Step 2: Choose correct contact arrangement
Parallel contacts represent OR logic, so placing sensors in parallel activates alarm if any sensor is ON.Final Answer:
Place all three sensor contacts in parallel feeding the alarm coil -> Option BQuick Check:
Parallel contacts = OR = Alarm ON if any sensor ON [OK]
- Using series contacts which require all sensors ON
- Using NOT contacts incorrectly
- Using XOR which only activates if exactly one sensor is ON
Ready to prove it?
Pass the test and this pattern moves unknown
