Complete the code to declare a 4-bit 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 increment the counter on each clock cycle.
always @(posedge clk) begin if (reset) counter <= 0; else counter <= counter [1] 1; end
The counter increases by 1 each clock cycle, so we use the plus operator.
Fix the error in the counter reset condition to make it synchronous.
always @(posedge clk) begin if ([1]) counter <= 0; else counter <= counter + 1; end
The synchronous reset uses the 'reset' signal checked inside the clocked block.
Fill both blanks to create a modulo-10 counter that resets after 9.
always @(posedge clk) begin if (reset) counter <= 0; else if (counter [1] 9) counter <= 0; else counter <= counter [2] 1; end
The counter resets when it is greater than 9, and increments by 1 otherwise.
Fill all three blanks to create a parameterized counter with enable and synchronous reset.
module counter #(parameter WIDTH = [1]) ( input clk, input reset, input [2], output reg [WIDTH-1:0] count ); always @(posedge clk) begin if (reset) count <= 0; else if ([3]) count <= count + 1; end endmodule
The WIDTH parameter is set to 8 bits, the input signal is named 'enable', and the counter increments only when 'enable' is high.