チャタリング吸収 ( eliminate SW chattering )
タクトSW ( push button ) の入力は必ずといっていいほどチャタリングします。
これを吸収するモジュールを作成します。
sw_debounce.v
module sw_debounce(clock_in,reset_n,sw_in, sw_out);
input clock_in, reset_n;
input sw_in;
output sw_out;
reg sw_out;
reg sw_prv;
reg [5:0]count;
always @(posedge clock_in or negedge reset_n)
begin
if (!reset_n)
begin
count = 1;
sw_prv = sw_in;
end
else
begin
if (sw_prv == sw_in)
begin
if (count == 0)
begin
sw_out = sw_in;
end
else
begin
count = count + 1;
end
end
else
begin
count = 1;
end
sw_prv = sw_in;
end
end
endmodule