-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdebouncer.v
45 lines (39 loc) · 968 Bytes
/
debouncer.v
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
37
38
39
40
41
42
43
44
45
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 07:13:02 02/14/2020
// Design Name:
// Module Name: Debouncer
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module Debouncer(
input button_in,
input clk,
output reg button_out);
reg sync_0;
reg sync_1;
reg [15:0] tmpCounter;
always @(posedge clk) sync_0 <= button_in;
always @(posedge clk) sync_1 <= sync_0;
always @(posedge clk) begin
if (sync_1 == button_out)
tmpCounter <= 16'b0;
else begin
tmpCounter <= tmpCounter + 1;
if (tmpCounter == 16'hffff)
button_out <= ~button_out;
end
end // always @ (posedge clk)
endmodule