Forum Discussion
Altera_Forum
Honored Contributor
7 years agoThe main problem with your loop is that the line "counter <= counter + 1;" will always be executed, whatever the conditions you test inside the loop are.
If I understand correctly what you mean (i.e. that the "counter <= counter + 1;" only be executed if the condition you test for is never met inside the loop) then you could do that by adding a boolean variable in your process, for example called "new_code_valid", initially set to true, and that you set to false with an if inside your loop when the condition is met. Then outside of the loop you add a second if that will only increase the counter if the variable new_code_valid is true. I usually don't recommend to use variables in a process, especially if you are a beginner, but this is one of the cases where using a variable is much easier and readable. There are three another flaws I think in your design. First the test condition that you put would still allow the exact same value in the array. You can fix this by changing the < in the first test to a <=. Then, in the elsif (counter < 8) condition, you assign an entry in the array, and then you read back the exact same entry, in the same clock cycle. This won't work, because when you read back pigsArray_signal(counter) you will still read the old value in the array. Use tempLocation instead. In addition, in the case where numbers are between 0 and 100, if you start filling your array with the values 0, 25, 50, 75, then no other value will be accepted and you will never fill up with 8 values.