0
0
Verilogprogramming~20 mins

Modulo-N counter in Verilog - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Modulo-N Counter Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple Modulo-4 counter
What is the output sequence of the 2-bit Modulo-4 counter after 5 clock cycles?

Consider the following Verilog code snippet:
Verilog
module mod4_counter(input clk, input reset, output reg [1:0] count);
  always @(posedge clk or posedge reset) begin
    if (reset)
      count <= 2'b00;
    else
      count <= (count == 2'b11) ? 2'b00 : count + 1;
  end
endmodule
A0, 1, 2, 3, 4
B1, 2, 3, 0, 1
C0, 1, 2, 3, 0
D0, 1, 2, 0, 1
Attempts:
2 left
💡 Hint
Remember the counter resets to 0 after reaching 3 (2'b11).
🧠 Conceptual
intermediate
1:30remaining
Understanding Modulo-N counter reset behavior
In a Modulo-N counter implemented in Verilog, what is the purpose of the reset signal?
ATo pause the counter temporarily
BTo initialize the counter value to zero or a known state
CTo increase the counting speed
DTo change the counting direction
Attempts:
2 left
💡 Hint
Think about what happens when the system starts or needs to restart counting.
🔧 Debug
advanced
2:30remaining
Identify the error in this Modulo-5 counter code
What error will occur when simulating this Modulo-5 counter Verilog code?
Verilog
module mod5_counter(input clk, input reset, output reg [2:0] count);
  always @(posedge clk or posedge reset) begin
    if (reset)
      count <= 3'b000;
    else if (count == 3'b101)
      count <= 3'b000;
    else
      count <= count + 1;
  end
endmodule
AThe counter never resets because 3'b101 is 5 decimal, which is out of 3-bit range
BRuntime error because count is declared as 2 bits but assigned 3 bits
CSyntax error due to missing semicolon
DThe counter resets correctly after counting to 5
Attempts:
2 left
💡 Hint
Check the binary value used for comparison and the bit width of count.
📝 Syntax
advanced
2:00remaining
Syntax error in Modulo-N counter code
Which option contains the correct syntax for a Modulo-3 counter in Verilog?
Aalways @(posedge clk or posedge reset) begin if(reset) count <= 2'b00; else if(count == 2'b10) count <= 2'b00; else count <= count + 1; end
Balways @(posedge clk or posedge reset) begin if(reset) count = 2'b00; else if(count == 2'b11) count <= 2'b00; else count <= count + 1; end
Calways @(posedge clk or posedge reset) begin if(reset) count <= 2'b00 else if(count == 2'b10) count <= 2'b00; else count <= count + 1; end
Dalways @(posedge clk or posedge reset) begin if(reset) count <= 2'b00; else if(count == 2'b10) count = 2'b00; else count <= count + 1; end
Attempts:
2 left
💡 Hint
Check for missing semicolons and correct use of non-blocking assignments.
🚀 Application
expert
3:00remaining
Design challenge: Modulo-6 counter output after 10 cycles
Given this Modulo-6 counter Verilog code, what is the value of 'count' after 10 positive clock edges starting from reset?

Code:
module mod6_counter(input clk, input reset, output reg [2:0] count);
always @(posedge clk or posedge reset) begin
if (reset)
count <= 3'b000;
else if (count == 3'b101)
count <= 3'b000;
else
count <= count + 1;
end
endmodule
A0 (3'b000)
B3 (3'b011)
C5 (3'b101)
D4 (3'b100)
Attempts:
2 left
💡 Hint
Count the increments carefully and remember the counter resets after reaching 5.