欢迎使用CSDN-markdown编辑器

各位好:
这是我的第一篇博客。是一篇在FPGA中利用Verilog代码实现去抖动的代码博客,希望对大家有用。
如有Bug和不足之处还望指出,谢谢。

//
// Company: SCU
// Engineer: YinyuLiu
//
// Create Date: 10:22:41 06/04/2015
// Design Name: CommonTools
// Module Name: Debounce
// Project Name: >>>> PublicParts
// Target Devices:
// Tool versions: Quartus II v9.1
// Description: >>>> This module is designed for common use of sliminate jitter of button.
// >>>> erveryone can use it and improvement it.
// Dependencies:
//
// Revision: 1.0
// Additional Comments:
// >> Caution: Only non-commercial use, reproduce, please indicate the
// >> source and author.
// >> SCU—->Particle Physics and Nuclear Physics—->LiuYinYu
// >> Liuyinyu0629@foxmail.com
// >> chengdu/China.
//
//
module Debounce(pulseIn, clk, pulseOut);

parameter ClkFrequency = 25;  //MHz
parameter Bit32 = 32;
parameter TimeDelay = 30; //ms
parameter TimeConstant = ClkFrequency*TimeDelay*1000;

input pulseIn;
input clk;
output pulseOut;

reg [Bit32-1:0] timeCount = 32'b0;
reg pulseOut;
reg pulse1,pulse0;
reg debouncing = 1'b0;

always @(posedge clk) 
begin
     pulse0 <= pulseIn;
    pulse1 <= pulse0;
    if (!debouncing)
    begin
        if(pulse1 == 1'b0 && pulse0 == 1'b1)
        begin
            debouncing <= 1'b1;
            pulseOut <= 1'b1;
        end
        else if(pulse1 == 1'b1 && pulse0 == 1'b0)
        begin 
            debouncing <= 1'b1;
            pulseOut <= 1'b0;
        end
    end
    else if (debouncing)
    begin
        if(timeCount < TimeConstant[Bit32-1:0])
            timeCount <= timeCount + 32'd1;
        else
        begin
            debouncing <= 1'b0;
            timeCount <= 32'd0;
        end
    end
end

endmodule

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值