Guest
I am trying to debounce a switch on a Xilinx FPGA using Verilog
modules. The main module is a shift register with a load and enable,
and the register should shift each time the button is pressed. I am
using the clock to debounce the switch. The problem i am having with
my design is that each time i push the button, the register shifts a
lot (more than 8 times, the number of LEDs i have on the board.)
could someone help me out with this? Thanks.
-Keith
// shiftrne.v
module shiftrne (R, L, E, w, BTN, Q, clock);
parameter n = 8;
input clock;
input [n-1:0] R;
input L, E, w, BTN;
output [n-1:0] Q;
reg [n-1:0] Q;
integer k;
wire btn2;
//assign btn2 = BTN;
mydebounce M1 (clock, BTN, btn2);
always @(btn2)
if(btn2 == 1)
begin
if (L)
Q <= R;
else if (!E)
begin
for (k = n-1; k > 0; k = k-1)
Q[k-1] <= Q[k];
Q[n-1] <= w;
end
end
endmodule
-----------------------------------------------------------------------------------------------------------------------------------------
module mydebounce (clock, butin, butout);
parameter DELAY = 270000; // .01 sec with a 27Mhz clock
input clock, butin;
output butout;
reg [18:0] count;
reg butout;
//assign butout <= butin;
always @(posedge clock)
if (butin == 1)
begin
count <= count+1;
if (count == DELAY)
butout <= 1;
else
butout <= 0;
end
else
begin
count <= 0;
butout <= 0;
end
modules. The main module is a shift register with a load and enable,
and the register should shift each time the button is pressed. I am
using the clock to debounce the switch. The problem i am having with
my design is that each time i push the button, the register shifts a
lot (more than 8 times, the number of LEDs i have on the board.)
could someone help me out with this? Thanks.
-Keith
// shiftrne.v
module shiftrne (R, L, E, w, BTN, Q, clock);
parameter n = 8;
input clock;
input [n-1:0] R;
input L, E, w, BTN;
output [n-1:0] Q;
reg [n-1:0] Q;
integer k;
wire btn2;
//assign btn2 = BTN;
mydebounce M1 (clock, BTN, btn2);
always @(btn2)
if(btn2 == 1)
begin
if (L)
Q <= R;
else if (!E)
begin
for (k = n-1; k > 0; k = k-1)
Q[k-1] <= Q[k];
Q[n-1] <= w;
end
end
endmodule
-----------------------------------------------------------------------------------------------------------------------------------------
module mydebounce (clock, butin, butout);
parameter DELAY = 270000; // .01 sec with a 27Mhz clock
input clock, butin;
output butout;
reg [18:0] count;
reg butout;
//assign butout <= butin;
always @(posedge clock)
if (butin == 1)
begin
count <= count+1;
if (count == DELAY)
butout <= 1;
else
butout <= 0;
end
else
begin
count <= 0;
butout <= 0;
end