找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 217|回复: 0
收起左侧

基于fpga的输入信号边沿滤波(上升沿/下降沿)微秒 veilog

[复制链接]
ID:467203 发表于 2024-1-23 00:56 | 显示全部楼层 |阅读模式
滤波效果如图所示
51hei.png

直接上代码

veilog源码
module my_filter_us(
        input clk,//200Mhz
        input rst,
        input pulse_in,
        input[7:0] pulse_delay,//滤波数值输入,单位us  1-100
        output reg pulse_out=1



);
reg[19:0] cnt_delay=0;
reg[3:0] filter_satae=3;

wire[19:0] data;
assign data=pulse_delay*200;
reg[19:0] cnt_rst=0;
reg rst_n=0;

always @(posedge clk)
        begin
                if(cnt_rst<100000)
                        begin
                                cnt_rst<=cnt_rst+1;
                        end
                else
                        begin
                                rst_n<=1;
                        end
        end

always @(posedge clk or negedge rst_n)
        begin
                if(!rst_n)
                        begin

                        end
                else
                        begin
                                case(filter_satae)
                                        0:        begin
                                                        if(pulse_out==0)
                                                                begin
                                                                        filter_satae<=filter_satae+1;
                                                                end
                                                        else if(cnt_delay<data)
                                                                        begin
                                                                                if(pulse_in==0)
                                                                                        begin
                                                                                                cnt_delay<=cnt_delay+1;
                                                                                        end
                                                                                else
                                                                                        begin
                                                                                                cnt_delay<=0;
                                                                                                //data<=pulse_delay*200;
                                                                                        end
                                                                        end
                                                        else if(pulse_in==0)
                                                                begin
                                                                        pulse_out<=0;
                                                                        cnt_delay<=0;
                                                                end
                                                end
                                        1:        begin
                                                        filter_satae<=filter_satae+1;
                                                end
                                        2:        begin
                                                        if(pulse_out==1)
                                                                begin
                                                                        filter_satae<=filter_satae+1;
                                                                end
                                                        else if(cnt_delay<data)
                                                                        begin
                                                                                if(pulse_in==1)
                                                                                        begin
                                                                                                cnt_delay<=cnt_delay+1;
                                                                                        end
                                                                                else
                                                                                        begin
                                                                                                cnt_delay<=0;
                                                                                                //data<=pulse_delay*200;
                                                                                        end
                                                                        end
                                                        else if(pulse_in==1)
                                                                begin
                                                                        pulse_out<=1;
                                                                        cnt_delay<=0;
                                                                end

                                                end
                                        3:        begin
                                                        filter_satae<=0;
                                                        //data<=pulse_delay*200;
                                                end

                                endcase
                        end
        end


endmodule


仿真
`timescale 1ns/1ps
module my_filter_us_tb(
);
reg clk=0;
reg pulse_in=0;
reg [7:0]pulse_delay=10;
wire pulse_out;

my_filter_us u1(
        .clk(clk),
        .pulse_in(pulse_in),
        .pulse_delay(pulse_delay),
        .pulse_out(pulse_out)
);

initial begin
forever
        begin
                clk=0; #2 clk=1; #3;//200Mhz      

        end
end

initial begin
forever
        begin



                pulse_in=0; #60000;
                pulse_in=0; #3000 pulse_in=1; #3000;
                pulse_in=0; #3000 pulse_in=1; #3000;
                pulse_in=0; #3000 pulse_in=1; #3000;
                pulse_in=0; #3000 pulse_in=1; #3000;

                pulse_in=1; #60000;
                pulse_in=0; #3000 pulse_in=1; #3000;
                pulse_in=0; #3000 pulse_in=1; #3000;
                pulse_in=0; #3000; pulse_in=1; #3000;
                pulse_in=0; #3000; pulse_in=1; #3000;

        end
end
endmodule

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表