Start-stop motor control in PLC Programming - Time & Space Complexity
We want to understand how the time it takes for a start-stop motor control program to run changes as the program runs repeatedly.
Specifically, we ask: How does the program's execution time grow when it checks the motor state many times?
Analyze the time complexity of the following code snippet.
// Simple start-stop motor control
IF StartButton THEN
Motor := TRUE;
ELSIF StopButton THEN
Motor := FALSE;
END_IF;
This code checks if the start or stop button is pressed and turns the motor on or off accordingly.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Checking the state of StartButton and StopButton inputs.
- How many times: This check happens once every program scan cycle, repeating continuously.
Each scan cycle runs the same checks once, regardless of how long the program runs.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 cycles | 10 checks |
| 100 cycles | 100 checks |
| 1000 cycles | 1000 checks |
Pattern observation: The number of operations grows directly with the number of cycles, but each cycle does a fixed small amount of work.
Time Complexity: O(1)
This means each program scan takes a constant amount of time, no matter how many times it runs.
[X] Wrong: "The program takes longer as the motor runs longer because it checks more inputs."
[OK] Correct: The program checks the same inputs each cycle, so each cycle's work stays the same regardless of motor run time.
Understanding how simple control logic runs repeatedly with fixed cost helps you explain how automation programs behave in real systems.
"What if we added a loop inside the program to check multiple sensors? How would the time complexity change?"
Practice
Solution
Step 1: Understand start-stop control basics
Start-stop control uses two buttons: Start to turn on the motor, Stop to turn it off.Step 2: Identify motor running behavior
The motor stays on after Start is pressed and released, until Stop is pressed.Final Answer:
To turn a motor on with a Start button and keep it running until a Stop button is pressed -> Option CQuick Check:
Start keeps motor running until Stop pressed = D [OK]
- Thinking motor runs only while Start is held
- Assuming motor stops automatically without Stop button
- Confusing Stop button with reversing motor
Solution
Step 1: Recall NO contact behavior
A normally open (NO) contact is open by default and closes when pressed.Step 2: Match to Start button function
The Start button is NO so it closes circuit when pressed to start motor.Final Answer:
A contact that closes when the button is pressed -> Option AQuick Check:
NO contact closes on press = B [OK]
- Confusing NO with NC (normally closed)
- Thinking Start button contact is always closed
- Mixing coil symbol with contact symbol
Start NO ---[ ]---+---( ) Motor
Stop NC ----[ ]---|
Motor ---[ ]-------+
What happens when the Start button is pressed and then released, assuming the motor was off initially?
Solution
Step 1: Analyze Start button effect
Pressing Start closes NO contact, energizing Motor coil.Step 2: Understand holding circuit
Motor contact in parallel holds coil energized after Start released.Final Answer:
Motor turns on and stays on until Stop is pressed -> Option AQuick Check:
Holding circuit keeps motor on after Start release = A [OK]
- Thinking motor turns off immediately after Start release
- Ignoring Stop button effect
- Misreading holding contact function
Solution
Step 1: Check Stop button wiring
Stop button must be NC to break circuit when pressed.Step 2: Identify effect of NO Stop button
If Stop is NO, pressing it does not open circuit, so motor stays on.Final Answer:
Stop button contact is wired as normally open (NO) instead of normally closed (NC) -> Option DQuick Check:
Stop must be NC to stop motor = C [OK]
- Wiring Stop as NO contact
- Confusing Start and Stop button contacts
- Forgetting holding contact role
Solution
Step 1: Understand emergency stop function
E-Stop must break power immediately to stop motor safely.Step 2: Choose wiring method
Placing E-Stop as NC contact in series with Stop button breaks circuit when pressed.Final Answer:
Add the E-Stop as a normally closed (NC) contact in series with the Stop button -> Option BQuick Check:
E-Stop NC in series cuts motor power = A [OK]
- Wiring E-Stop as NO contact
- Placing E-Stop in parallel with Start button
- Using E-Stop as coil instead of contact
Ready to prove it?
Pass the test and this pattern moves unknown
