This repository was archived by the owner on Aug 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathinputconditioner.v
More file actions
56 lines (48 loc) · 1.98 KB
/
inputconditioner.v
File metadata and controls
56 lines (48 loc) · 1.98 KB
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
46
47
48
49
50
51
52
53
54
55
56
// TAKEN FROM LISA'S 2016 REPOSITORY
//------------------------------------------------------------------------
// Input Conditioner
// 1) Synchronizes input to clock domain
// 2) Debounces input
// 3) Creates pulses at edge transitions
//------------------------------------------------------------------------
`timescale 1 ns / 1 ps
module inputconditioner
(
input clk, // Clock domain to synchronize input to
input noisysignal, // (Potentially) noisy input signal
output reg conditioned, // Conditioned output signal
output reg positiveedge, // 1 clk pulse at rising edge of conditioned
output reg negativeedge // 1 clk pulse at falling edge of conditioned
);
initial positiveedge = 0;
initial negativeedge = 0;
initial conditioned = 0;
parameter counterwidth = 3; // Counter size, in bits, >= log2(waittime)
parameter waittime = 3; // Debounce delay, in clock cycles
reg[counterwidth-1:0] counter = 0; //not sure what this syntax is
reg synchronizer0 = 0;
reg synchronizer1 = 0;
always @(posedge clk ) begin
if(conditioned == synchronizer1) begin //if conditioned is same as we thought
counter <= 0;
positiveedge <= 0; //not sure if this should be nonblockingit
negativeedge <= 0;
end
else begin //if conditioned has changed
if( counter == waittime) begin //when debouncing is done
counter <= 0; //reset counter
conditioned <= synchronizer1; //save conditioned in synchronizer1
positiveedge <= synchronizer1; //set negativeedge opposite
negativeedge <= !synchronizer1; //set positiveedge opposite
end
else begin
counter <= counter+1; //wait for debouncing
end
end
if (counter == 0) begin
synchronizer0 <= noisysignal;
synchronizer1 <= synchronizer0;
end
end
//max glitch is 6 clock cycles
endmodule