Challenge - 5 Problems
Up-Down Counter Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a 3-bit up-down counter with direction control
What is the value of
count after 5 clock cycles if dir = 1 (count up) starting from 3'b010?Verilog
module counter(input clk, input dir, output reg [2:0] count); initial count = 3'b010; always @(posedge clk) begin if (dir) count <= count + 1; else count <= count - 1; end endmodule
Attempts:
2 left
💡 Hint
Count up 5 times starting from 2 (binary 010).
✗ Incorrect
Starting at 3'b010 (decimal 2), counting up 5 times: 3,4,5,6,7 which is 3'b111. But since counting starts after first clock, after 5 cycles count is 7 (3'b111). However, initial count is 2, after 5 increments count is 7 (3'b111). So correct answer is 3'b111.
❓ Predict Output
intermediate2:00remaining
Output of a 4-bit up-down counter counting down
Given a 4-bit up-down counter starting at 4'b1001 and
dir = 0 (count down), what is the value of count after 3 clock cycles?Verilog
module counter(input clk, input dir, output reg [3:0] count); initial count = 4'b1001; always @(posedge clk) begin if (dir) count <= count + 1; else count <= count - 1; end endmodule
Attempts:
2 left
💡 Hint
Count down 3 times starting from 9 (binary 1001).
✗ Incorrect
Starting at 4'b1001 (decimal 9), counting down 3 times: 8,7,6 which is 4'b0110.
🔧 Debug
advanced2:00remaining
Identify the error in this up-down counter code
What error will this Verilog code produce when simulated?
Verilog
module counter(input clk, input dir, output reg [2:0] count); initial count = 3'b000; always @(posedge clk) begin if (dir == 1) count <= count + 1; else count <= count - 1; end endmodule
Attempts:
2 left
💡 Hint
Check the type of assignment used inside the always block triggered by clock.
✗ Incorrect
In sequential logic (posedge clk), non-blocking assignments (<=) should be used instead of blocking (=). Using blocking assignment here causes synthesis issues.
🧠 Conceptual
advanced2:00remaining
Behavior of up-down counter at overflow
What happens when a 3-bit up-down counter with direction control counts up from 3'b111 (decimal 7) and increments once more?
Attempts:
2 left
💡 Hint
Think about how binary counters behave with fixed bit width.
✗ Incorrect
A 3-bit counter wraps around after reaching max value 7 (3'b111). Incrementing 7 + 1 results in 0 (3'b000).
📝 Syntax
expert2:00remaining
Identify the syntax error in this up-down counter code
Which option correctly fixes the syntax error in this Verilog code snippet?
Verilog
always @(posedge clk) begin if (dir == 1) count <= count + 1 else count <= count - 1; end
Attempts:
2 left
💡 Hint
Check statement termination inside always block.
✗ Incorrect
Verilog statements must end with semicolons. Missing semicolon after 'count <= count + 1' causes syntax error.