Input addressing scheme in PLC Programming - Time & Space Complexity
When working with input addressing in PLC programming, it's important to know how the time to read inputs changes as the number of inputs grows.
We want to understand how the program's speed changes when it reads more inputs.
Analyze the time complexity of the following code snippet.
// Read multiple inputs using input addressing scheme
FOR i := 0 TO n-1 DO
inputValue := READ_INPUT(i); // Read input at address i
PROCESS(inputValue); // Process the input value
END_FOR
This code reads and processes each input one by one using an input addressing scheme.
- Primary operation: Reading and processing each input inside the loop.
- How many times: The loop runs once for each input, so n times.
As the number of inputs increases, the program reads and processes more inputs, so the work grows steadily.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 reads and processes |
| 100 | 100 reads and processes |
| 1000 | 1000 reads and processes |
Pattern observation: The number of operations grows directly with the number of inputs.
Time Complexity: O(n)
This means the time to read and process inputs grows in a straight line as the number of inputs increases.
[X] Wrong: "Reading multiple inputs happens all at once, so time stays the same no matter how many inputs there are."
[OK] Correct: Each input must be read and processed separately, so more inputs mean more time.
Understanding how input reading scales helps you explain how your PLC program will behave with more sensors or buttons, showing you think about real system growth.
"What if the inputs were read in parallel instead of one by one? How would the time complexity change?"
Practice
I1.3 mean in a PLC program?Solution
Step 1: Understand the input address format
The formatI<byte>.<bit>means input at specified byte and bit.Step 2: Interpret
This means input at byte 1, bit 3.I1.3Final Answer:
Input at byte 1, bit 3 -> Option DQuick Check:
Input address = I1.3 means byte 1, bit 3 [OK]
- Confusing input with output addresses
- Mixing up byte and bit positions
- Assuming bit number comes before byte
Solution
Step 1: Recall input address syntax
The correct format isI<byte>.<bit>.Step 2: Match byte 2 and bit 5
So input bit 5 in byte 2 isI2.5.Final Answer:
I2.5 -> Option AQuick Check:
Correct input syntax = I2.5 [OK]
- Swapping byte and bit numbers
- Using O instead of I for input
- Using dash instead of dot
I0.7 is ON and all others OFF, what is the binary value of byte 0?Solution
Step 1: Understand bit numbering in a byte
Bit 0 is the least significant bit (rightmost), bit 7 is the most significant (leftmost).Step 2: Set bit 7 ON and others OFF
Bit 7 ON means the leftmost bit is 1, others 0, so binary is 10000000.Final Answer:
10000000 -> Option BQuick Check:
I0.7 ON means bit 7 = 1, binary = 10000000 [OK]
- Assuming bit 7 is rightmost bit
- Confusing bit numbering direction
- Setting wrong bit ON
I3.8. What is wrong with this address?Solution
Step 1: Recall bit numbering limits
A byte has bits numbered 0 to 7 only, so bit 8 is invalid.Step 2: Check address
Bit 8 is outside valid range, so address is incorrect.I3.8Final Answer:
Bit number 8 does not exist in a byte -> Option AQuick Check:
Bits 0-7 valid, 8 invalid [OK]
- Thinking bits go 1 to 8
- Ignoring dot separator
- Assuming case sensitivity matters
Solution
Step 1: Identify byte and bit range
You want bits 0 to 3 in byte 4, so bits 0,1,2,3 of byte 4.Step 2: Write input addresses for these bits
These areI4.0,I4.1,I4.2,I4.3.Final Answer:
I4.0, I4.1, I4.2, I4.3 -> Option CQuick Check:
Bits 0-3 in byte 4 = I4.0 to I4.3 [OK]
- Mixing bits from different bytes
- Using bits 4-7 instead of 0-3
- Confusing byte numbers
Ready to prove it?
Pass the test and this pattern moves unknown
