0
0
Verilogprogramming~20 mins

Down counter design in Verilog - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Down Counter Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a 4-bit down counter
What is the output of the 4-bit down counter after 3 clock cycles if it starts at 4'b1010 (decimal 10)?
Verilog
module down_counter(input clk, input reset, output reg [3:0] count);
  always @(posedge clk or posedge reset) begin
    if (reset)
      count <= 4'b1010;
    else
      count <= count - 1;
  end
endmodule
A4'b1001
B4'b0111
C4'b0110
D4'b0101
Attempts:
2 left
💡 Hint
Count down from 1010 three times, subtracting 1 each clock cycle.
🧠 Conceptual
intermediate
1:30remaining
Behavior of synchronous reset in down counter
In a synchronous reset down counter, what happens when the reset signal is asserted at the clock edge?
AThe counter resets to initial value only at the next clock edge.
BThe counter freezes and holds its current value indefinitely.
CThe counter counts down twice in the same clock cycle.
DThe counter resets to initial value immediately, ignoring the clock.
Attempts:
2 left
💡 Hint
Synchronous means reset works with the clock.
🔧 Debug
advanced
2:30remaining
Identify the error in this down counter code
What error will this Verilog down counter code produce when simulated?
Verilog
module down_counter(input clk, input reset, output reg [3:0] count);
  always @(posedge clk or posedge reset) begin
    if (reset == 1'b1)
      count = 4'b1111;
    else
      count = count - 1;
  end
endmodule
ASynthesis warning: use non-blocking assignments (<=) inside always block.
BNo error, code works correctly.
CRuntime error: count variable is not initialized.
DSyntax error: missing semicolon after count assignment.
Attempts:
2 left
💡 Hint
Check the type of assignment used inside sequential always block.
📝 Syntax
advanced
2:00remaining
Syntax error in down counter module
Which option contains the correct syntax for a 3-bit down counter with asynchronous reset?
A
module down_counter(input clk, input reset, output reg [2:0] count);
  always @(posedge clk or posedge reset) begin
    if reset
      count &lt;= 3'b000;
    else
      count &lt;= count - 1;
  end
endmodule
B
module down_counter(input clk, input reset, output reg [2:0] count)
  always @(posedge clk or posedge reset) begin
    if (reset)
      count &lt;= 3'b000;
    else
      count &lt;= count - 1;
  end
endmodule
C
module down_counter(input clk, input reset, output reg [2:0] count);
  always @(posedge clk or posedge reset) begin
    if (reset)
      count &lt;= 3'b000;
    else
      count &lt;= count - 1;
  end
endmodule
D
module down_counter(input clk, input reset, output reg [2:0] count);
  always @(posedge clk or posedge reset) begin
    if (reset == 1'b1)
      count = 3'b000;
    else
      count = count - 1;
  end
endmodule
Attempts:
2 left
💡 Hint
Check for missing semicolons and correct if syntax.
🚀 Application
expert
3:00remaining
Design a down counter with load and enable signals
Which Verilog code correctly implements a 4-bit down counter with synchronous load and enable signals? When load is high, the counter loads the input value; when enable is high and load is low, the counter counts down by 1 each clock cycle.
A
module down_counter(input clk, input reset, input load, input enable, input [3:0] data_in, output reg [3:0] count);
  always @(posedge clk) begin
    if (reset)
      count &lt;= 4'b0000;
    else if (load)
      count &lt;= data_in;
    else if (enable)
      count &lt;= count - 1;
  end
endmodule
B
module down_counter(input clk, input reset, input load, input enable, input [3:0] data_in, output reg [3:0] count);
  always @(posedge clk or posedge reset) begin
    if (reset)
      count &lt;= 4'b0000;
    else if (enable)
      count &lt;= count - 1;
    else if (load)
      count &lt;= data_in;
  end
endmodule
C
module down_counter(input clk, input reset, input load, input enable, input [3:0] data_in, output reg [3:0] count);
  always @(posedge clk or posedge reset) begin
    if (reset == 1'b1)
      count = 4'b0000;
    else if (load == 1'b1)
      count = data_in;
    else if (enable == 1'b1)
      count = count - 1;
  end
endmodule
D
module down_counter(input clk, input reset, input load, input enable, input [3:0] data_in, output reg [3:0] count);
  always @(posedge clk or posedge reset) begin
    if (reset)
      count &lt;= 4'b0000;
    else if (load)
      count &lt;= data_in;
    else if (enable)
      count &lt;= count - 1;
  end
endmodule
Attempts:
2 left
💡 Hint
Reset should be asynchronous; load has priority over enable.