Forum Discussion
Altera_Forum
Honored Contributor
16 years agoDebouncer verilog code
Hi you I wrote a simple code for a debouncer circuit, and I appreciate if you can have a look and correct what's wrong.
module debouncer (noisy,clk_1KHz,debounced);
input wire clk_1KHz...
Altera_Forum
Honored Contributor
11 years agodear TCWORLD,
I would like to clarify that this code is written by the Altera Teacher ARTEM_BOND and "reg" is authored by himself. I left exactly as he wrote, to not cause confusion. Below is my code which coincidentally, was exactly the name I used:
module debounce(
input wire clock,
input wire IN,
output reg OUT
);
parameter M = 8;
reg shift;
//shift: wait for stable
always @ (posedge clock)
begin
shift <= {shift,IN}; // N shift register
// if(shift == (2**M)*0)
if(~|shift)
OUT <= 1'b0;
// else if(shift == (2**M)-1)
else if(&shift)
OUT <= 1'b1;
else OUT <= OUT;
end
endmodule
If I understand correctly what you suggested, their changes are only to make the code cleaner... It really was it, nothing worked to help me, because nothing was fixed!!! As I requested earlier: ..."I think something is wrong in the code because I can notice any noise, by oscilloscope, even increased the value of M. Could you help me with this?" (Excuse me if not expressed myself correctly, my English is not very good.)- sintech5 years ago
New Contributor
For someone who found this topic looking for a working debouncer.
The correct code:
module debounce( input wire clock, input wire IN, output reg OUT ); parameter M = 8; reg [M:0]shift; //shift: wait for stable always @ (posedge clock) begin shift <= {shift,IN}; // N shift register if(~|shift) OUT <= 1'b0; else if(&shift) OUT <= 1'b1; else OUT <= OUT; end endmodule