0
0
Verilogprogramming~10 mins

Down counter design 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 down counter register.

Verilog
reg [[1]:0] counter;
Drag options to blanks, or click blank then click option'
A7
B4
C0
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using 4:0 which is 5 bits
Using 7:0 which is 8 bits
2fill in blank
medium

Complete the code to decrement the counter by 1 on each clock cycle.

Verilog
always @(posedge clk) begin
  if (reset) counter <= 4'b1111;
  else counter <= counter [1] 1;
end
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' which counts up
Using '*' or '/' which are not for decrementing
3fill in blank
hard

Fix the error in the code to reset the counter to 15 when reset is active.

Verilog
always @(posedge clk) begin
  if (reset == [1]) counter <= 4'b1111;
  else counter <= counter - 1;
end
Drag options to blanks, or click blank then click option'
A1
B0
Chigh
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 which means reset inactive
Using 'true' or 'high' which are not valid in Verilog
4fill in blank
hard

Fill both blanks to complete the code that wraps the counter to 15 when it reaches 0.

Verilog
always @(posedge clk) begin
  if (reset) counter <= 4'b1111;
  else if (counter == [1]) counter <= [2];
  else counter <= counter - 1;
end
Drag options to blanks, or click blank then click option'
A4'b0000
B4'b1111
C4'b0001
D4'b1110
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 for the check
Setting counter to 14 instead of 15
5fill in blank
hard

Fill all three blanks to complete the module declaration and port list for the down counter.

Verilog
module down_counter(
  input wire [1],
  input wire [2],
  output reg [3:0] [3]
);
Drag options to blanks, or click blank then click option'
Aclk
Breset
Ccounter
Denable
Attempts:
3 left
💡 Hint
Common Mistakes
Using enable instead of reset
Naming output as enable instead of counter