Stimulus process with wait statements in VHDL - Time & Space Complexity
When we use wait statements in a VHDL stimulus process, we want to understand how the time the process takes grows as we add more wait steps.
We ask: How does adding more wait statements affect the total execution time?
Analyze the time complexity of the following code snippet.
process
begin
signal_a <= '1';
wait for 10 ns;
signal_a <= '0';
wait for 10 ns;
signal_a <= '1';
wait for 10 ns;
wait; -- end process
end process;
This process changes a signal and waits for fixed time intervals between changes.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Each wait for 10 ns statement pauses the process.
- How many times: The process has three wait statements executed sequentially.
Imagine we add more wait statements like these to the process.
| Input Size (number of wait steps) | Approx. Operations (waits) |
|---|---|
| 3 | 3 waits |
| 10 | 10 waits |
| 100 | 100 waits |
Pattern observation: The total wait time grows directly with the number of wait statements added.
Time Complexity: O(n)
This means the total execution time grows in a straight line as you add more wait steps.
[X] Wrong: "Adding more wait statements does not affect total execution time because the process just waits."
[OK] Correct: Each wait adds a fixed delay, so more waits add more total time, making the process take longer.
Understanding how wait statements affect timing helps you design testbenches and simulations that run efficiently and predictably.
"What if we replaced fixed wait times with conditional waits? How would that change the time complexity?"
Practice
wait for statements inside a stimulus process in VHDL?Solution
Step 1: Understand the role of stimulus processes
Stimulus processes apply test inputs to signals during simulation.Step 2: Identify the function of
Thewait forwait forstatement pauses the process for a specified time, allowing signals to hold values before changing again.Final Answer:
To pause the process and apply inputs step-by-step over time -> Option BQuick Check:
Stimulus process uses wait for to pause and apply inputs [OK]
- Thinking wait for resets signals
- Confusing wait for with variable declaration
- Assuming wait for defines clock period
Solution
Step 1: Review how stimulus processes terminate
Stimulus processes often run indefinitely unless explicitly stopped.Step 2: Identify the correct wait statement to stop the process
The statementwait;causes the process to suspend forever, effectively stopping it.Final Answer:
wait; -> Option AQuick Check:
Use wait; to stop stimulus process [OK]
- Using wait for with a time instead of wait;
- Trying to use end process; as a stop command
- Using stop; which is not valid VHDL
process
begin
signal_a <= '0';
wait for 10 ns;
signal_a <= '1';
wait for 20 ns;
wait;
end process;
What is the value of signal_a at 25 ns after simulation start?Solution
Step 1: Trace signal assignments over time
At 0 ns,signal_ais set to '0'. After 10 ns, it changes to '1'.Step 2: Determine signal value at 25 ns
At 25 ns, which is after the 10 ns and before the 30 ns (10+20),signal_aremains '1'.Final Answer:
'1' -> Option CQuick Check:
Signal changes at 10 ns to '1', stays until 30 ns [OK]
- Assuming signal_a is still '0' at 25 ns
- Ignoring the second wait for 20 ns
- Confusing wait; with wait for
process begin signal_b <= '1'; wait for 5 ns signal_b <= '0'; wait for 5 ns; wait; end process;
Solution
Step 1: Check syntax of wait statements
The firstwait for 5 nsis missing a semicolon at the end.Step 2: Confirm other syntax elements
Signal assignments and the finalwait;are correct. Sensitivity list is not required in a process with wait statements.Final Answer:
Missing semicolon after first wait for statement -> Option AQuick Check:
Every wait for must end with semicolon [OK]
- Thinking sensitivity list is required with wait
- Misreading signal assignment syntax
- Assuming wait; must be last line only
clk every 15 ns and stops after 90 ns. Which code snippet correctly implements this behavior?Solution
Step 1: Understand toggling every 15 ns for 90 ns
Toggling means changing clk from 0 to 1 or 1 to 0 every 15 ns. For 90 ns total, toggling happens 6 times (90/15).Step 2: Analyze each option's logic
process variable count : integer := 0; begin while count < 6 loop clk <= not clk; wait for 15 ns; count := count + 1; end loop; wait; end process; uses a loop with a counter to toggle clk 6 times, waiting 15 ns each time, then stops with wait;. Others either toggle once or use incorrect timing.Final Answer:
variable count : integer := 0; while count < 6 loop clk <= not clk; wait for 15 ns; count := count + 1; end loop; wait; -> Option DQuick Check:
Loop with wait for 15 ns toggles clk 6 times [OK]
- Using single wait for without loop for repeated toggling
- Incorrect loop ranges causing wrong toggle count
- Not stopping process after toggling
Ready to prove it?
Pass the test and this pattern moves unknown
