Complete the code to declare a 4-bit down counter register.
reg [[1]:0] counter;
The counter is 4 bits wide, so the index goes from 3 down to 0.
Complete the code to decrement the counter by 1 on each clock cycle.
always @(posedge clk) begin if (reset) counter <= 4'b1111; else counter <= counter [1] 1; end
To count down, we subtract 1 from the counter each clock cycle.
Fix the error in the code to reset the counter to 15 when reset is active.
always @(posedge clk) begin if (reset == [1]) counter <= 4'b1111; else counter <= counter - 1; end
The reset signal is active high, so it should be compared to 1.
Fill both blanks to complete the code that wraps the counter to 15 when it reaches 0.
always @(posedge clk) begin if (reset) counter <= 4'b1111; else if (counter == [1]) counter <= [2]; else counter <= counter - 1; end
When the counter reaches 0 (4'b0000), it wraps back to 15 (4'b1111).
Fill all three blanks to complete the module declaration and port list for the down counter.
module down_counter( input wire [1], input wire [2], output reg [3:0] [3] );
The module has inputs clk and reset, and a 4-bit output counter.
