Since it's a 3-bit counter, it counts from 0 to 7 and then wraps around. After 5 pulses starting from 0, the sequence is [1, 2, 3, 4, 5]. However, the question asks for the output sequence starting from 0 after 5 pulses, which includes the initial 0 and the next 4 increments: [0, 1, 2, 3, 4].
Final Answer:
[0, 1, 2, 3, 4] -> Option A
Quick Check:
Count starts at 0, increments each pulse = [0..4] [OK]
Hint: Count increments after clock pulse, starts from 0 [OK]
Common Mistakes:
Including initial 0 before first pulse
Counting 6 values instead of 5
Confusing count start value
4. Identify the error in this Verilog code for a 4-bit up counter:
module counter(input clk, input reset, output reg [3:0] count);
always @(posedge clk) begin
if (reset == 1) count = 0;
else count = count + 1;
end
endmodule
medium
A. Output 'count' should not be declared as reg.
B. Reset condition should be 'if (reset != 1)'.
C. Using blocking assignments '=' instead of non-blocking '<=' inside always block.
D. Clock edge sensitivity should be negedge instead of posedge.
Solution
Step 1: Check assignment type in sequential always block
Inside always @(posedge clk), non-blocking assignments '<=' should be used to avoid race conditions.
Step 2: Verify other parts of the code
Reset condition and reg declaration are correct. Clock edge is correctly posedge.
Final Answer:
Using blocking assignments '=' instead of non-blocking '<=' inside always block. -> Option C
Quick Check:
Sequential logic uses '<=' not '=' [OK]
Hint: Use '<=' for sequential logic assignments [OK]
Common Mistakes:
Using '=' in always @(posedge clk)
Misunderstanding reset condition
Thinking reg is wrong for output
Changing clock edge unnecessarily
5. How can you modify a 4-bit up counter to count only when an enable signal is high?
module counter(input clk, input reset, output reg [3:0] count);
always @(posedge clk) begin
if (reset) count <= 0;
else count <= count + 1;
end
endmodule
hard
A. Add 'if (enable) count <= count + 1;' inside the always block after reset check.
B. Add 'if (enable) count = count + 1;' outside the always block.
C. Replace 'count <= count + 1;' with 'count <= count - 1;' when enable is high.
D. Add 'enable' to the sensitivity list of the always block.
Solution
Step 1: Understand how to control counting with enable
Counting should happen only when enable is high, so add a condition inside the always block after reset.
Step 2: Implement enable check correctly
Use 'if (enable) count <= count + 1;' with non-blocking assignment inside the always block.
Final Answer:
Add 'if (enable) count <= count + 1;' inside the always block after reset check. -> Option A
Quick Check:
Enable controls counting inside always block [OK]
Hint: Check enable inside always block after reset [OK]
Common Mistakes:
Using blocking assignment outside always block
Changing count direction instead of gating
Adding enable to sensitivity list (not needed)
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.