Output addressing scheme in PLC Programming - Time & Space Complexity
When working with output addressing in PLC programming, it's important to understand how the program accesses and controls outputs.
We want to know how the time to set outputs grows as the number of outputs increases.
Analyze the time complexity of the following output addressing code snippet.
FOR i := 0 TO n-1 DO
Output[i] := TRUE;
END_FOR;
This code turns on each output from 0 up to n-1 one by one.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Setting each output bit to TRUE inside a loop.
- How many times: The loop runs exactly n times, once for each output.
As the number of outputs (n) increases, the program sets more outputs one by one.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 output sets |
| 100 | 100 output sets |
| 1000 | 1000 output sets |
Pattern observation: The number of operations grows directly with the number of outputs.
Time Complexity: O(n)
This means the time to set outputs grows in a straight line as the number of outputs increases.
[X] Wrong: "Setting multiple outputs at once takes the same time as setting one output."
[OK] Correct: Each output must be addressed and set individually, so more outputs mean more time.
Understanding how output addressing scales helps you explain how PLC programs handle many outputs efficiently and shows your grasp of program performance.
"What if we used a batch command to set all outputs at once? How would the time complexity change?"
Practice
Solution
Step 1: Understand output addressing purpose
Output addressing tells the PLC which output device to activate or control.Step 2: Differentiate from inputs and other settings
It does not specify inputs, programming language, or power supply.Final Answer:
Which physical output device the PLC controls -> Option AQuick Check:
Output addressing = physical output device [OK]
- Confusing output with input addressing
- Thinking it defines programming language
- Mixing it with power supply details
Solution
Step 1: Identify output address format
Output addresses usually start with 'O' followed by module and point numbers, e.g., O:2/5.Step 2: Recognize other prefixes
'I' is for inputs, 'M' for memory bits, 'T' for timers, so they are incorrect for output addressing.Final Answer:
O:2/5 -> Option BQuick Check:
Output address starts with 'O' [OK]
- Choosing input or memory addresses as output
- Mixing timer addresses with outputs
- Ignoring the prefix letter
O:1/3, which physical output does it refer to?Solution
Step 1: Parse the output address format
O:1/3 means output module 1, point 3 (the third output on module 1).Step 2: Exclude other interpretations
It is not a memory bit, not an input module, and the format is module/point (not point/module).Final Answer:
Module 1, output point 3 -> Option AQuick Check:
O:1/3 = module 1, point 3 [OK]
- Swapping module and point numbers
- Confusing output with input addresses
- Ignoring the prefix 'O:'
O:2-4Solution
Step 1: Check the separator in the address
Output addresses use a slash '/' to separate module and point, not a dash '-'.Step 2: Validate other parts
Module 2 and point 4 are valid numbers, and 'O' prefix is correct for output.Final Answer:
Incorrect separator; should use '/' instead of '-' -> Option CQuick Check:
Use '/' between module and point [OK]
- Using dash instead of slash
- Thinking module or point numbers are invalid
- Misunderstanding the prefix letter
Solution
Step 1: Understand module points numbering
Points start at 0, so module 2 with 4 points has points 0,1,2,3.Step 2: Identify last point of module 2
The last point is 3, so address is O:2/3. O:2/4 is invalid (point 4 does not exist).Step 3: Exclude other options
O:3/0 is invalid (module 3 does not exist). O:1/7 is last point of module 1, not module 2.Final Answer:
O:2/3 -> Option DQuick Check:
Last point = points - 1 = 3 [OK]
- Counting points starting at 1 instead of 0
- Using invalid module numbers
- Confusing module and point numbers
Ready to prove it?
Pass the test and this pattern moves unknown
