-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbtn_sw.v
48 lines (41 loc) · 1.2 KB
/
btn_sw.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
46
47
48
/* ------------------------------------------ *
* Title : Button-Switch Converters *
* Project : Verilog Utility Modules *
* ------------------------------------------ *
* File : btn_sw.v *
* Author : Yigit Suoglu *
* Last Edit : 30/01/2021 *
* Licence : CERN-OHL-W *
* ------------------------------------------ *
* Description : Allows the use of switches *
* as buttons, and buttons as *
* switches. *
* ------------------------------------------ */
module BTNtoSW#(parameter RESETVAL = 1'b0, parameter NEGEDGESENS = 1'b0)(clk, rst, btn, sw);
input clk, rst, btn;
output reg sw;
wire btn_cntr;
assign btn_cntr = (NEGEDGESENS) ? ~btn : btn;
always@(posedge btn_cntr or posedge rst)
begin
if(rst)
begin
sw <= RESETVAL;
end
else
begin
sw <= ~sw;
end
end
endmodule
module SWtoBTN(clk, sw, btn);
input clk, sw;
output btn;
reg sw_d, sw_dd;
assign btn = sw_dd ^ sw_d;
always@(posedge clk)
begin
sw_d <= sw;
sw_dd <= sw_d;
end
endmodule