Altera_Forum
Honored Contributor
13 years agoVerilog always blocks
Hi all,
So I'm a verilog beginner having just picked myself up a DE1 board to play with. Currently I am having issues with always blocks. Given this simple example:
module FirstProject (SW, LEDR);
input SW;
output LEDR;
reg LEDR;
reg counter = 3'b0;
always (SW) //at symbol removed as forum thinks I'm trying to post a link
begin
counter = (counter + 1)% 4'b1000;
LEDR = counter;
end
endmodule
My understanding is that the always block should only execute when a change in SW[0] occurs, but on the board the always block is continually executed resulting in all 3 LED's being lit. If I change always (at) (SW[0]) to always (at) (posedge SW[0]) then things behave as expected and the LED's count upwards when the switch is toggled on. So my question is why would the not behave as expected and only change each time the switch is toggled? Any help would be appreciated.