You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Verilog防抖器模块异常求助:button_debounce信号始终为0

Verilog防抖器输出始终为0的问题排查与修复

核心问题:防抖器实例化遗漏reset端口

在测试模块debouncer_tb中,实例化防抖器debounce时未传入reset信号:

debounce uut2(divded_clock_out, button, button_debounce);

而debounce模块的端口定义包含reset输入,遗漏该端口会导致内部DFF的reset端口悬空。由于DFF的复位是高电平有效,悬空端口通常会被识别为高电平,使得三个DFF持续处于复位状态,输出reg_wire始终为0,最终button_debounce恒为0。

修复步骤:补全实例化的reset端口

修改测试模块中的防抖器实例化代码,添加reset信号:

debounce uut2(divded_clock_out, button, button_debounce, reset);

额外优化:防抖逻辑合理性调整

当前防抖逻辑直接将三个寄存器输出相与:

assign button_debounce = reg_wire[0] & reg_wire[1] & reg_wire[2];

这种逻辑要求三个采样周期同时为高才输出高,实际防抖更常用的是检测连续稳定的采样值,可以优化为:

// 检测后两个寄存器一致,代表连续两次采样输入稳定
assign button_debounce = reg_wire[1] & reg_wire[2];

修正后的完整测试模块代码

module debouncer_tb();
    reg clk;
    reg reset;
    reg button;
    
    wire divded_clock_out;
    wire button_debounce;
    
    initial begin
        clk = 0;
        reset = 0;
        button = 0;
        #10;
        reset = 1;
        button = 1;
        // 增加仿真时长,覆盖分频器计数周期
        #1000000;
        $finish;
    end
    
    always #10 clk=~clk;
    
    divider uut(clk, reset, divded_clock_out);
    
    // 补全reset端口
    debounce uut2(divded_clock_out, button, button_debounce, reset);
endmodule

仿真验证说明

修正后,reset变为1后分频器开始工作,输出分频时钟。经过3个分频时钟上升沿后,三个DFF会依次采样到button的高电平,此时reg_wire全部为1,button_debounce会变为高电平。需确保仿真时长足够覆盖分频器的计数周期(约1ms,对应100MHz输入时钟)。

内容的提问来源于stack exchange,提问作者Rolando

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 09:55:22