Forum Discussion
Altera_Forum
Honored Contributor
17 years agosimple question
Hi there, I'm trying to increment a row of leds by one but pressing a pushbutton that is normally high until it is pressed. I have this code, but for some reason, the led's just light randomly. I'...
Altera_Forum
Honored Contributor
17 years agoYour code is exactly doing what you have written: increment the counter while the key is pressed. You apparently intended to increment it by one for each falling edge of the key signal.
The key inputs are said to have debouncing circuits in the DE2-70 manual. If this is correct, the below code (synchronous edge detection) should work.reg k1;
reg k2;
always @(posedge iCLK_28)
begin
k1 <= KEY;
k2 <= k1;
if(!iKEY)
j <= 0;
else if (!k1 && k2)
j <= j + 1;
end