1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| `timescale 1ns / 1ps
module key_filter( input clk , input rst_n , input key , output reg key_out ); parameter TIME_20MS = 20'd1_000_000 ; reg [19:00] cnt_20ms ; always @(posedge clk) begin if(!rst_n) cnt_20ms <= 20'd0 ; else if(!key) begin if(cnt_20ms == TIME_20MS - 20'd1) cnt_20ms <= cnt_20ms ; else cnt_20ms <= cnt_20ms + 20'd1 ; end else cnt_20ms <= 20'd0 ; end always @(posedge clk) begin if(!rst_n) key_out <= 1'b0 ; else if(cnt_20ms == TIME_20MS - 20'd2) key_out <= 1'b1 ; else key_out <= 1'b0 ; end endmodule
|