summaryrefslogtreecommitdiff
path: root/button_sync.v
diff options
context:
space:
mode:
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