summaryrefslogtreecommitdiff
path: root/button_sync.v
blob: 5913ce5a101f2162a445853b26b0ad7dd3c2ff5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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