Forum Discussion
Altera_Forum
Honored Contributor
14 years agosir, ovro.
I have quick question for you. i have running code below which I used switch as input. but i don't have any idea how to implement button debouncing. code: --- Quote Start --- /*game pattern(LED | BUTTON)*/ if(ButtonT==11000000) //button detection delay begin ledBlink = timer1; ButtonT = 1; if(ledBlink == 1) begin LED = D1; if(sw1==0 && sw4==0) begin score1 = score1+2; end else if (sw1==0 || sw4==0) begin score1 = score1+1'b1; end end else if(ledBlink == 2) begin LED = D2; if(sw2==0 && sw3==0) begin score1 = score1+2; end else if (sw2==0 || sw3==0) begin score1=score1+1'b1; end end else if(ledBlink == 3) begin LED = D3; if(sw3 == 0) begin score1 = score1+1'b1; end end else if(ledBlink == 4) begin LED = D4; if(sw4 == 0) begin score1 = score1+1'b1; end end else if(ledBlink == 5) begin LED = D8; if(sw4 == 0 ) begin score1 = score1+1'b1; end end else if(ledBlink == 6) begin LED = D7; if(sw3 == 0) begin score1 = score1+1'b1; end end else if(ledBlink == 7) begin LED = D6; if(sw2 == 0) begin score1 = score1+1'b1; end end else if(ledBlink == 8) begin LED = D5; if(sw1 == 0) begin score1 = score1+1'b1; end end else begin LED= off; end if(score1 == 10) begin score1 = 0; score2 = score2+1; end end else begin ButtonT=ButtonT+1'b1; end end --- Quote End --- I tested debouncing like on embdded C which I think cannot be implemented here in verilog programming, like this. --- Quote Start --- else if(ledBlink == 3) begin LED = D3; if(sw3 == 0) begin score1 = score1+1'b1; while (sw3 == 0); // I think it can't be implenmented here. :( end end --- Quote End --- THANK YOU!