Forum Discussion
Altera_Forum
Honored Contributor
14 years ago --- Quote Start --- Replace always @ ( clk or in_port) with always @ (posedge clk) You may also need to change further, if you want the counter to increment only once when you push the switch: now it keeps on increasing at the clk rate as long as you keep the switch pressed. --- Quote End --- Thank you for your reply. Sorry, I try your suggestion,but it get the incorrect result. I don't know whether I misunderstanding your suggestion. I replace always @ ( clk or in_port) with always @ (posedge clk) In the normal case, when I press the switch, the counter will be increased once. However the experimental result shows the counter's number is a random number. The following is my experimental setting The initial the setting in_port = 8'b0000_0000 ,then the count shows number in NIOSII console with NIOS IDE --- Quote Start --- count is 0 --- Quote End --- next, I press the switch, I think the in_port = 8'b1000_0000 ,then the count shows number in NIOSII console with NIOS IDE --- Quote Start --- count is 208 (I want the count is 0) --- Quote End --- next, I keep on the switch pressed, the in_port = 8'b1000_0000 ,then the count shows number in NIOSII console with NIOS IDE --- Quote Start --- count is 30 (I want the count is 0) --- Quote End --- next, I keep on the switch pressed, the in_port = 8'b1000_0000 ,then the count shows number in NIOSII console with NIOS IDE --- Quote Start --- count is 93 (I want the count is 0) --- Quote End --- next, I press another switch, the in_port = 8'b1000_0010 ,then the count shows number in NIOSII console with NIOS IDE --- Quote Start --- count is 93 (I want the count is 1) --- Quote End --- next, I keep on switch pressed , the in_port = 8'b1000_0010 ,then the count shows number in NIOSII console with NIOS IDE --- Quote Start --- count is 93 (I want the count is 1) --- Quote End --- next, I release the switch, the in_port = 8'b1000_0000 (It will start to get the random number) ,then the count shows number in NIOSII console with NIOS IDE --- Quote Start --- count is 43 (I want the count is 1) --- Quote End --- next, I keep on the original switch pressed, the in_port = 8'b1000_0000 ,then the count shows number in NIOSII console with NIOS IDE --- Quote Start --- count is 58 (I want the count is 1) --- Quote End --- next, I press another switch, the in_port = 8'b1000_0010 ,then the count shows number in NIOSII console with NIOS IDE --- Quote Start --- count is 58 (I want the count is 2) --- Quote End --- Therefore I am almost crazy. I don't know why I can get this result. I replace always @ ( clk or in_port) with always @ (in_port) Let the command is executed in "always block" when the in_port changed. But the result is the same totally.