0
0
Verilogprogramming~10 mins

Modulo-N counter in Verilog - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a 4-bit register named 'count'.

Verilog
reg [3:0] [1] ;
Drag options to blanks, or click blank then click option'
Acounter
Bcount
Cvalue
Dcnt
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different register name like 'cnt' or 'counter'.
2fill in blank
medium

Complete the code to increment 'count' by 1 on each positive clock edge.

Verilog
always @(posedge clk) begin
  [1] <= count + 1;
end
Drag options to blanks, or click blank then click option'
Acount
Bclk
Ccounter
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning to 'clk' or other unrelated signals.
3fill in blank
hard

Fix the error in the reset condition to set 'count' to zero when 'rst' is high.

Verilog
always @(posedge clk or posedge rst) begin
  if ([1]) begin
    count <= 0;
  end else begin
    count <= count + 1;
  end
end
Drag options to blanks, or click blank then click option'
Arst
Bclk
Ccount
Denable
Attempts:
3 left
💡 Hint
Common Mistakes
Checking 'if (clk)' or 'if (enable)' instead of 'if (rst)'.
4fill in blank
hard

Fill both blanks to complete the modulo-N counter that resets 'count' to zero when it reaches N-1.

Verilog
parameter N = 10;
always @(posedge clk or posedge rst) begin
  if (rst) begin
    count <= 0;
  end else if (count [1] N-1) begin
    count <= [2];
  end else begin
    count <= count + 1;
  end
end
Drag options to blanks, or click blank then click option'
A==
B0
C>=
DN
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' instead of '==' or resetting to N instead of 0.
5fill in blank
hard

Fill all three blanks to create a modulo-N counter with enable signal that increments only when enabled.

Verilog
parameter N = 8;
always @(posedge clk or posedge rst) begin
  if (rst) begin
    count <= 0;
  end else if ([1]) begin
    if (count [2] N-1) begin
      count <= [3];
    end else begin
      count <= count + 1;
    end
  end
end
Drag options to blanks, or click blank then click option'
Aenable
B==
C0
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong condition for enable or comparison operators.