+
+ /* Clock debouncing */
+ reg lastinclk = 0;
+ reg [5:0] debounce = 0;
+ reg fixedclk = 0;
+ reg [9:0] resetcountdown = 0;
+
+ always @(posedge clk) begin
+ if (inclk != lastinclk) begin
+ lastinclk <= inclk;
+ debounce <= 1;
+ resetcountdown <= 10'b1111111111;
+ end else if (debounce == 0) begin
+ fixedclk <= inclk;
+ resetcountdown <= resetcountdown - 1;
+ end else
+ debounce <= debounce + 1;
+ end