Complete the code to declare the input signal for the debouncer module.
module debouncer(
input wire [1],
output reg clean_out
);The input signal to be debounced is usually called noisy_in.
Complete the code to declare a 16-bit register for the counter.
reg [[1]:0] counter;
A 16-bit register is declared as [15:0] because indexing starts at 0.
Fix the error in the always block sensitivity list to include the clock signal.
always @([1]) begin if (reset) begin counter <= 0; end else if (noisy_in == clean_out) begin counter <= 0; end else begin counter <= counter + 1; end end
The always block should be triggered on the positive edge of the clock for synchronous logic.
Fill both blanks to complete the condition that resets the counter when stable and sets the output.
if (counter == [1]) begin clean_out <= [2]; end
The counter resets when it reaches MAX_COUNT, and the output is set to the stable noisy_in value.
Fill all three blanks to complete the parameter declaration, the counter increment, and the output assignment.
parameter [1] = 16'hFFFF; always @(posedge clk) begin if (reset) begin counter <= 0; clean_out <= 0; end else if (noisy_in == clean_out) begin counter <= 0; end else if (counter < [2]) begin counter <= counter + [3]; end else begin clean_out <= noisy_in; end end
The parameter MAX_COUNT defines the debounce time. The counter increments by 1 until it reaches MAX_COUNT.
