chandlerbing65nm
Member level 5
I have a problem with turning on the LEDS using push-buttons. The LED (1 or 2) only tuns on when I both push-buttons (long press pb1 , quick press pb2 to light LED 2 and long press pb2 , quick press pb1 to light LED 1).
The code is written in verilog.
Here is the Top level block:
The clock divider code:
The DFF code:
The code is written in verilog.
Here is the Top level block:
Code:
module debouncer(
input [1:0]pb,
input clk,
output [1:0]score);
wire slow_clk;
wire Q1,Q2,Q2_bar;
reg [1:0]pb_out;
clock_div u1(clk,slow_clk);
my_dff d1(slow_clk, pb,Q1 );
my_dff2 e1(slow_clk, Q1,Q2 );
assign Q2_bar = ~Q2;
always @(pb)
begin
if (pb[0] == 1'b1) begin
pb_out[0] <= Q1 & Q2_bar;
end
else if (pb[1] == 1'b1) begin
pb_out[1] <= Q1 & Q2_bar;
end
else begin
pb_out = 0;
end
end
assign score = pb_out;
endmodule
The clock divider code:
Code:
module clock_div(input clk, output reg slow_clk
);
reg [23:0]counter=0;
always @(posedge clk)
begin
counter <= (counter>=1250000)?0:counter+1;
slow_clk <= (counter < 625000)?1'b0:1'b1;
end
endmodule
The DFF code:
Code:
module my_dff(
input DFF_CLOCK,
input [1:0]D,
output reg Q
);
always @ (posedge DFF_CLOCK)
begin
if (D[0] == 1'b1) begin
Q <= D[0];
end
else if (D[1] == 1'b1) begin
Q <= D[1];
end
else begin
Q <= 1'b0;
end
end
endmodule
module my_dff2(input DFF_CLOCK, D, output reg Q);
always @ (posedge DFF_CLOCK) begin
Q <= D;
end
endmodule