What a great schematic: +1 for going to the trouble of generating it. You've got multiple issues with your code, and this is a great example of the dangers of using blocking assignments, feedback, not using synthesis templates, and so on. Quartus has certainly screwed up, but it's not surprising given the input. Issues:
- don't use blocking assignments here - use
<=
- sort out your
begin
s andend
s. As a staring point, don't put anybegin
/end
in your code unless it's necessary; it's verbose, and hides errors like this. Only usebegin
/end
when you explicitly need to make a multi-stament block. Note thataux=aux+1
is outside your clockedif
/else
statement - when is it meant to execute? - Sort out where and when you want
aux
to increment. - Be very careful when you have feedback like
aux=aux+1
. If you're not careful, the real hardware will oscillate. - don't write chained logic like this - start to think parallel.
Quartus has had a fairly good go, but the circuit it has produced will just oscillate, and the aux
output is not clocked, which was presumably your intention. Quartus has put in the red buffer because it can see that it has produced an unstable feedback circuit, and it's had a half-hearted go at breaking it. It should have produced a warning somewhere about this.
1 - rewrite your code; something like
always @(posedge clock or posedge reset)
if(reset)
out <= 0;
else
out <= aux;
always @(posedge clock or posedge reset)
if(reset)
aux <= 0;
else
aux <= aux + 1'b1;
2 - don't assign to multiple variables in a clocked always
unless/until you understand what can go wrong with it (hint: check all branches/execution paths, confirm that something logical happens to all variables you assign to in all possible paths)
3 - Find a book on VHDL, read the chapter on delta delays/assignments, and your Verilog will be much better.