0
0
Verilogprogramming~10 mins

Up-down counter with direction control 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'
Acount
Bclk
Cdir
Dreset
Attempts:
3 left
💡 Hint
Common Mistakes
Using clock or reset names instead of the counter variable.
Forgetting to specify the bit width.
2fill in blank
medium

Complete the code to check if the reset signal is active high.

Verilog
if ([1]) begin
  count <= 4'b0000;
end
Drag options to blanks, or click blank then click option'
Areset
Bclk
Cdir
Denable
Attempts:
3 left
💡 Hint
Common Mistakes
Using clock or direction signals instead of reset.
Not resetting the counter properly.
3fill in blank
hard

Fix the error in the always block sensitivity list to trigger on clock's positive edge.

Verilog
always @([1]) begin
  if (reset) count <= 4'b0000;
  else if (dir) count <= count + 1;
  else count <= count - 1;
end
Drag options to blanks, or click blank then click option'
Anegedge clk
Bposedge reset
Cclk
Dposedge clk
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'negedge' instead of 'posedge'.
Using the reset signal in sensitivity list incorrectly.
4fill in blank
hard

Fill both blanks to complete the conditional increment and decrement of the counter.

Verilog
if (dir) count <= count [1] 1;
else count <= count [2] 1;
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication or division instead of addition or subtraction.
Mixing up increment and decrement operators.
5fill in blank
hard

Fill all three blanks to complete the module header and port declarations for the up-down counter.

Verilog
module up_down_counter(
  input wire [1],
  input wire [2],
  input wire [3],
  output reg [3:0] count
);
Drag options to blanks, or click blank then click option'
Aclk
Breset
Cdir
Denable
Attempts:
3 left
💡 Hint
Common Mistakes
Including 'enable' which is not used in this design.
Mixing up the order of inputs.