有限状态机实现的软件消抖电路
debouncing scheme 2
// Debouncing circuit
module debouncing
(
input wire clk,
input wire reset,
input wire sw, // 抖动的按钮或拨码开关输入信号
output reg db_level, // 去抖动后的开关信号输出
output reg db_tick // 每次输出宽度等于一个clk周期的脉冲信号
);
// 状态寄存器相关常量和变量定义
localparam [1:0]
zero = 2'b00,
wait0 = 2'b01,
one = 2'b10,
wait1 = 2'b11;
reg [1:0] state_reg;
reg [1:0] state_next;
// 状态寄存器时序逻辑
always @(posedge clk, posedge reset)
begin