summaryrefslogtreecommitdiff
path: root/button_sync.v
diff options
context:
space:
mode:
authorChristian Cunningham <cc@local.lan>2026-03-28 16:35:19 -0700
committerChristian Cunningham <cc@local.lan>2026-03-28 16:35:19 -0700
commit07cc3c5c788eff68b8d68713204613b07824fae2 (patch)
tree8de16b7b00ceeeeb62103964ed4ea1be1487b6fd /button_sync.v
Initial CommitHEADmaster
Diffstat (limited to 'button_sync.v')
-rw-r--r--button_sync.v20
1 files changed, 20 insertions, 0 deletions
diff --git a/button_sync.v b/button_sync.v
new file mode 100644
index 0000000..5913ce5
--- /dev/null
+++ b/button_sync.v
@@ -0,0 +1,20 @@
+// This module is used for sycronizing the keys to the clock.
+// The key input is active low, like the keys on the board.
+// This module inverts the buttons so that the pressed output is active high
+// button_down is high if any of the buttons are pressed
+module button_sync (
+ input clk,
+ input [7:0] key,
+ output button_down,
+ output reg [7:0] pressed
+);
+ // used to avoid metastability
+ reg [7:0] key1;
+
+ assign button_down = |pressed;
+
+ always @(posedge clk) begin
+ pressed <= key1;
+ key1 <= key;
+ end
+endmodule