0
0
Verilogprogramming~20 mins

Ring counter in Verilog - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Ring Counter Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a 4-bit ring counter after 3 clock cycles

Consider this 4-bit ring counter Verilog code snippet. What is the value of q after 3 positive clock edges?

Verilog
module ring_counter(input clk, input reset, output reg [3:0] q);
  always @(posedge clk or posedge reset) begin
    if (reset)
      q <= 4'b0001;
    else
      q <= {q[2:0], q[3]};
  end
endmodule
A4'b0100
B4'b0010
C4'b1000
D4'b0001
Attempts:
2 left
💡 Hint

Each clock cycle shifts the '1' bit to the left, wrapping around.

🧠 Conceptual
intermediate
1:30remaining
Understanding the purpose of a ring counter

What is the main purpose of a ring counter in digital circuits?

ATo store multiple bits of data permanently
BTo generate a sequence where a single '1' bit circulates through flip-flops
CTo perform arithmetic addition on input signals
DTo count the number of clock cycles in binary form
Attempts:
2 left
💡 Hint

Think about how the '1' bit moves in a ring counter.

🔧 Debug
advanced
2:30remaining
Identify the error in this ring counter code

What error will occur when running this Verilog ring counter code?

Verilog
module ring_counter(input clk, input reset, output reg [3:0] q);
  always @(posedge clk or posedge reset) begin
    if (reset)
      q <= 4'b0001;
    else
      q <= {q[3:1], q[0]};
  end
endmodule
AThe '1' bit will not circulate correctly; it will stay in the same position
BNo error; the code works as intended
CThe counter will count in binary instead of circulating a single '1'
DSyntax error due to incorrect concatenation syntax
Attempts:
2 left
💡 Hint

Check how bits are shifted in the concatenation.

📝 Syntax
advanced
1:30remaining
Which option correctly implements a 3-bit ring counter reset?

Which code snippet correctly resets a 3-bit ring counter to 3'b001 on reset?

Aif (reset) q <= 3'b001;
Bif (reset) q = 3'b001;
Cif reset q <= 3'b001;
Dif (reset) q <= 3'b1;
Attempts:
2 left
💡 Hint

Remember the correct syntax for if statements and non-blocking assignments in always blocks.

🚀 Application
expert
2:00remaining
Number of states in a 5-bit ring counter

How many unique states does a 5-bit ring counter have before repeating the sequence?

A1
B10
C32
D5
Attempts:
2 left
💡 Hint

Think about how the single '1' bit moves through the 5 flip-flops.