Forum Discussion
Altera_Forum
Honored Contributor
14 years agoVery simple Verilog code, but not working on DE2
I am running this simple code, pushing KEY[3] works fine (decrement), but when I push KEY[1] the 7-seg changes with both pushing and releasing and display some random number on the 7-seg. hex_7...
Altera_Forum
Honored Contributor
14 years agoAs a simple fact, you can't have two different edge sensitive triggers for a single counter.
The code actually defines an edge sensitive (synchronous) trigger for KEY[3] and an asynchronous trigger for KEY[1], which doesn't work for a counter. The combination of negedge KEY[1] and if (KEY[1] == 0) is a specific Verilog syntax, that's e.g. used for asynchronous resets. You typically should get a serious synthesis warning like "count[x] doesn't hold it's state between clock edges" indicating, that the counter doesn't work. Facing this fact, you obviously need to use a different method to detect keypress events. The common method is synchronous edge detection utilizing a system clock and comparing present and previous state of a signal.