Hi,
This little experimental project i did is to light the LED on whenever the button on the tact switch is press. however, the LED did not seems to response to tat.
So i thought maybe is the asynchronous problem as in the Debouncer. So i follow the similar coding as in the debouncer but cancelled out the PB_down and PB_up output since only 1 output is needed. But the results is the same.
I'm not sure whenever my code is correct either, just started to experimenting around with it for a few months.
Codes:
module testsw (clk, sw, LED1, LED2);
input clk;
input sw;
output LED1;
output LED2;
reg [22:0] cnt;
always@ (posedge clk) cnt <= cnt+1;
wire state;
debouncer swmod(.clk(clk), .PB(sw), .PB_state(state));
assign LED1 = ~cnt[22] & ~cnt[20];
assign LED2 = state;
endmodule
module debouncer(clk, PB, PB_state);
input clk;
input PB;
output PB_state;
reg PB_sync_0; always @(posedge clk) PB_sync_0 <= ~PB;
reg PB_sync_1; always @(posedge clk) PB_sync_1 <= PB_sync_0;
reg [15:0] PB_cnt;
reg PB_state;
wire PB_idle = (PB_state==PB_sync_1);
wire PB_cnt_max = &PB_cnt;
always @(posedge clk)
if(PB_idle)
PB_cnt <= 0;
else
begin
PB_cnt <= PB_cnt + 1;
if(PB_cnt_max) PB_state <= ~PB_state;
end
endmodule
Thanks in advance!
Regards,
LoneSync