From a6e1b22f9f6005df1f5df3120c5da3a4c677f24d Mon Sep 17 00:00:00 2001 From: Andreas Olofsson Date: Wed, 13 Apr 2016 20:47:22 -0400 Subject: [PATCH] Adding async reset to debuncer. - Can't guarantee that there will be a clock at startup. - All IO modules with suspect clocking situation should have async reset on all key signals. - To test, then you turn off clock and look for "x propagation". --- src/common/hdl/oh_debouncer.v | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/common/hdl/oh_debouncer.v b/src/common/hdl/oh_debouncer.v index 835e1c6..7a3d5be 100644 --- a/src/common/hdl/oh_debouncer.v +++ b/src/common/hdl/oh_debouncer.v @@ -25,9 +25,10 @@ module oh_debouncer #( parameter BOUNCE = 100, // bounce time (s) reg clean_out; // synchronize incoming signal - oh_dsync dsync (.dout (noisy_synced), - .clk (clk), - .din (noisy_in)); + oh_dsync dsync (.dout (noisy_synced), + .clk (clk), + .nreset (nreset), + .din (noisy_in)); // synchronize reset to clk oh_rsync rsync (.nrst_out (nreset_synced), @@ -35,8 +36,11 @@ module oh_debouncer #( parameter BOUNCE = 100, // bounce time (s) .nrst_in (nreset)); // detecting change in state on input - always @ (posedge clk) - noisy_reg <= noisy_synced; + always @ (posedge clk or negedge nreset) + if(!nreset) + noisy_reg <= 1'b0; + else + noisy_reg <= noisy_synced; assign change_detected = noisy_reg ^ noisy_synced; @@ -55,8 +59,10 @@ module oh_debouncer #( parameter BOUNCE = 100, // bounce time (s) ); // sample noisy signal safely - always @ (posedge clk) - if(carry) + always @ (posedge clk or negedge nreset) + if(!nreset) + clean_out <= 'b0; + else if(carry) clean_out <= noisy_reg; endmodule // oh_debouncer